Skip to content

Commit 586b757

Browse files
committed
Merge pull request #36 from phpcr/session_export_improvements
2 new features for session export view
2 parents 2bbddf1 + 8fda423 commit 586b757

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# alpha2 / dev-master
2+
3+
- Added `--pretty` option to `session:export:view` command to output formatted XML
4+
- Ask confirmation before overwriting file in `session:export:view`

features/phpcr_session_export_view.feature

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ Feature: Export the repository to an XML file
2828
Invalid path 'cms'
2929
"""
3030

31-
Scenario: Export to an existing file
31+
Scenario: Export to an existing file (should overwrite as --no-interaction is specified)
3232
Given the file "foobar.xml" exists
33-
And I execute the "session:export:view /tests_general_base foobar.xml" command
34-
Then the command should fail
35-
And the output should contain:
36-
"""
37-
File "foobar.xml" already exists.
38-
"""
33+
And I execute the "session:export:view /tests_general_base foobar.xml --no-interaction" command
34+
Then the command should not fail
3935

4036
Scenario: Export non recursive
4137
Given I execute the "session:export:view /tests_general_base foobar.xml --no-recurse" command
@@ -51,3 +47,10 @@ Feature: Export the repository to an XML file
5147
Scenario: Export the document view
5248
Given I execute the "session:export:view / foobar.xml --document" command
5349
Then the command should not fail
50+
51+
Scenario: Export the document view in pretty way
52+
Given I execute the "session:export:view / foobar.xml --pretty" command
53+
Then the command should not fail
54+
And the file "foobar.xml" should exist
55+
And the xpath count "/sv:node" is "1" in file "foobar.xml"
56+
And the xpath count "/sv:node/sv:node" is "1" in file "foobar.xml"

src/PHPCR/Shell/Console/Command/Phpcr/SessionExportViewCommand.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protected function configure()
2020
$this->addOption('no-recurse', null, InputOption::VALUE_NONE, 'Do not recurse');
2121
$this->addOption('skip-binary', null, InputOption::VALUE_NONE, 'Skip binary properties');
2222
$this->addOption('document', null, InputOption::VALUE_NONE, 'Export the document view');
23+
$this->addOption('pretty', null, InputOption::VALUE_NONE, 'Export in human readable format');
2324
$this->setHelp(<<<HERE
2425
Serializes the node (and if <info>--no-recurse</info> is false, the whole subgraph) at
2526
<info>absPath</info> as an XML stream and outputs it to the supplied URI. The
@@ -58,12 +59,20 @@ public function execute(InputInterface $input, OutputInterface $output)
5859
{
5960
$session = $this->getHelper('phpcr')->getSession();
6061
$file = $input->getArgument('file');
62+
$pretty = $input->getOption('pretty');
6163
$exportDocument = $input->getOption('document');
64+
$dialog = $this->getHelper('dialog');
6265

6366
if (file_exists($file)) {
64-
throw new \InvalidArgumentException(sprintf(
65-
'File "%s" already exists.', $file
66-
));
67+
$confirmed = true;
68+
69+
if (false === $input->getOption('no-interaction')) {
70+
$confirmed = $dialog->askConfirmation($output, 'File already exists, overwrite?');
71+
}
72+
73+
if (false === $confirmed) {
74+
return;
75+
}
6776
}
6877

6978
$stream = fopen($file, 'w');
@@ -87,5 +96,13 @@ public function execute(InputInterface $input, OutputInterface $output)
8796
}
8897

8998
fclose($stream);
99+
100+
if ($pretty) {
101+
$xml = new \DOMDocument(1.0);
102+
$xml->load($file);
103+
$xml->preserveWhitespace = true;
104+
$xml->formatOutput = true;
105+
$xml->save($file);
106+
}
90107
}
91108
}

0 commit comments

Comments
 (0)