|
14 | 14 | use OCA\Files_External\NotFoundException; |
15 | 15 | use OCA\Files_External\Service\GlobalStoragesService; |
16 | 16 | use OCP\AppFramework\Http; |
| 17 | +use OCP\EventDispatcher\IEventDispatcher; |
17 | 18 | use OCP\Files\StorageNotAvailableException; |
| 19 | +use OCP\Log\BeforeMessageLoggedEvent; |
18 | 20 | use Symfony\Component\Console\Input\InputArgument; |
19 | 21 | use Symfony\Component\Console\Input\InputInterface; |
20 | 22 | use Symfony\Component\Console\Input\InputOption; |
21 | 23 | use Symfony\Component\Console\Output\OutputInterface; |
22 | 24 |
|
23 | 25 | class Verify extends Base { |
| 26 | + /// formatting tags for the various log levels |
| 27 | + public const FORMATTING = ['comment', 'comment', 'comment', 'error', 'error']; |
| 28 | + |
24 | 29 | public function __construct( |
25 | 30 | protected GlobalStoragesService $globalService, |
| 31 | + protected IEventDispatcher $eventDispatcher, |
26 | 32 | ) { |
27 | 33 | parent::__construct(); |
28 | 34 | } |
@@ -57,13 +63,36 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
57 | 63 | return Http::STATUS_NOT_FOUND; |
58 | 64 | } |
59 | 65 |
|
| 66 | + $logMessages = []; |
| 67 | + $logListener = null; |
| 68 | + if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
| 69 | + $logListener = function (BeforeMessageLoggedEvent $event) use (&$logMessages) { |
| 70 | + $format = self::FORMATTING[$event->getLevel()]; |
| 71 | + $logMessages[] = " - <$format>" . $event->getMessage()['message'] . "</$format>"; |
| 72 | + }; |
| 73 | + $this->eventDispatcher->addListener(BeforeMessageLoggedEvent::class, $logListener); |
| 74 | + } |
| 75 | + |
60 | 76 | $this->updateStorageStatus($mount, $configInput, $output); |
61 | 77 |
|
| 78 | + if ($logListener) { |
| 79 | + $this->eventDispatcher->removeListener(BeforeMessageLoggedEvent::class, $logListener); |
| 80 | + } |
| 81 | + |
62 | 82 | $this->writeArrayInOutputFormat($input, $output, [ |
63 | 83 | 'status' => StorageNotAvailableException::getStateCodeName($mount->getStatus()), |
64 | 84 | 'code' => $mount->getStatus(), |
65 | 85 | 'message' => $mount->getStatusMessage() |
66 | 86 | ]); |
| 87 | + |
| 88 | + if (count($logMessages)) { |
| 89 | + $output->writeln(''); |
| 90 | + $output->writeln('Messages logged during validation:'); |
| 91 | + foreach ($logMessages as $logMessage) { |
| 92 | + $output->writeln($logMessage); |
| 93 | + } |
| 94 | + } |
| 95 | + |
67 | 96 | return self::SUCCESS; |
68 | 97 | } |
69 | 98 |
|
|
0 commit comments