3 namespace Drupal\Console\Command\Database;
5 use Drupal\Console\Core\Style\DrupalStyle;
6 use Symfony\Component\Console\Input\InputArgument;
7 use Symfony\Component\Console\Input\InputInterface;
8 use Symfony\Component\Console\Output\OutputInterface;
11 * Class LogPollCommand
13 * @package Drupal\Console\Command\Database
15 class LogPollCommand extends DatabaseLogBase
25 protected function execute(InputInterface $input, OutputInterface $output)
27 $io = new DrupalStyle($input, $output);
29 $io->note($this->trans('commands.database.log.poll.messages.warning'));
31 $this->getDefaultOptions($input);
32 $this->duration = $input->getArgument('duration');
34 $this->pollForEvents($io);
40 protected function configure()
43 ->setName('database:log:poll')
44 ->setDescription($this->trans('commands.database.log.poll.description'));
46 $this->addDefaultLoggingOptions();
50 InputArgument::OPTIONAL,
51 $this->trans('commands.database.log.poll.arguments.duration'),
57 * @param DrupalStyle $io
59 protected function pollForEvents(DrupalStyle $io)
61 $query = $this->makeQuery($io)->countQuery();
62 $results = $query->execute()->fetchAssoc();
63 $count = $results['expression'] - 1;//minus 1 so the newest message always prints
65 $tableHeader = $this->createTableHeader();
67 //Poll, force no wait on first loop
68 $lastExec = time() - $this->duration;
70 if (time() > $lastExec + $this->duration) {
71 //Print out any new db logs
72 $query = $this->makeQuery($io, $count);
73 $results = $query->execute()->fetchAll();
74 $count += count($results);
76 foreach ($results as $r) {
77 $tableRows[] = $this->createTableRow($r);
79 if (!empty($tableRows)) {
80 $io->table($tableHeader, $tableRows);
82 //update the last exec time