/** * @test */ public function it_bootstraps_drupal() { if (!function_exists('watchdog_severity_levels')) { $this->fail('Drupal API unavailable'); } $watchdogLevels = watchdog_severity_levels(); $this->assertCount(8, $watchdogLevels, 'Drupal API available'); }
/** * 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} u ON w.uid = u.uid WHERE w.wid = :id', array(':id' => $event_id))->fetchObject()) { $severity = watchdog_severity_levels(); $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; }
/** * Create the filter/sort form at the top of a list of exports. * * This handles the very default conditions, and most lists are expected * to override this and call through to parent::list_form() in order to * get the base form and then modify it as necessary to add search * gadgets for custom fields. */ public function list_form(&$form, &$form_state) { parent::list_form($form, $form_state); $class = _ultimate_cron_get_class('job'); $lock_ids = $class::isLockedMultiple($this->items); $log_entries = $class::loadLatestLogEntries($this->items); $progresses = $class::getProgressMultiple($this->items); foreach ($this->items as $name => $item) { $item->log_entry = isset($item->log_entry) ? $item->log_entry : $log_entries[$name]; $item->progress = isset($item->progress) ? $item->progress : $progresses[$name]; $item->lock_id = isset($item->lock_id) ? $item->lock_id : $lock_ids[$name]; } $form['#attached']['js'][] = drupal_get_path('module', 'ultimate_cron') . '/js/ultimate_cron.js'; if (module_exists('nodejs')) { $settings = _ultimate_cron_plugin_load('settings', 'general')->getDefaultSettings(); if (!empty($settings['nodejs'])) { nodejs_send_content_channel_token('ultimate_cron'); $form['#attached']['js'][] = drupal_get_path('module', 'ultimate_cron') . '/js/ultimate_cron.nodejs.js'; } } // There's no normal for Ultimate Cron! unset($form['top row']['storage']['#options'][t('Normal')]); $all = array('all' => t('- All -')); $options = $all + array('running' => 'running', -1 => 'no info') + watchdog_severity_levels(); $form['top row']['status'] = array('#type' => 'select', '#title' => t('Status'), '#options' => $options, '#default_value' => 'all', '#weight' => -2); $jobs = ultimate_cron_get_hooks(); $modules = array(); foreach ($jobs as $job) { $info = system_get_info('module', $job['module']); $modules[$job['module']] = $info && !empty($info['name']) ? $info['name'] : $job['module']; } $form['top row']['module'] = array('#type' => 'select', '#title' => t('Module'), '#options' => $all + $modules, '#default_value' => 'all', '#weight' => -1); $form['bottom row']['reload'] = array('#type' => 'submit', '#id' => 'ctools-export-ui-list-items-reload', '#value' => t('Reload'), '#attributes' => array('class' => array('use-ajax-submit'))); }
/** * Format a watchdog message in a one-line summary. * * @param $message * A watchdog messsage object. * @return * A string containing the watchdog message's timestamp, severity, type, * and actual message. */ private function formatWatchdogMessage($message) { static $levels; if (!isset($levels)) { module_load_include('admin.inc', 'dblog'); $levels = watchdog_severity_levels(); } return t('@timestamp - @severity - @type - !message', array('@timestamp' => $message->timestamp, '@severity' => $levels[$message->severity], '@type' => $message->type)); }