2
2
3
3
namespace PHPCR \Util \Console \Command ;
4
4
5
+ use PHPCR \ImportUUIDBehaviorInterface ;
6
+ use PHPCR \RepositoryInterface ;
5
7
use Symfony \Component \Console \Input \InputInterface ;
6
8
use Symfony \Component \Console \Input \InputOption ;
7
9
use Symfony \Component \Console \Output \OutputInterface ;
8
- use PHPCR \RepositoryInterface ;
9
- use PHPCR \ImportUUIDBehaviorInterface ;
10
10
11
11
/**
12
12
* Command to import a system or document view XML into the repository.
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 , 'Behavior to handle uuid on 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
@@ -60,11 +68,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
60
68
return 1 ;
61
69
}
62
70
63
- $ session ->importXML (
64
- $ parentPath ,
65
- $ filename ,
66
- ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW
67
- );
71
+ $ uuidBehavior = $ input ->getOption ('uuid-behavior ' );
72
+ if (!array_key_exists ($ uuidBehavior , self ::UUID_BEHAVIOR )) {
73
+ $ output ->writeln (sprintf ('<error>UUID-Behavior "%s" is not supported</error> ' , $ uuidBehavior ));
74
+
75
+ return 1 ;
76
+ }
77
+
78
+ $ session ->importXML ($ parentPath , $ filename , self ::UUID_BEHAVIOR [$ uuidBehavior ]);
68
79
$ session ->save ();
69
80
70
81
$ output ->writeln (sprintf (
0 commit comments