I'm using this is module and, after a migration from D7 to D8, I wrote a custom module to create some redirect with "patterns".
The site is live and now I want to enable my module and "reset" 404 unfixed (what I see on admin/config/search/redirect/404), so I can monitor only new 404 not "matched" with my module.

How can I do this?
Can I simply truncate all records from table "redirect_404"?

Thanks!

Issue fork redirect-2922444

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

arrubiu created an issue. See original summary.

arrubiu’s picture

Issue summary: View changes
abaier’s picture

I would also be interested how I could clear the list to start logging from scratch. A while after the launch we added some redirect patterns, so many of the logged entries should be obsolete now.

Thanks for any help!

arrubiu’s picture

I made this with a "simple" query, removing records from the table, but a "button" could be useful.

berdir’s picture

Category: Support request » Feature request

Yes, patches that add a button somewhere that executes a truncate query would be great. Maybe on the settings form as we already have a form there.

rajeshwari10’s picture

Status: Active » Needs review
StatusFileSize
new1.51 KB

Hi,

I have added a Reset button in the existing Settings Form. On clicking the same will truncate all the 404 data from the database.

Adding the patch. Please Review.

Thanks

rajeshwari10’s picture

StatusFileSize
new1.32 KB

Sorry, Removed the unwanted Use statement.

Thanks

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/modules/redirect_404/redirect_404.module
    @@ -35,6 +35,12 @@ function redirect_404_form_redirect_settings_form_alter(&$form, FormStateInterfa
     
    +  $form['reset_404'] = [
    +    '#type' => 'submit',
    +    '#value' => 'Reset 404',
    +    '#submit' => ['reset404'],
    +  ];
    

    The value must use to t() to be translatable. It should also explain more clearly what it does, e.g. "Clear all 404 log entries".

  2. +++ b/modules/redirect_404/redirect_404.module
    @@ -94,3 +100,13 @@ function redirect_404_redirect_presave(Redirect $redirect) {
    +/**
    + * Submit Handler for Reseting all the 404 logs from Database.
    + *
    + * @return \Drupal\Core\Database\StatementInterface|int|null
    + */
    +function reset404() {
    +  $query = \Drupal::database()->truncate('redirect_404')->execute();
    +  return $query;
    +}
    

    Submit callbacks don't return anything, there is no need for that.

    Also, all functions must be prefixed with the module name and as a submit function, should have a submit suffix, e.g. redirect_404_reset_submit()

pifagor’s picture

Status: Needs work » Needs review
StatusFileSize
new580 bytes
pifagor’s picture

StatusFileSize
new1.35 KB

Sorry, work patch

pifagor’s picture

StatusFileSize
new1.29 KB
mpp’s picture

@berdir, I noticed we still do a lot of hook_form_FORM_ID_alter(), it would be nice if there was a more object oriented way to alter form objects. Would it be an option to extend the RedirectSettingsForm and alter the route to the extended one? Or is this a bad idea as something else may have changed it before?

@pifagor #11, I'd use just one capital here and resetting has two t's:

 + * Submit Handler for Reseting all the 404 logs from Database.
 + * Submit handler for resetting all the 404 logs from the database.
berdir’s picture

form alter is fine here. Altering the route is way more complex and only one module can do that. This is a common pattern to add additional settings to forms provided by other modules.

berdir’s picture

Version: 8.x-1.0-beta1 » 8.x-1.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

Lets add some test coverage for this, shouldn't be complicated, in the existing tests after testing the UI, press the button and then check that the empty message is displayed.

Anybody made their first commit to this issue’s fork.

Grevil made their first commit to this issue’s fork.

grevil’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

I added appropriate Tests for the "Clear all 404 log entries" button as suggested by @Berdir in #14 See MR above

Until this is commited you can use:
https://git.drupalcode.org/project/redirect/-/merge_requests/4.patch
as patch.

anybody’s picture

Updated the MR to also contain the patch by @pifagor from #11. RTBC +1 from my perspective, well done @pifagor & @Grevil! :)

anybody’s picture

Let's bring this to a successful end :) Please review finally, I guess it's ready for takeoff.

petr illek’s picture

Hi,
I tested the patch and it is working as expected.
I was looking for such thing for a long time.
Can we make a new release?

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @Petr Illek so let's finally RTBC this issue.

  • Berdir committed da8abde on 8.x-1.x authored by Grevil
    Issue #2922444 by Anybody, pifagor, Grevil, rajeshwari10: Remove all 404...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.