2
2
3
3
namespace PHPCR \Util \Console \Command ;
4
4
5
+ use PHPCR \Query \QueryResultInterface ;
6
+ use PHPCR \Query \RowInterface ;
5
7
use Symfony \Component \Console \Input \InputOption ;
6
8
use Symfony \Component \Console \Input \InputInterface ;
7
9
use Symfony \Component \Console \Output \OutputInterface ;
8
- use Symfony \Component \Console \Helper \DialogHelper ;
9
10
10
11
/**
11
12
* Command which can update the properties of nodes found
@@ -110,13 +111,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
110
111
$ result = $ query ->execute ();
111
112
112
113
if (!$ noInteraction ) {
113
- if (false === $ this ->getAction ( $ output , $ result )) {
114
+ if (false === $ this ->shouldExecute ( $ input , $ output , $ result )) {
114
115
return 0 ;
115
116
}
116
117
}
117
118
118
119
$ persistIn = $ persistCounter ;
119
120
121
+ /** @var $row RowInterface */
120
122
foreach ($ result as $ i => $ row ) {
121
123
$ output ->writeln (sprintf (
122
124
"<info>Updating node:</info> [%d] %s. " ,
@@ -149,21 +151,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
149
151
return 0 ;
150
152
}
151
153
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 )
153
158
{
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 (
157
160
'<question>About to update %d nodes. Enter "Y" to continue, "N" to cancel or "L" to list.</question> ' ,
158
161
count ($ result ->getRows ())
159
- ), false ));
162
+ )));
160
163
161
164
if ($ response == 'L ' ) {
165
+ /** @var $row RowInterface */
162
166
foreach ($ result as $ i => $ row ) {
163
167
$ output ->writeln (sprintf (' - [%d] %s ' , $ i , $ row ->getPath ()));
164
168
}
165
169
166
- return $ this ->getAction ( $ output , $ result );
170
+ return $ this ->shouldExecute ( $ input , $ output , $ result );
167
171
}
168
172
169
173
if ($ response == 'N ' ) {
@@ -174,6 +178,6 @@ protected function getAction($output, $result)
174
178
return true ;
175
179
}
176
180
177
- return $ this ->getAction ( $ output , $ result );
181
+ return $ this ->shouldExecute ( $ input , $ output , $ result );
178
182
}
179
183
}
0 commit comments