22
33namespace PHPCR \Util \Console \Command ;
44
5+ use PHPCR \Query \QueryResultInterface ;
6+ use PHPCR \Query \RowInterface ;
57use Symfony \Component \Console \Input \InputOption ;
68use Symfony \Component \Console \Input \InputInterface ;
79use Symfony \Component \Console \Output \OutputInterface ;
8- use Symfony \Component \Console \Helper \DialogHelper ;
910
1011/**
1112 * Command which can update the properties of nodes found
@@ -110,13 +111,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
110111 $ result = $ query ->execute ();
111112
112113 if (!$ noInteraction ) {
113- if (false === $ this ->getAction ( $ output , $ result )) {
114+ if (false === $ this ->shouldExecute ( $ input , $ output , $ result )) {
114115 return 0 ;
115116 }
116117 }
117118
118119 $ persistIn = $ persistCounter ;
119120
121+ /** @var $row RowInterface */
120122 foreach ($ result as $ i => $ row ) {
121123 $ output ->writeln (sprintf (
122124 "<info>Updating node:</info> [%d] %s. " ,
@@ -149,21 +151,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
149151 return 0 ;
150152 }
151153
152- protected function getAction ($ output , $ result )
154+ /**
155+ * @return bool Whether to execute the action or not.
156+ */
157+ private function shouldExecute (InputInterface $ input , OutputInterface $ output , QueryResultInterface $ result )
153158 {
154- /** @var $dialog DialogHelper */
155- $ dialog = $ this ->getHelperSet ()->get ('dialog ' );
156- $ response = strtoupper ($ dialog ->ask ($ output , sprintf (
159+ $ response = strtoupper ($ this ->ask ($ input , $ output , sprintf (
157160 '<question>About to update %d nodes. Enter "Y" to continue, "N" to cancel or "L" to list.</question> ' ,
158161 count ($ result ->getRows ())
159- ), false ));
162+ )));
160163
161164 if ($ response == 'L ' ) {
165+ /** @var $row RowInterface */
162166 foreach ($ result as $ i => $ row ) {
163167 $ output ->writeln (sprintf (' - [%d] %s ' , $ i , $ row ->getPath ()));
164168 }
165169
166- return $ this ->getAction ( $ output , $ result );
170+ return $ this ->shouldExecute ( $ input , $ output , $ result );
167171 }
168172
169173 if ($ response == 'N ' ) {
@@ -174,6 +178,6 @@ protected function getAction($output, $result)
174178 return true ;
175179 }
176180
177- return $ this ->getAction ( $ output , $ result );
181+ return $ this ->shouldExecute ( $ input , $ output , $ result );
178182 }
179183}
0 commit comments