Loading modules/redirect_404/config/install/views.view.redirect_404.yml +59 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ display: columns: path: path count: count daily_count: daily_count timestamp: timestamp info: path: Loading @@ -92,6 +93,13 @@ display: separator: '' empty_column: false responsive: '' daily_count: sortable: true default_sort_order: desc align: '' separator: '' empty_column: false responsive: '' timestamp: sortable: true default_sort_order: desc Loading Loading @@ -206,6 +214,57 @@ display: format: unserialized key: '' plugin_id: serialized daily_count: id: daily_count table: redirect_404 field: daily_count relationship: none group_type: group admin_label: '' label: 'Daily count' exclude: false alter: alter_text: false text: '' make_link: false path: '' absolute: false external: false replace_spaces: false path_case: none trim_whitespace: false alt: '' rel: '' link_class: '' prefix: '' suffix: '' target: '' nl2br: false max_length: 0 word_boundary: true ellipsis: true more_link: false more_link_text: '' more_link_path: '' strip_tags: false trim: false preserve_tags: '' html: false element_type: '' element_class: '' element_label_type: '' element_label_class: '' element_label_colon: true element_wrapper_type: '' element_wrapper_class: '' element_default_classes: true empty: '' hide_empty: false empty_zero: false hide_alter_empty: true format: unserialized key: '' plugin_id: serialized timestamp: id: timestamp table: redirect_404 Loading modules/redirect_404/redirect_404.install +102 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,13 @@ function redirect_404_schema() { 'not null' => TRUE, 'default' => 0, ], 'daily_count' => [ 'description' => 'The number of requests with that path and language in a day.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ], 'timestamp' => [ 'description' => 'The timestamp of the last request with that path and language.', 'type' => 'int', Loading @@ -60,3 +67,98 @@ function redirect_404_schema() { function redirect_404_update_8101() { \Drupal::database()->schema()->dropField('redirect_404', 'relevancy'); } /** * Add daily count field to redirect_404 table and view. */ function redirect_404_update_8102() { \Drupal::database()->schema()->addField('redirect_404', 'daily_count', [ 'description' => 'The number of requests with that path and language in a day.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ]); $view_config = \Drupal::configFactory()->getEditable('views.view.redirect_404'); if (!$view_config->isNew()) { $columns_key = 'display.default.display_options.style.options.columns'; $columns = $view_config->get($columns_key); $columns['daily_count'] = 'daily_count'; $view_config->set($columns_key, $columns); $info_key = 'display.default.display_options.style.options.info'; $info = $view_config->get($info_key); $info['daily_count'] = [ 'sortable' => TRUE, 'default_sort_order' => 'desc', 'align' => '', 'separator' => '', 'empty_column' => FALSE, 'responsive' => '', ]; $view_config->set($info_key, $info); $fields = $view_config->get('display.default.display_options.fields'); $daily_count = [ 'id' => 'daily_count', 'table' => 'redirect_404', 'field' => 'daily_count', 'relationship' => 'none', 'group_type' => 'group', 'admin_label' => '', 'label' => 'Daily count', 'exclude' => FALSE, 'alter' => [ 'alter_text' => FALSE, 'text' => '', 'make_link' => FALSE, 'path' => '', 'absolute' => FALSE, 'external' => FALSE, 'replace_spaces' => FALSE, 'path_case' => 'none', 'trim_whitespace' => FALSE, 'alt' => '', 'rel' => '', 'link_class' => '', 'prefix' => '', 'suffix' => '', 'target' => '', 'nl2br' => FALSE, 'max_length' => 0, 'word_boundary' => TRUE, 'ellipsis' => TRUE, 'more_link' => FALSE, 'more_link_text' => '', 'more_link_path' => '', 'strip_tags' => FALSE, 'trim' => FALSE, 'preserve_tags' => '', 'html' => FALSE, ], 'element_type' => '', 'element_class' => '', 'element_label_type' => '', 'element_label_class' => '', 'element_label_colon' => TRUE, 'element_wrapper_type' => '', 'element_wrapper_class' => '', 'element_default_classes' => TRUE, 'empty' => '', 'hide_empty' => FALSE, 'empty_zero' => FALSE, 'hide_alter_empty' => TRUE, 'format' => 'unserialized', 'key' => '', 'plugin_id' => 'serialized', ]; $count_index = array_search('count', array_keys($fields)); $fields = array_slice($fields, 0, $count_index + 1) + ['daily_count' => $daily_count] + array_slice($fields, $count_index); $view_config->set('display.default.display_options.fields', $fields)->save(); } } modules/redirect_404/redirect_404.module +8 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,14 @@ function redirect_404_cron() { /** @var \Drupal\redirect_404\SqlRedirectNotFoundStorage $redirect_storage */ $redirect_storage = \Drupal::service('redirect.not_found_storage'); $redirect_storage->purgeOldRequests(); $last_daily_reset = \Drupal::state()->get('redirect_404.last_daily_reset', 0); if (date('d', $last_daily_reset) != date('d')) { $redirect_storage->resetDailyCount(); \Drupal::state()->set('redirect_404.last_daily_reset', \Drupal::time()->getRequestTime()); } } /** Loading modules/redirect_404/redirect_404.views.inc +12 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,18 @@ function redirect_404_views_data() { ], ]; $data['redirect_404']['daily_count'] = [ 'title' => t('Daily count'), 'help' => t('The number of requests with that path and language in a day.'), 'field' => [ 'id' => 'numeric', 'click sortable' => TRUE, ], 'filter' => [ 'id' => 'numeric', ], ]; $data['redirect_404']['timestamp'] = [ 'title' => t('Timestamp'), 'help' => t('The timestamp of the last request with that path and language.'), Loading modules/redirect_404/src/RedirectNotFoundStorageInterface.php +5 −0 Original line number Diff line number Diff line Loading @@ -50,4 +50,9 @@ interface RedirectNotFoundStorageInterface { */ public function purgeOldRequests(); /** * Resets the daily counts of 404 request logs. */ public function resetDailyCount(); } Loading
modules/redirect_404/config/install/views.view.redirect_404.yml +59 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ display: columns: path: path count: count daily_count: daily_count timestamp: timestamp info: path: Loading @@ -92,6 +93,13 @@ display: separator: '' empty_column: false responsive: '' daily_count: sortable: true default_sort_order: desc align: '' separator: '' empty_column: false responsive: '' timestamp: sortable: true default_sort_order: desc Loading Loading @@ -206,6 +214,57 @@ display: format: unserialized key: '' plugin_id: serialized daily_count: id: daily_count table: redirect_404 field: daily_count relationship: none group_type: group admin_label: '' label: 'Daily count' exclude: false alter: alter_text: false text: '' make_link: false path: '' absolute: false external: false replace_spaces: false path_case: none trim_whitespace: false alt: '' rel: '' link_class: '' prefix: '' suffix: '' target: '' nl2br: false max_length: 0 word_boundary: true ellipsis: true more_link: false more_link_text: '' more_link_path: '' strip_tags: false trim: false preserve_tags: '' html: false element_type: '' element_class: '' element_label_type: '' element_label_class: '' element_label_colon: true element_wrapper_type: '' element_wrapper_class: '' element_default_classes: true empty: '' hide_empty: false empty_zero: false hide_alter_empty: true format: unserialized key: '' plugin_id: serialized timestamp: id: timestamp table: redirect_404 Loading
modules/redirect_404/redirect_404.install +102 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,13 @@ function redirect_404_schema() { 'not null' => TRUE, 'default' => 0, ], 'daily_count' => [ 'description' => 'The number of requests with that path and language in a day.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ], 'timestamp' => [ 'description' => 'The timestamp of the last request with that path and language.', 'type' => 'int', Loading @@ -60,3 +67,98 @@ function redirect_404_schema() { function redirect_404_update_8101() { \Drupal::database()->schema()->dropField('redirect_404', 'relevancy'); } /** * Add daily count field to redirect_404 table and view. */ function redirect_404_update_8102() { \Drupal::database()->schema()->addField('redirect_404', 'daily_count', [ 'description' => 'The number of requests with that path and language in a day.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ]); $view_config = \Drupal::configFactory()->getEditable('views.view.redirect_404'); if (!$view_config->isNew()) { $columns_key = 'display.default.display_options.style.options.columns'; $columns = $view_config->get($columns_key); $columns['daily_count'] = 'daily_count'; $view_config->set($columns_key, $columns); $info_key = 'display.default.display_options.style.options.info'; $info = $view_config->get($info_key); $info['daily_count'] = [ 'sortable' => TRUE, 'default_sort_order' => 'desc', 'align' => '', 'separator' => '', 'empty_column' => FALSE, 'responsive' => '', ]; $view_config->set($info_key, $info); $fields = $view_config->get('display.default.display_options.fields'); $daily_count = [ 'id' => 'daily_count', 'table' => 'redirect_404', 'field' => 'daily_count', 'relationship' => 'none', 'group_type' => 'group', 'admin_label' => '', 'label' => 'Daily count', 'exclude' => FALSE, 'alter' => [ 'alter_text' => FALSE, 'text' => '', 'make_link' => FALSE, 'path' => '', 'absolute' => FALSE, 'external' => FALSE, 'replace_spaces' => FALSE, 'path_case' => 'none', 'trim_whitespace' => FALSE, 'alt' => '', 'rel' => '', 'link_class' => '', 'prefix' => '', 'suffix' => '', 'target' => '', 'nl2br' => FALSE, 'max_length' => 0, 'word_boundary' => TRUE, 'ellipsis' => TRUE, 'more_link' => FALSE, 'more_link_text' => '', 'more_link_path' => '', 'strip_tags' => FALSE, 'trim' => FALSE, 'preserve_tags' => '', 'html' => FALSE, ], 'element_type' => '', 'element_class' => '', 'element_label_type' => '', 'element_label_class' => '', 'element_label_colon' => TRUE, 'element_wrapper_type' => '', 'element_wrapper_class' => '', 'element_default_classes' => TRUE, 'empty' => '', 'hide_empty' => FALSE, 'empty_zero' => FALSE, 'hide_alter_empty' => TRUE, 'format' => 'unserialized', 'key' => '', 'plugin_id' => 'serialized', ]; $count_index = array_search('count', array_keys($fields)); $fields = array_slice($fields, 0, $count_index + 1) + ['daily_count' => $daily_count] + array_slice($fields, $count_index); $view_config->set('display.default.display_options.fields', $fields)->save(); } }
modules/redirect_404/redirect_404.module +8 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,14 @@ function redirect_404_cron() { /** @var \Drupal\redirect_404\SqlRedirectNotFoundStorage $redirect_storage */ $redirect_storage = \Drupal::service('redirect.not_found_storage'); $redirect_storage->purgeOldRequests(); $last_daily_reset = \Drupal::state()->get('redirect_404.last_daily_reset', 0); if (date('d', $last_daily_reset) != date('d')) { $redirect_storage->resetDailyCount(); \Drupal::state()->set('redirect_404.last_daily_reset', \Drupal::time()->getRequestTime()); } } /** Loading
modules/redirect_404/redirect_404.views.inc +12 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,18 @@ function redirect_404_views_data() { ], ]; $data['redirect_404']['daily_count'] = [ 'title' => t('Daily count'), 'help' => t('The number of requests with that path and language in a day.'), 'field' => [ 'id' => 'numeric', 'click sortable' => TRUE, ], 'filter' => [ 'id' => 'numeric', ], ]; $data['redirect_404']['timestamp'] = [ 'title' => t('Timestamp'), 'help' => t('The timestamp of the last request with that path and language.'), Loading
modules/redirect_404/src/RedirectNotFoundStorageInterface.php +5 −0 Original line number Diff line number Diff line Loading @@ -50,4 +50,9 @@ interface RedirectNotFoundStorageInterface { */ public function purgeOldRequests(); /** * Resets the daily counts of 404 request logs. */ public function resetDailyCount(); }