diff --git a/config/install/past.settings.yml b/config/install/past.settings.yml index 73396e9..946b7c9 100644 --- a/config/install/past.settings.yml +++ b/config/install/past.settings.yml @@ -6,15 +6,11 @@ shutdown_handling: true log_session_id: true max_recursion: 10 backtrace_include: - # @todo Convert to string sequence: - # - PAST_SEVERITY_ERROR - # - PAST_SEVERITY_WARNING - # etc. - WATCHDOG_SEVERITY_0: 'WATCHDOG_SEVERITY_0' - WATCHDOG_SEVERITY_1: 'WATCHDOG_SEVERITY_1' - WATCHDOG_SEVERITY_2: 'WATCHDOG_SEVERITY_2' - WATCHDOG_SEVERITY_3: 'WATCHDOG_SEVERITY_3' - WATCHDOG_SEVERITY_4: 'WATCHDOG_SEVERITY_4' - WATCHDOG_SEVERITY_5: 'WATCHDOG_SEVERITY_5' - WATCHDOG_SEVERITY_6: '' - WATCHDOG_SEVERITY_7: '' + WATCHDOG_SEVERITY_EMERGENCY: true + WATCHDOG_SEVERITY_ALERT: true + WATCHDOG_SEVERITY_CRITICAL: true + WATCHDOG_SEVERITY_ERROR: true + WATCHDOG_SEVERITY_WARNING: true + WATCHDOG_SEVERITY_NOTICE: true + WATCHDOG_SEVERITY_INFO: false + WATCHDOG_SEVERITY_DEBUG: false diff --git a/config/schema/past.schema.yml b/config/schema/past.schema.yml index 7f35fba..153addb 100644 --- a/config/schema/past.schema.yml +++ b/config/schema/past.schema.yml @@ -29,4 +29,4 @@ past.settings: type: sequence label: 'Include watchdog severity levels from writing backtraces' sequence: - type: string + type: boolean diff --git a/modules/past_db/config/schema/past_db.views.schema.yml b/modules/past_db/config/schema/past_db.views.schema.yml new file mode 100644 index 0000000..74c9bb2 --- /dev/null +++ b/modules/past_db/config/schema/past_db.views.schema.yml @@ -0,0 +1,13 @@ +# Schema for the views plugins of the past_db module. + +views.field.past_db_event_argument_data: + type: views_field + label: 'Event Argument Data' + +views.field.past_db_event_argument_value: + type: views_filter + label: 'Event Argument Value' + +views.field.past_db_trace_user: + type: views_field + label: 'Trace User' diff --git a/modules/past_db/past_db.controller.inc b/modules/past_db/past_db.controller.inc deleted file mode 100644 index 359e556..0000000 --- a/modules/past_db/past_db.controller.inc +++ /dev/null @@ -1,180 +0,0 @@ -type)) { - $entity->type = 'past_event'; - } - if (empty($entity->timestamp)) { - $entity->timestamp = REQUEST_TIME; - } - if (empty($entity->severity)) { - $entity->severity = PAST_SEVERITY_INFO; - } - if (empty($entity->uid) && !empty($GLOBALS['user'])) { - $entity->uid = $GLOBALS['user']->uid; - } - return $entity; - } - - /** - * {@inheritdoc} - */ - public function save($entity, DatabaseTransaction $transaction = NULL) { - /* @var PastEvent $entity */ - // Limit length of message. - if (strlen($entity->message) > 255) { - $entity->message = substr($entity->message, 0, 250) . '...'; - } - parent::save($entity, $transaction); - - // Save the arguments. - foreach ($entity->getArguments() as $argument) { - $argument->event_id = $entity->event_id; - $argument->save(); - } - - // Update child events to use the parent_event_id. - if ($child_events = $entity->getChildEvents()) { - db_update('past_event') - ->fields(array( - 'parent_event_id' => $entity->event_id, - )) - ->condition('event_id', $child_events) - ->execute(); - } - - // If running in a WebTestCase environment, propagate the log into - // simpletest log. - } - - /** - * {@inheritdoc} - */ - public function delete($ids, \DatabaseTransaction $transaction = NULL) { - // Delete the arguments first. - $query = new EntityFieldQuery(); - $query->entityCondition('entity_type', 'past_event_argument'); - $query->propertyCondition('event_id', $ids); - $result = $query->execute(); - if ($result) { - entity_delete_multiple('past_event_argument', array_keys($result['past_event_argument'])); - } - - parent::delete($ids, $transaction); - } - -} - -/** - * Controller class for the Entity Metadata. - */ -class PastDBEventMetadataController extends EntityDefaultMetadataController { - protected static $modules = array(); - - /** - * Overrides EntityDefaultMetadataController::entityPropertyInfo(). - */ - public function entityPropertyInfo() { - // Loading property information and make em better usable in here. - $info = parent::entityPropertyInfo(); - $prop = &$info[$this->type]['properties']; - - // The timestamp should be rendered/shown as a date. - $prop['timestamp']['type'] = 'date'; - $prop['severity']['options list'] = 'past_event_severities'; - $prop['uid'] = array( - 'label' => t('User'), - 'type' => 'user', - 'description' => t('The user who triggered the event.'), - 'setter callback' => 'entity_property_verbatim_set', - 'schema field' => 'uid', - ); - - return $info; - } -} - -/** - * Implements the default UI Controller. - */ -class PastDBEventUIController extends EntityDefaultUIController { - - /** - * Overrides EntityDefaultUIController::hook_menu(). - */ - public function hook_menu() { - $id_count = count(explode('/', $this->path)); - $plural_label = isset($this->entityInfo['plural label']) ? $this->entityInfo['plural label'] : $this->entityInfo['label'] . 's'; - $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object'; - $items[$this->path . '/' . $wildcard] = array( - 'title callback' => 'entity_label', - 'title arguments' => array($this->entityType, $id_count), - 'page callback' => 'past_db_event_view', - 'page arguments' => array($id_count), - 'load arguments' => array($this->entityType), - 'access callback' => 'entity_access', - 'access arguments' => array('view', $this->entityType, $id_count), - ); - return $items; - } -} - -/** - * Controller class for the Past Argument Metadata. - */ -class PastDBEventArgumentMetadataController extends EntityDefaultMetadataController { - - /** - * Overrides EntityDefaultMetadataController::entityPropertyInfo(). - */ - public function entityPropertyInfo() { - $info = parent::entityPropertyInfo(); - - $properties = &$info[$this->type]['properties']; - - // Link the event id property to the corresponding event entity. - $properties['event_id']['type'] = 'past_event'; - - return $info; - } -} - -/** - * Controller class for the Past Data Metadata. - */ -class PastDBEventDataMetadataController extends EntityDefaultMetadataController { - - /** - * Overrides EntityDefaultMetadataController::entityPropertyInfo(). - */ - public function entityPropertyInfo() { - $info = parent::entityPropertyInfo(); - - $properties = &$info[$this->type]['properties']; - - // Link the argument id property to the corresponding argument entity. - $properties['argument_id']['type'] = 'past_event_argument'; - - return $info; - } -} diff --git a/modules/past_db/past_db.drush.inc b/modules/past_db/past_db.drush.inc index c31c9e5..e97b18b 100644 --- a/modules/past_db/past_db.drush.inc +++ b/modules/past_db/past_db.drush.inc @@ -5,6 +5,8 @@ * Past DB commands for Drush. */ +use Drupal\past_db\PastEventArgument; + /** * Implements hook_drush_command(). */ @@ -85,7 +87,7 @@ function drush_past_db_past_show($arg = NULL) { * The id of the message to show. */ function past_db_drush_show_one($event_id) { - $event = entity_load('past_event', $event_id); + $event = \Drupal::entityManager()->loadEntityByUuid('past_event', $event_id); if (!$event) { return drush_set_error(dt('Past event #!event_id not found.', array('!event_id' => $event_id))); } @@ -396,25 +398,24 @@ function drush_core_watchdog_delete($arg = NULL) { * @param string $machine_name * (optional) Machine name. * - * @return EntityFieldQuery - * False or array with structure ('where' => string, 'args' => array()) + * @return \Drupal\Core\Entity\Query\QueryInterface + * The query object that can query the given entity type. **/ function past_db_drush_query_events($filter = NULL, $severity = NULL, $module = NULL, $machine_name = NULL) { - $query = new EntityFieldQuery(); - $query->entityCondition('entity_type', 'past_event'); + $query = \Drupal::entityQuery('past_event'); if ($severity) { - $query->propertyCondition('severity', $severity, '<='); + $query->condition('severity', $severity, '<='); } if ($filter) { - $query->propertyCondition('message', $filter, 'CONTAINS'); + $query->condition('message', $filter, 'CONTAINS'); } if ($module) { - $query->propertyCondition('module', $module); + $query->condition('module', $module); } if ($machine_name) { - $query->propertyCondition('machine_name', $machine_name); + $query->condition('machine_name', $machine_name); } - $query->propertyOrderBy('event_id', 'DESC'); + $query->sort('event_id', 'DESC'); return $query; } diff --git a/modules/past_db/past_db.module b/modules/past_db/past_db.module index 317fc8f..3a18f1c 100644 --- a/modules/past_db/past_db.module +++ b/modules/past_db/past_db.module @@ -5,11 +5,14 @@ * Module file for the Past DB module. */ -use Drupal\past\PastEventInterface; use \Drupal\past_db\Entity\PastEvent; /** * Entity URI callback for image style. + * + * @param \Drupal\past_db\Entity\PastEvent $event + * + * @return array */ function past_event_entity_uri(PastEvent $event) { return array( @@ -18,70 +21,6 @@ function past_event_entity_uri(PastEvent $event) { } /** - * Implements hook_entity_info(). - */ -function past_db_entity_info() { - $info['past_event'] = array( - 'label' => t('Past Event'), - 'module' => 'past_db', - 'fieldable' => TRUE, - 'controller class' => 'PastEventController', - 'metadata controller class' => 'PastDBEventMetadataController', - 'views controller class' => 'PastDBEventViewsController', - 'entity class' => 'PastEvent', - 'base table' => 'past_event', - 'uri callback' => 'entity_class_uri', - 'label callback' => 'entity_class_label', - 'access callback' => 'past_db_access', - 'entity keys' => array( - 'id' => 'event_id', - 'bundle' => 'type', - ), - 'bundle keys' => array( - 'bundle' => 'type', - ), - 'bundles' => array(), - 'admin ui' => array( - 'controller class' => 'PastDBEventUIController', - 'path' => 'admin/reports/past', - 'menu wildcard' => '%entity_object', - ), - ); - - $info['past_event_argument'] = array( - 'label' => t('Past Event Argument'), - 'module' => 'past_db', - 'controller class' => 'PastEventArgumentController', - 'metadata controller class' => 'PastDBEventArgumentMetadataController', - 'entity class' => 'PastEventArgument', - 'base table' => 'past_event_argument', - 'uri callback' => 'entity_class_uri', - 'label callback' => 'entity_class_label', - 'access callback' => 'past_db_access', - 'entity keys' => array( - 'id' => 'argument_id', - ), - ); - - $info['past_event_data'] = array( - 'label' => t('Past Event Data'), - 'module' => 'past_db', - 'controller class' => 'EntityAPIController', - 'metadata controller class' => 'PastDBEventDataMetadataController', - 'entity class' => 'PastEventData', - 'base table' => 'past_event_data', - 'uri callback' => 'entity_class_uri', - 'label callback' => 'entity_class_label', - 'access callback' => 'past_db_access', - 'entity keys' => array( - 'id' => 'data_id', - ), - ); - - return $info; -} - -/** * Menu argument loader; Load a event type by string. * * @param string $type @@ -104,12 +43,15 @@ function past_event_type_load($type) { * @param array $values * Additional event type values. * - * @return PastEventType + * @return \Drupal\past_db\Entity\PastEventType + * The Past Event Type crated. */ function past_event_type_create($type, $label, $values = array()) { $values['id'] = $type; $values['label'] = $label; - return entity_create('past_event_type', $values); + return \Drupal::entityManager() + ->getStorage('past_event_type') + ->create($values); } /** @@ -118,40 +60,53 @@ function past_event_type_create($type, $label, $values = array()) { * @param string $type_name * If set, the type with the given name is returned. * - * @return PastEventType[] - * Depending whether $type isset, an array of past event types or a single one. + * @return \Drupal\past_db\Entity\PastEventType[] + * Depending whether $type isset, + * an array of past event types or a single one. */ function past_event_get_types($type_name = NULL) { $properties = array(); if (!empty($type_name)) { $properties['id'] = $type_name; } - $types = entity_load_multiple_by_properties('past_event_type', $properties); + $types = \Drupal::entityManager() + ->getStorage('past_event_type') + ->loadByProperties($properties); return isset($type_name) ? reset($types) : $types; } /** * Access callback for the entity API. + * + * @param string $op + * The performed operation - view, delete, create, update, customs... + * @param $type + * (optional) The entity type on which $operation should be performed. + * @param \Drupal\Core\Session\AccountInterface $account + * (optional) The account to check if it has access. + * + * @return bool + * TRUE if $account can perform $operation on $entity */ function past_event_type_access($op, $type = NULL, $account = NULL) { - return user_access('administer past', $account); + return $account->hasPermission('administer past'); } /** * Access callback implementation. * - * @param $op + * @param string $op * The performed operation - view, delete, create, update, customs... * @param $entity * (optional) The entity on which $operation should be performed. - * @param $account + * @param \Drupal\Core\Session\AccountInterface $account * (optional) The account to check if it has access. * - * @return boolean + * @return bool * TRUE if $account can perform $operation on $entity */ function past_db_access($op, $entity = NULL, $account = NULL) { - return user_access('administer past', $account); + return $account->hasPermission('administer past'); } /** @@ -159,30 +114,22 @@ function past_db_access($op, $entity = NULL, $account = NULL) { */ function past_db_cron() { // Check if expiration is enabled. - if ($expire = \Drupal::config('past_settings')->get('events_expire', 0)) { + if ($expire = \Drupal::config('past_settings')->get('events_expire')) { // Fetch up to 100 past events to delete, delete oldest first. - $query = new EntityFieldQuery(); - $query->entityCondition('entity_type', 'past_event'); - $query->propertyCondition('timestamp', REQUEST_TIME - $expire, '<'); - $query->propertyOrderBy('timestamp'); + $query = \Drupal::entityQuery('past_event'); + $query->condition('timestamp', REQUEST_TIME - $expire, '<'); + $query->sort('timestamp'); $query->range(0, 100); $result = $query->execute(); if ($result) { - entity_delete_multiple('past_event', array_keys($result['past_event'])); + $controller = \Drupal::entityManager()->getStorage('past_event'); + $entities = $controller->loadMultiple(array_keys($result['past_event'])); + $controller->delete($entities); } } } /** - * Implements views arguments details. - * - * defined in PastDBEventUIController::hook_menu(). - */ -function past_db_event_view($event) { - return entity_view($event->entityType(), array($event), 'full', NULL, TRUE); -} - -/** * Implements hook_views_api(). */ function past_db_views_api() { @@ -336,11 +283,15 @@ function past_db_entity_extra_field_info() { /** * Returns an event object. * - * @return PastEventInterface + * @param array $options + * (optional) An array of values to set. + * + * @return \Drupal\past\PastEventInterface A new Past event instance. * A new Past event instance. */ function past_db_create_event(array $options = array()) { if (\Drupal::entityManager()->hasDefinition('past_event')) { - return entity_create('past_event', $options); + return \Drupal::entityManager()->getStorage('past_event')->create($options); } + return new \Drupal\past\PastEventNull(); } diff --git a/modules/past_db/src/Entity/PastEvent.php b/modules/past_db/src/Entity/PastEvent.php index 631382d..6e239f5 100644 --- a/modules/past_db/src/Entity/PastEvent.php +++ b/modules/past_db/src/Entity/PastEvent.php @@ -7,17 +7,22 @@ namespace Drupal\past_db\Entity; +use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Drupal\Core\Utility\Error; use Drupal\past\PastEventArgumentInterface; use Drupal\past\PastEventInterface; use Drupal\past_db\PastEventArgument; +use Drupal\user\Entity\User; use Exception; /** @@ -489,50 +494,52 @@ class PastEvent extends ContentEntityBase implements PastEventInterface { * * @param int $truncate * (optional) Truncate the session ID in case no user exists to the given - * length. FALSE to disable, defaults to 20ยท + * length. FALSE to disable, defaults to 20. * @param string $uri * (optional) The uri to be used for the trace links, defaults to the * extended view. * - * @return sting + * @return string * The rendered links. */ public function getActorDropbutton($truncate = 20, $uri = 'admin/reports/past/extended') { $links = array(); - $account = user_load((int) $this->getUid()); + /** @var AccountInterface $account */ + $account = User::load($this->getUid()); $sid = $this->getSessionId(); // If we have a user, display a dropbutton with link to the user profile and // a trace link and optionally a trace by session link. - if ($account && $account->uid > 0) { + if ($account && $account->id() > 0) { $links[] = array( - 'title' => format_username($account), - 'href' => drupal_get_path_alias('user/' . $account->uid), + 'title' => $account->getUsername(), + 'href' => \Drupal::service('path.alias_manager.cached')->getPathAlias('user/' . $account->id()), 'attributes' => array('title' => t('View profile')), ); $links[] = array( - 'title' => t('Trace: !user', array('!user' => format_username($account))), + 'title' => t('Trace: !user', array('!user' => $account->getUsername())), 'href' => $uri, - 'query' => array('uid' => $account->name), + 'query' => array('uid' => $account->getUsername()), ); if (!empty($sid)) { $links[] = array( 'title' => t('Trace session: @session', array( - '@session' => truncate_utf8($sid, 10, FALSE, TRUE))), + '@session' => Unicode::truncate($sid, 10, FALSE, TRUE), + )), 'href' => $uri, 'query' => array('session_id' => $sid), - 'attributes' => array('title' => check_plain($sid)), + 'attributes' => array('title' => Html::escape($sid)), ); } module_load_include('inc', 'views', 'includes/admin'); - views_ui_add_admin_css(); - return theme('links__ctools_dropbutton', array('links' => $links)); + return $links; } // If we only have a session ID, display that. if ($sid) { $title = t('Session: @session', array( - '@session' => $truncate ? truncate_utf8($sid, $truncate, FALSE, TRUE) : $sid)); - return l($title, $uri, array('query' => array('session_id' => $sid))); + '@session' => $truncate ? Unicode::truncate($sid, $truncate, FALSE, TRUE) : $sid, + )); + return \Drupal::l($title, Url::fromUri($uri), array('query' => array('session_id' => $sid))); } return t('Unknown'); diff --git a/modules/past_db/src/PastEventViewsData.php b/modules/past_db/src/PastEventViewsData.php index f592392..5d8d260 100644 --- a/modules/past_db/src/PastEventViewsData.php +++ b/modules/past_db/src/PastEventViewsData.php @@ -24,10 +24,10 @@ class PastEventViewsData extends EntityViewsData { 'help' => t('Display or filter by a specific argument data'), 'real field' => 'value', 'field' => array( - 'handler' => 'past_db_handler_field_event_argument_data', + 'id' => 'past_db_event_argument_data', ), 'filter' => array( - 'handler' => 'past_db_handler_filter_event_argument_value', + 'id' => 'past_db_event_argument_value', ), ); $data['past_event']['trace_user'] = array( @@ -35,7 +35,7 @@ class PastEventViewsData extends EntityViewsData { 'help' => t('Add links to sort the view by user / session id.'), 'real field' => 'uid', 'field' => array( - 'handler' => 'past_db_handler_field_trace_user', + 'id' => 'past_db_trace_user', ), ); diff --git a/modules/past_db/views/handlers/past_db_handler_field_event_argument_data.inc b/modules/past_db/src/Plugin/views/field/EventArgumentData.php similarity index 60% rename from modules/past_db/views/handlers/past_db_handler_field_event_argument_data.inc rename to modules/past_db/src/Plugin/views/field/EventArgumentData.php index b77e2d4..c5f554d 100644 --- a/modules/past_db/views/handlers/past_db_handler_field_event_argument_data.inc +++ b/modules/past_db/src/Plugin/views/field/EventArgumentData.php @@ -1,21 +1,31 @@ NULL); $definition['data_key'] = array('default' => NULL); return $definition; @@ -24,12 +34,12 @@ class past_db_handler_field_event_argument_data extends views_handler_field_enti /** * {@inheritdoc} */ - function options_form(&$form, &$form_state) { - parent::options_form($form, $form_state); + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + parent::buildOptionsForm($form, $form_state); $form['argument_name'] = array( '#type' => 'textfield', - '#title' => t('Argument nane'), + '#title' => t('Argument name'), '#default_value' => $this->options['argument_name'], '#required' => TRUE, ); @@ -45,10 +55,11 @@ class past_db_handler_field_event_argument_data extends views_handler_field_enti /** * {@inheritdoc} */ - function render($values) { - $event = $this->get_value(NULL); + public function render(ResultRow $values) { + /** @var PastEvent $event */ + $event = $this->getValue($values); if (empty($this->options['argument_name'])) { - return; + return ""; } if (!empty($event)) { $argument = $event->getArgument($this->options['argument_name']); @@ -60,7 +71,7 @@ class past_db_handler_field_event_argument_data extends views_handler_field_enti return is_array($data) ? print_r($data, TRUE) : $data; } } - return; + return ""; } } diff --git a/modules/past_db/src/Plugin/views/field/TraceUser.php b/modules/past_db/src/Plugin/views/field/TraceUser.php new file mode 100644 index 0000000..5fac021 --- /dev/null +++ b/modules/past_db/src/Plugin/views/field/TraceUser.php @@ -0,0 +1,53 @@ +getValue($value, 'uid'); + if (is_numeric($uid) && $uid > 0) { + $uids[] = $uid; + } + } + if ($uids) { + User::loadMultiple($uids); + } + } + + /** + * {@inheritdoc} + */ + public function render(ResultRow $values) { + /** @var PastEvent $event */ + $event = $this->getValue($values); + $url = Url::fromRoute(''); + return $event->getActorDropbutton(20, $url->toString()); + } + +} diff --git a/modules/past_db/src/Plugin/views/filter/EventArgumentValue.php b/modules/past_db/src/Plugin/views/filter/EventArgumentValue.php new file mode 100644 index 0000000..4cc9bac --- /dev/null +++ b/modules/past_db/src/Plugin/views/filter/EventArgumentValue.php @@ -0,0 +1,93 @@ + NULL); + $definition['data_key'] = array('default' => NULL); + return $definition; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + parent::buildOptionsForm($form, $form_state); + + $form['argument_name'] = array( + '#type' => 'textfield', + '#title' => t('Argument name'), + '#default_value' => $this->options['argument_name'], + ); + + $form['data_key'] = array( + '#type' => 'textfield', + '#title' => t('Data key'), + '#default_value' => $this->options['data_key'], + ); + return $form; + } + + /** + * {@inheritdoc} + */ + public function query() { + $this->ensureMyTable(); + + // Add the join for the argument table using a new relationship. + $configuration = array( + 'field' => 'event_id', + 'left_field' => 'event_id', + 'table' => 'past_event_argument', + 'left_table' => 'past_event', + 'type' => 'INNER', + ); + $join = new JoinPluginBase($configuration, $this->getPluginId(), $this->getPluginDefinition()); + $relationship_alias = $this->query->addRelationship($this->options['id'], $join, 'past_event'); + + // Limit to a specific argument, if configured. + if ($this->options['argument_name']) { + $this->query->addWhere($this->options['group'], $relationship_alias . '.name', $this->options['argument_name'], '='); + } + + // Join the data table using the specified relationship. + $configuration = array( + 'field' => 'argument_id', + 'left_field' => 'argument_id', + 'table' => 'past_event_data', + 'left_table' => 'past_event_argument', + 'type' => 'INNER', + ); + $join = new JoinPluginBase($configuration, $this->getPluginId(), $this->getPluginDefinition()); + $this->table_alias = $this->query->addTable('past_event', $relationship_alias, $join); + + // Limit to a specific data key, if configured. + if ($this->options['data_key']) { + $this->query->addWhere($this->options['group'], $relationship_alias . '.name', $this->options['data_key'], '='); + } + parent::query(); + } + +} diff --git a/modules/past_db/views/handlers/past_db_handler_field_trace_user.inc b/modules/past_db/views/handlers/past_db_handler_field_trace_user.inc deleted file mode 100644 index f79c54d..0000000 --- a/modules/past_db/views/handlers/past_db_handler_field_trace_user.inc +++ /dev/null @@ -1,40 +0,0 @@ -get_value($value, 'uid'); - if (is_numeric($uid) && $uid > 0) { - $uids[] = $uid; - } - } - if ($uids) { - user_load_multiple($uids); - } - } - - /** - * {@inheritdoc} - */ - function render($values) { - $event = $this->get_value(NULL); - return $event->getActorDropbutton(20, request_path()); - } -} diff --git a/modules/past_db/views/handlers/past_db_handler_filter_event_argument_value.inc b/modules/past_db/views/handlers/past_db_handler_filter_event_argument_value.inc deleted file mode 100644 index 82711f7..0000000 --- a/modules/past_db/views/handlers/past_db_handler_filter_event_argument_value.inc +++ /dev/null @@ -1,87 +0,0 @@ - NULL); - $definition['data_key'] = array('default' => NULL); - return $definition; - } - - /** - * {@inheritdoc} - */ - function options_form(&$form, &$form_state) { - parent::options_form($form, $form_state); - - $form['argument_name'] = array( - '#type' => 'textfield', - '#title' => t('Argument nane'), - '#default_value' => $this->options['argument_name'], - ); - - $form['data_key'] = array( - '#type' => 'textfield', - '#title' => t('Data key'), - '#default_value' => $this->options['data_key'], - ); - return $form; - } - - /** - * {@inheritdoc} - */ - function query() { - $this->ensure_my_table(); - - // Add the join for the argument table using a new relationship. - $join = new views_join(); - $join->definition = array( - 'field' => 'event_id', - 'left_field' => 'event_id', - 'table' => 'past_event_argument', - 'left_table' => 'past_event', - 'type' => 'INNER', - ); - $join->construct(); - $relationship_alias = $this->query->add_relationship($this->options['id'], $join, 'past_event'); - - // Limit to a specific argument, if configured. - if ($this->options['argument_name']) { - $this->query->add_where($this->options['group'], $relationship_alias . '.name', $this->options['argument_name'], '='); - } - - // Join the data table using the specified relationship. - $join = new views_join(); - $join->definition = array( - 'field' => 'argument_id', - 'left_field' => 'argument_id', - 'table' => 'past_event_data', - 'left_table' => 'past_event_argument', - 'type' => 'INNER', - ); - $join->construct(); - $this->table_alias = $this->query->add_table('past_event', $relationship_alias, $join); - - // Limit to a specific data key, if configured. - if ($this->options['data_key']) { - $this->query->add_where($this->options['group'], $relationship_alias . '.name', $this->options['data_key'], '='); - } - parent::query(); - } - -} diff --git a/past.module b/past.module index 8518480..7cad77d 100644 --- a/past.module +++ b/past.module @@ -5,6 +5,7 @@ * Module file for the past project. */ +use Drupal\Component\Utility\Xss; use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Site\Settings; use Drupal\Core\Url; @@ -181,13 +182,14 @@ function past_form_system_logging_settings_alter(&$form, &$form_state) { * Keys are Watchdog severity levels, values are unset. */ function _past_watchdog_severity_defaults() { - return drupal_map_assoc(array( + $defaults = array( 'WATCHDOG_SEVERITY_' . RfcLogLevel::EMERGENCY, 'WATCHDOG_SEVERITY_' . RfcLogLevel::ALERT, 'WATCHDOG_SEVERITY_' . RfcLogLevel::CRITICAL, 'WATCHDOG_SEVERITY_' . RfcLogLevel::ERROR, 'WATCHDOG_SEVERITY_' . RfcLogLevel::NOTICE, - )); + ); + return array_combine($defaults, $defaults); } /** @@ -205,7 +207,7 @@ function _past_watchdog_severity_defaults() { function _past_get_formatted_backtrace($severity_level, $slice = 5) { $config = \Drupal::config('past.settings'); $log_backtrace = $config->get('backtrace_include'); - $severity_keyvalue = 'WATCHDOG_SEVERITY_' . $severity_level; + $severity_keyvalue = 'WATCHDOG_SEVERITY_' . strtoupper(RfcLogLevel::getLevels()[$severity_level]); if (!is_null($severity_level) && empty($log_backtrace[$severity_keyvalue])) { return NULL; } @@ -236,7 +238,7 @@ function _past_get_formatted_backtrace($severity_level, $slice = 5) { else { foreach ($trace['args'] as $arg) { if (is_scalar($arg)) { - $call['args'][] = is_string($arg) ? '\'' . filter_xss($arg) . '\'' : $arg; + $call['args'][] = is_string($arg) ? '\'' . Xss::filter($arg) . '\'' : $arg; } else { $call['args'][] = ucfirst(gettype($arg)); diff --git a/src/Form/PastSettingsForm.php b/src/Form/PastSettingsForm.php index e0f7c07..2c3e4a4 100644 --- a/src/Form/PastSettingsForm.php +++ b/src/Form/PastSettingsForm.php @@ -80,9 +80,20 @@ class PastSettingsForm extends ConfigFormBase { '#description' => t('When enabled, Past will take watchdog log entries. To avoid redundancy, you can turn off the database logging module.'), ); + $options = $config->get('backtrace_include'); + $included_severity_levels = array(); + foreach (RfcLogLevel::getLevels() as $level => $value) { + $severity_keyvalue = 'WATCHDOG_SEVERITY_' . strtoupper($value); + if ($options[$severity_keyvalue]) { + $included_severity_levels[] = "" . $level; + } + else { + $included_severity_levels[] = 0; + } + } $form['watchdog']['backtrace_include'] = array( '#type' => 'checkboxes', - '#default_value' => $config->get('backtrace_include'), + '#default_value' => $included_severity_levels, '#options' => RfcLogLevel::getLevels(), '#title' => t('Watchdog severity levels from writing backtraces'), '#description' => t('A backtrace is logged for all severities that are checked.'), @@ -111,9 +122,14 @@ class PastSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $included_severity_levels = array(); - foreach ($form_state->getValue('backtrace_include') as $level => $enabled) { - if ($enabled) { - $included_severity_levels[] = $level; + $options = $form_state->getValue('backtrace_include'); + foreach (RfcLogLevel::getLevels() as $level => $value) { + $severity_keyvalue = 'WATCHDOG_SEVERITY_' . strtoupper($value); + if ($options[$level] !== 0) { + $included_severity_levels[$severity_keyvalue] = TRUE; + } + else { + $included_severity_levels[$severity_keyvalue] = FALSE; } } $this->config('past.settings') diff --git a/src/Tests/PastKernelTest.php b/src/Tests/PastKernelTest.php index b480c46..e5a86e8 100644 --- a/src/Tests/PastKernelTest.php +++ b/src/Tests/PastKernelTest.php @@ -32,7 +32,7 @@ class PastKernelTest extends KernelTestBase { 'system', 'views', 'user', - 'options' + 'options', ); /**