/** * @param \Drupal\Console\Style\DrupalStyle $io * @param $eventType * @param $eventSeverity * @param $userId * @return bool */ protected function clearEvents(DrupalStyle $io, $eventType, $eventSeverity, $userId) { $connection = $this->getDatabase(); $severity = RfcLogLevel::getLevels(); $query = $connection->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; }
protected function clearEvents($event_type, $event_severity, $user_id, $output) { $connection = $this->getDatabase(); $severity = RfcLogLevel::getLevels(); $query = $connection->delete('watchdog'); if (!empty($event_type)) { $query->condition('type', $event_type); } if (!empty($event_severity) && in_array($event_severity, $severity)) { $query->condition('severity', array_search($event_severity, $severity)); } elseif (!empty($event_severity)) { $output->writeln('[-] <error>' . sprintf($this->trans('commands.database.log.clear.messages.invalid-severity'), $event_severity) . '</error>'); } if (!empty($user_id)) { $query->condition('uid', $user_id); } $result = $query->execute(); if (!$result) { $output->writeln('[+] <error>' . $this->trans('commands.database.log.clear.messages.clear-error') . '</error>'); return false; } else { $output->writeln('[+] <info>' . $this->trans('commands.database.log.clear.messages.clear-sucess') . '</info>'); return true; } }
protected function clearEvents($event_type, $event_severity, $user_id, $output) { $table = $this->getTableHelper(); $table->setlayout($table::LAYOUT_COMPACT); $connection = $this->getDatabase(); $date_formatter = $this->getDateFormatter(); $user_storage = $this->getEntityManager()->getStorage('user'); $severity = RfcLogLevel::getLevels(); $query = $connection->delete('watchdog'); if (!empty($event_type)) { $query->condition('type', $event_type); } if (!empty($event_severity) && in_array($event_severity, $severity)) { $query->condition('severity', array_search($event_severity, $severity)); } elseif (!empty($event_severity)) { $output->writeln('[-] <error>' . sprintf($this->trans('commands.dblog.debug.messages.invalid-severity'), $event_severity) . '</error>'); } if (!empty($user_id)) { $query->condition('uid', $user_id); } $result = $query->execute(); if (!$result) { $output->writeln('[+] <error>' . $this->trans('commands.dblog.clear.messages.clear-error') . '</error>'); return false; } else { $output->writeln('[+] <info>' . $this->trans('commands.dblog.clear.messages.clear-sucess') . '</info>'); return true; } }
protected function getAllEvents($event_type, $event_severity, $user_id, $offset, $limit, $output) { $table = new Table($output); $table->setStyle('compact'); $connection = $this->getDatabase(); $date_formatter = $this->getDateFormatter(); $user_storage = $this->getEntityManager()->getStorage('user'); $severity = RfcLogLevel::getLevels(); $query = $connection->select('watchdog', 'w'); $query->fields('w', array('wid', 'uid', 'severity', 'type', 'timestamp', 'message', 'variables')); if (!empty($event_type)) { $query->condition('type', $event_type); } if (!empty($event_severity) && in_array($event_severity, $severity)) { $query->condition('severity', array_search($event_severity, $severity)); } elseif (!empty($event_severity)) { $output->writeln('[-] <error>' . sprintf($this->trans('commands.database.log.debug.messages.invalid-severity'), $event_severity) . '</error>'); } if (!empty($user_id)) { $query->condition('uid', $user_id); } if (!$offset) { $offset = 0; } if ($limit) { $query->range($offset, $limit); } $result = $query->execute(); $table->setHeaders([$this->trans('commands.database.log.debug.messages.event-id'), $this->trans('commands.database.log.debug.messages.type'), $this->trans('commands.database.log.debug.messages.date'), $this->trans('commands.database.log.debug.messages.message'), $this->trans('commands.database.log.debug.messages.user'), $this->trans('commands.database.log.debug.messages.severity')]); foreach ($result as $dblog) { $user = $user_storage->load($dblog->uid); $table->addRow([$dblog->wid, $dblog->type, $date_formatter->format($dblog->timestamp, 'short'), Unicode::truncate(Html::decodeEntities(strip_tags($this->formatMessage($dblog))), 56, true, true), $user->getUsername() . ' (' . $user->id() . ')', $severity[$dblog->severity]]); } $table->render(); }
protected function getAllEvents(DrupalStyle $io, $eventType, $eventSeverity, $userId, $asc, $offset, $limit) { $connection = $this->getDrupalService('database'); $dateFormatter = $this->getDrupalService('date.formatter'); $userStorage = $this->getDrupalService('entity_type.manager')->getStorage('user'); $severity = RfcLogLevel::getLevels(); $query = $connection->select('watchdog', 'w'); $query->fields('w', ['wid', 'uid', 'severity', 'type', 'timestamp', 'message', 'variables']); if ($eventType) { $query->condition('type', $eventType); } if ($eventSeverity) { if (!in_array($eventSeverity, $severity)) { $io->error(sprintf($this->trans('commands.database.log.debug.messages.invalid-severity'), $eventSeverity)); return false; } $query->condition('severity', array_search($eventSeverity, $severity)); } if ($userId) { $query->condition('uid', $userId); } if ($asc) { $query->orderBy('wid', 'ASC'); } else { $query->orderBy('wid', 'DESC'); } if ($limit) { $query->range($offset, $limit); } $result = $query->execute(); $tableHeader = [$this->trans('commands.database.log.debug.messages.event-id'), $this->trans('commands.database.log.debug.messages.type'), $this->trans('commands.database.log.debug.messages.date'), $this->trans('commands.database.log.debug.messages.message'), $this->trans('commands.database.log.debug.messages.user'), $this->trans('commands.database.log.debug.messages.severity')]; $tableRows = []; foreach ($result as $dblog) { $user = $userStorage->load($dblog->uid); $tableRows[] = [$dblog->wid, $dblog->type, $dateFormatter->format($dblog->timestamp, 'short'), Unicode::truncate(Html::decodeEntities(strip_tags($this->formatMessage($dblog))), 56, true, true), $user->getUsername() . ' (' . $user->id() . ')', $severity[$dblog->severity]]; } $io->table($tableHeader, $tableRows); return true; }
/** * Displays details about a specific database log message. * * @param int $event_id * Unique ID of the database log message. * * @return array * If the ID is located in the Database Logging table, a build array in the * format expected by drupal_render(); * */ public function eventDetails($event_id) { $build = array(); if ($dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', array(':id' => $event_id))->fetchObject()) { $severity = RfcLogLevel::getLevels(); $message = $this->formatMessage($dblog); $username = array('#theme' => 'username', '#account' => $dblog->uid ? $this->userStorage->load($dblog->uid) : User::getAnonymousUser()); $rows = array(array(array('data' => $this->t('Type'), 'header' => TRUE), $this->t($dblog->type)), array(array('data' => $this->t('Date'), 'header' => TRUE), $this->dateFormatter->format($dblog->timestamp, 'long')), array(array('data' => $this->t('User'), 'header' => TRUE), array('data' => $username)), array(array('data' => $this->t('Location'), 'header' => TRUE), $this->l($dblog->location, $dblog->location ? Url::fromUri($dblog->location) : Url::fromRoute('<none>'))), array(array('data' => $this->t('Referrer'), 'header' => TRUE), $this->l($dblog->referer, $dblog->referer ? Url::fromUri($dblog->referer) : Url::fromRoute('<none>'))), array(array('data' => $this->t('Message'), 'header' => TRUE), $message), array(array('data' => $this->t('Severity'), 'header' => TRUE), $severity[$dblog->severity]), array(array('data' => $this->t('Hostname'), 'header' => TRUE), SafeMarkup::checkPlain($dblog->hostname)), array(array('data' => $this->t('Operations'), 'header' => TRUE), SafeMarkup::checkAdminXss($dblog->link))); $build['dblog_table'] = array('#type' => 'table', '#rows' => $rows, '#attributes' => array('class' => array('dblog-event')), '#attached' => array('library' => array('dblog/drupal.dblog'))); } return $build; }
/** * Displays details about a specific database log message. * * @param int $event_id * Unique ID of the database log message. * * @return array * If the ID is located in the Database Logging table, a build array in the * format expected by drupal_render(); * */ public function eventDetails($event_id) { $build = array(); if ($dblog = $this->database->query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users_field_data} u ON w.uid = u.uid WHERE w.wid = :id AND u.default_langcode = 1', array(':id' => $event_id))->fetchObject()) { $severity = RfcLogLevel::getLevels(); $message = $this->formatMessage($dblog); $username = array('#theme' => 'username', '#account' => user_load($dblog->uid)); $rows = array(array(array('data' => $this->t('Type'), 'header' => TRUE), $this->t($dblog->type)), array(array('data' => $this->t('Date'), 'header' => TRUE), $this->dateFormatter->format($dblog->timestamp, 'long')), array(array('data' => $this->t('User'), 'header' => TRUE), array('data' => $username)), array(array('data' => $this->t('Location'), 'header' => TRUE), _l($dblog->location, $dblog->location)), array(array('data' => $this->t('Referrer'), 'header' => TRUE), _l($dblog->referer, $dblog->referer)), array(array('data' => $this->t('Message'), 'header' => TRUE), $message), array(array('data' => $this->t('Severity'), 'header' => TRUE), $severity[$dblog->severity]), array(array('data' => $this->t('Hostname'), 'header' => TRUE), String::checkPlain($dblog->hostname)), array(array('data' => $this->t('Operations'), 'header' => TRUE), $dblog->link)); $build['dblog_table'] = array('#type' => 'table', '#rows' => $rows, '#attributes' => array('class' => array('dblog-event')), '#attached' => array('library' => array('dblog/drupal.dblog'))); } return $build; }