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