@@ -40,6 +40,12 @@ protected function configure()
4040 'The query language (e.g. sql, jcr_sql2) ' ,
4141 'jcr-sql2 '
4242 )
43+ ->addOption (
44+ 'persist-counter ' , 'c ' ,
45+ InputOption::VALUE_OPTIONAL ,
46+ 'Save the session every x requests ' ,
47+ '100 '
48+ )
4349 ->setDescription ('Command to manipulate the nodes in the workspace. ' )
4450 ->setHelp (<<<HERE
4551The <info>phpcr:nodes:update</info> can manipulate the properties of nodes
@@ -80,6 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8086
8187 $ query = $ input ->getOption ('query ' );
8288 $ queryLanguage = strtoupper ($ input ->getOption ('query-language ' ));
89+ $ persistCounter = intval ($ input ->getOption ('persist-counter ' ));
8390 $ setProp = $ input ->getOption ('set-prop ' );
8491 $ removeProp = $ input ->getOption ('remove-prop ' );
8592 $ addMixins = $ input ->getOption ('add-mixin ' );
@@ -111,6 +118,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
111118 }
112119 }
113120
121+ $ persistIn = $ persistCounter ;
122+
114123 foreach ($ result as $ i => $ row ) {
115124 $ output ->writeln (sprintf (
116125 "<info>Updating node:</info> [%d] %s. " ,
@@ -127,6 +136,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
127136 'removeMixins ' => $ removeMixins ,
128137 'applyClosures ' => $ applyClosures ,
129138 ));
139+
140+ $ persistIn --;
141+ if (0 === $ persistIn ) {
142+ $ output ->writeln ('<info>Saving nodes processed so far...</info> ' );
143+ $ session ->save ();
144+ $ persistIn = $ persistCounter ;
145+ }
130146 }
131147
132148 $ output ->writeln ('<info>Saving session...</info> ' );
0 commit comments