X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FDatabase%2FLogClearCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FDatabase%2FLogClearCommand.php;h=ac87b803686fda7ad646d02e72bf14b7f7415b9b;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/drupal/console/src/Command/Database/LogClearCommand.php b/vendor/drupal/console/src/Command/Database/LogClearCommand.php new file mode 100644 index 000000000..ac87b8036 --- /dev/null +++ b/vendor/drupal/console/src/Command/Database/LogClearCommand.php @@ -0,0 +1,175 @@ +database = $database; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('database:log:clear') + ->setDescription($this->trans('commands.database.log.clear.description')) + ->addArgument( + 'event-id', + InputArgument::OPTIONAL, + $this->trans('commands.database.log.clear.arguments.event-id') + ) + ->addOption( + 'type', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.database.log.clear.options.type') + ) + ->addOption( + 'severity', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.database.log.clear.options.severity') + ) + ->addOption( + 'user-id', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.database.log.clear.options.user-id') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $eventId = $input->getArgument('event-id'); + $eventType = $input->getOption('type'); + $eventSeverity = $input->getOption('severity'); + $userId = $input->getOption('user-id'); + + if ($eventId) { + $this->clearEvent($io, $eventId); + } else { + $this->clearEvents($io, $eventType, $eventSeverity, $userId); + } + + return 0; + } + + /** + * @param DrupalStyle $io + * @param $eventId + * @return bool + */ + private function clearEvent(DrupalStyle $io, $eventId) + { + $result = $this->database->delete('watchdog')->condition('wid', $eventId)->execute(); + + if (!$result) { + $io->error( + sprintf( + $this->trans('commands.database.log.clear.messages.not-found'), + $eventId + ) + ); + + return false; + } + + $io->success( + sprintf( + $this->trans('commands.database.log.clear.messages.event-deleted'), + $eventId + ) + ); + + return true; + } + + /** + * @param DrupalStyle $io + * @param $eventType + * @param $eventSeverity + * @param $userId + * @return bool + */ + protected function clearEvents(DrupalStyle $io, $eventType, $eventSeverity, $userId) + { + $severity = RfcLogLevel::getLevels(); + $query = $this->database->delete('watchdog'); + + if ($eventType) { + $query->condition('type', $eventType); + } + + if ($eventSeverity) { + if (!in_array($eventSeverity, $severity)) { + $io->error( + sprintf( + $this->trans('commands.database.log.clear.messages.invalid-severity'), + $eventSeverity + ) + ); + + return false; + } + + $query->condition('severity', array_search($eventSeverity, $severity)); + } + + if ($userId) { + $query->condition('uid', $userId); + } + + $result = $query->execute(); + + if (!$result) { + $io->error( + $this->trans('commands.database.log.clear.messages.clear-error') + ); + + return false; + } + + $io->success( + $this->trans('commands.database.log.clear.messages.clear-sucess') + ); + + return true; + } +}