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