Skip to content
Snippets Groups Projects
Commit da8abde3 authored by Joshua Sedler's avatar Joshua Sedler :cartwheel_tone2: Committed by Sascha Grossenbacher
Browse files

Issue #2922444 by Anybody, pifagor, Grevil, rajeshwari10: Remove all 404 from list

parent e29b7f7a
No related branches found
No related tags found
Loading
......@@ -43,6 +43,12 @@ function redirect_404_form_redirect_settings_form_alter(&$form, FormStateInterfa
'#description' => t('The maximum number of 404 error logs to keep in the database log. Requires a <a href=":cron">cron maintenance task</a>.', [':cron' => Url::fromRoute('system.status')->toString()])
];
$form['reset_404'] = [
'#type' => 'submit',
'#value' => t('Clear all 404 log entries'),
'#submit' => ['redirect_404_reset_submit'],
];
$ignored_pages = $config->get('pages');
// Add a new path to be ignored, if there is an ignore argument in the query.
if ($path_to_ignore = \Drupal::request()->query->get('ignore')) {
......@@ -102,3 +108,10 @@ function redirect_404_redirect_presave(Redirect $redirect) {
// Mark a potentially existing log entry for this path as resolved.
\Drupal::service('redirect.not_found_storage')->resolveLogRequest($path, $langcode);
}
/**
* Submit Handler for Reseting all the 404 logs from Database.
*/
function redirect_404_reset_submit() {
\Drupal::database()->truncate('redirect_404')->execute();
}
......@@ -193,4 +193,43 @@ class Fix404RedirectUITest extends Redirect404TestBase {
$this->assertSession()->fieldValueEquals('ignore_pages', "/node/*\r\n/term/*\n/llama_page");
}
/**
* Tests the test_404_reset_submit button to remove all 404 entries.
*/
public function test404ResetSubmit() {
// Go to non-existing paths:
$this->drupalGet('non-existing0');
$this->drupalGet('non-existing0?test=1');
$this->drupalGet('non-existing0?test=2');
$this->drupalGet('non-existing1');
$this->drupalGet('non-existing2');
// Go to the "Fix 404" page and check wheter these 404 entries exist:
$this->drupalGet('admin/config/search/redirect/404');
$this->assertText('non-existing0?test=1');
$this->assertText('non-existing0?test=2');
$this->assertText('non-existing0');
$this->assertText('non-existing1');
$this->assertText('non-existing2');
// Go to the "Settings" page, press the "Clear all 404 log entries" button:
$this->drupalGet('admin/config/search/redirect/settings');
$this->assertElementPresent('#edit-reset-404');
$this->getSession()->getPage()->pressButton('Clear all 404 log entries');
// Go to the "Fix 404" page and check wheter these 404 entries DO NOT exist:
$this->drupalGet('admin/config/search/redirect/404');
$this->assertNoText('non-existing0?test=1');
$this->assertNoText('non-existing0?test=2');
$this->assertNoText('non-existing0');
$this->assertNoText('non-existing1');
$this->assertNoText('non-existing2');
// Ensure new 404 entries are created after clearing:
$this->drupalGet('non-existing0');
$this->drupalGet('non-existing0?test=1');
// Go to the "Fix 404" page and check wheter these 404 entries exist:
$this->drupalGet('admin/config/search/redirect/404');
$this->assertText('non-existing0');
$this->assertText('non-existing0?test=1');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment