Skip to content

Commit d1d18b0

Browse files
committed
store address in db if test is positive
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent c3a501f commit d1d18b0

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lib/Command/CirclesTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use daita\MySmallPhpTools\Traits\TArrayTools;
3737
use Exception;
3838
use OC\Core\Command\Base;
39+
use OCA\Circles\AppInfo\Application;
3940
use OCA\Circles\Model\GlobalScale\GSEvent;
4041
use OCA\Circles\Service\ConfigService;
4142
use OCA\Circles\Service\GlobalScaleService;
@@ -45,6 +46,7 @@
4546
use Symfony\Component\Console\Input\InputInterface;
4647
use Symfony\Component\Console\Input\InputOption;
4748
use Symfony\Component\Console\Output\OutputInterface;
49+
use Symfony\Component\Console\Question\ConfirmationQuestion;
4850

4951

5052
/**
@@ -157,19 +159,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int
157159
$result[$wrapper->getInstance()] = $wrapper->getEvent();
158160
}
159161

162+
$localLooksGood = false;
160163
foreach ($instances as $instance) {
161164
$output->write($instance . ' ');
162165
if (array_key_exists($instance, $result)
163166
&& $result[$instance]->getResult()
164167
->gInt('status') === 1) {
165168
$output->writeln('<info>ok</info>');
169+
if ($this->configService->isLocalInstance($instance)) {
170+
$localLooksGood = true;
171+
}
166172
} else {
167173
$output->writeln('<error>fail</error>');
168174
}
169175
}
170176

171177
$this->configService->setAppValue(ConfigService::TEST_NC_BASE, '');
172178

179+
if ($localLooksGood) {
180+
$this->saveUrl($input, $output, $input->getOption('url'));
181+
}
182+
173183
return 0;
174184
}
175185

@@ -204,5 +214,40 @@ private function testRequest(OutputInterface $o, string $type, string $route, ar
204214
return false;
205215
}
206216

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+
207252
}
208253

0 commit comments

Comments
 (0)