18
18
*/
19
19
class WorkspaceImportCommand extends BaseCommand
20
20
{
21
+ const UUID_BEHAVIOR = [
22
+ 'new ' => ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW ,
23
+ 'remove ' => ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REMOVE_EXISTING ,
24
+ 'replace ' => ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REPLACE_EXISTING ,
25
+ 'throw ' => ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW ,
26
+ ];
27
+
21
28
/**
22
29
* {@inheritDoc}
23
30
*/
@@ -29,6 +36,7 @@ protected function configure()
29
36
->setName ('phpcr:workspace:import ' )
30
37
->addArgument ('filename ' , null , 'The xml file to import ' )
31
38
->addOption ('parentpath ' , 'p ' , InputOption::VALUE_OPTIONAL , 'Repository path to the parent where to import the file contents ' , '/ ' )
39
+ ->addOption ('uuid-behavior ' , null , InputOption::VALUE_REQUIRED , 'How to handle UUID collisions during the import ' , 'new ' )
32
40
->setDescription ('Import xml data into the repository, either in JCR system view format or arbitrary xml ' )
33
41
->setHelp (<<<EOF
34
42
The <info>import</info> command uses the PHPCR SessionInterface::importXml method
@@ -39,6 +47,17 @@ protected function configure()
39
47
40
48
If the <info>parentpath</info> option is set, the document is imported to that
41
49
path. Otherwise the document is imported at the repository root.
50
+
51
+ The optional <info>uuid-behavior</info> option describes how UUIDs should be
52
+ handled. The following options are available:
53
+
54
+ * <info>new</info> recreate a new uuid for each imported node;
55
+ * <info>remove</info> on collision, remove the old node from the repository and
56
+ put the imported data in the tree;
57
+ * <info>replace</info> on collision, replace the existing node with the one being
58
+ imported. All children of the imported node also go to the new path;
59
+ * <info>throw</info> throw an exception on uuid collision.
60
+
42
61
EOF
43
62
)
44
63
;
@@ -60,11 +79,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
60
79
return 1 ;
61
80
}
62
81
63
- $ session ->importXML (
64
- $ parentPath ,
65
- $ filename ,
66
- ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW
67
- );
82
+ $ uuidBehavior = $ input ->getOption ('uuid-behavior ' );
83
+ if (!array_key_exists ($ uuidBehavior , self ::UUID_BEHAVIOR )) {
84
+ $ output ->writeln (sprintf ('<error>UUID-Behavior "%s" is not supported</error> ' , $ uuidBehavior ));
85
+ $ output ->writeln (sprintf ('Supported behaviors are %s ' , implode (', ' , array_keys (self ::UUID_BEHAVIOR ))));
86
+
87
+ return 1 ;
88
+ }
89
+
90
+ $ session ->importXML ($ parentPath , $ filename , self ::UUID_BEHAVIOR [$ uuidBehavior ]);
68
91
$ session ->save ();
69
92
70
93
$ output ->writeln (sprintf (
0 commit comments