|
36 | 36 | use daita\MySmallPhpTools\Traits\TArrayTools; |
37 | 37 | use Exception; |
38 | 38 | use OC\Core\Command\Base; |
| 39 | +use OCA\Circles\AppInfo\Application; |
39 | 40 | use OCA\Circles\Model\GlobalScale\GSEvent; |
40 | 41 | use OCA\Circles\Service\ConfigService; |
41 | 42 | use OCA\Circles\Service\GlobalScaleService; |
|
45 | 46 | use Symfony\Component\Console\Input\InputInterface; |
46 | 47 | use Symfony\Component\Console\Input\InputOption; |
47 | 48 | use Symfony\Component\Console\Output\OutputInterface; |
| 49 | +use Symfony\Component\Console\Question\ConfirmationQuestion; |
48 | 50 |
|
49 | 51 |
|
50 | 52 | /** |
@@ -157,19 +159,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
157 | 159 | $result[$wrapper->getInstance()] = $wrapper->getEvent(); |
158 | 160 | } |
159 | 161 |
|
| 162 | + $localLooksGood = false; |
160 | 163 | foreach ($instances as $instance) { |
161 | 164 | $output->write($instance . ' '); |
162 | 165 | if (array_key_exists($instance, $result) |
163 | 166 | && $result[$instance]->getResult() |
164 | 167 | ->gInt('status') === 1) { |
165 | 168 | $output->writeln('<info>ok</info>'); |
| 169 | + if ($this->configService->isLocalInstance($instance)) { |
| 170 | + $localLooksGood = true; |
| 171 | + } |
166 | 172 | } else { |
167 | 173 | $output->writeln('<error>fail</error>'); |
168 | 174 | } |
169 | 175 | } |
170 | 176 |
|
171 | 177 | $this->configService->setAppValue(ConfigService::TEST_NC_BASE, ''); |
172 | 178 |
|
| 179 | + if ($localLooksGood) { |
| 180 | + $this->saveUrl($input, $output, $input->getOption('url')); |
| 181 | + } |
| 182 | + |
173 | 183 | return 0; |
174 | 184 | } |
175 | 185 |
|
@@ -204,5 +214,40 @@ private function testRequest(OutputInterface $o, string $type, string $route, ar |
204 | 214 | return false; |
205 | 215 | } |
206 | 216 |
|
| 217 | + |
| 218 | + /** |
| 219 | + * @param InputInterface $input |
| 220 | + * @param OutputInterface $output |
| 221 | + * @param string $address |
| 222 | + */ |
| 223 | + private function saveUrl(InputInterface $input, OutputInterface $output, string $address): void { |
| 224 | + if ($address === '') { |
| 225 | + return; |
| 226 | + } |
| 227 | + |
| 228 | + $output->writeln(''); |
| 229 | + $output->writeln( |
| 230 | + 'The address <info>' . $address . '</info> seems to reach your local Nextcloud.' |
| 231 | + ); |
| 232 | + |
| 233 | + $helper = $this->getHelper('question'); |
| 234 | + $output->writeln(''); |
| 235 | + $question = new ConfirmationQuestion( |
| 236 | + '<info>Do you want to store this address in database ?</info> (y/N) ', false, '/^(y|Y)/i' |
| 237 | + ); |
| 238 | + |
| 239 | + if (!$helper->ask($input, $output, $question)) { |
| 240 | + $output->writeln('Configuration NOT saved'); |
| 241 | + |
| 242 | + return; |
| 243 | + } |
| 244 | + |
| 245 | + $this->configService->setAppValue(ConfigService::FORCE_NC_BASE, $address); |
| 246 | + $output->writeln( |
| 247 | + 'New configuration <info>' . Application::APP_NAME . '.' . ConfigService::FORCE_NC_BASE . '=\'' |
| 248 | + . $address . '\'</info> stored in database' |
| 249 | + ); |
| 250 | + } |
| 251 | + |
207 | 252 | } |
208 | 253 |
|
0 commit comments