Drush command to remove circular redirects

Created on 7 February 2024, 7 months ago
Updated 29 August 2024, 10 days ago

Problem/Motivation

It'd be useful to have a Drush command to purge circular redirects.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

🇺🇸United States DamienMcKenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @DamienMcKenna
  • 🇺🇸United States DamienMcKenna NH, USA

    This logic works for me, it could be turned into a command.

      /**
       * Purge circular redirects.
       *
       * @command mymodule:purge-circular-redirects
       */
      public function fixCircularRedirects() {
        $db = \Drupal::database();
        $records = $db->query("SELECT redirect.rid
          FROM {redirect}
          INNER JOIN {path_alias}
          	ON CONCAT('/', redirect.redirect_source__path) = path_alias.alias")
          ->fetchCol();
        if (!empty($records)) {
          $this->logger->notice($this->t('@count redirect records to purge: @list', [
            '@count' => count($records),
            '@list' => implode(', ', $records),
          ]));
          $db->delete('redirect')
            ->condition('rid', $records, 'IN')
            ->execute();
          $this->logger->notice($this->t('@count redirect records purged.', [
            '@count' => count($records),
          ]));
        }
        else {
          $this->logger->notice($this->t('No circiular redirects found.'));
        }
      }
    
  • First commit to issue fork.
  • Pipeline finished with Success
    about 2 months ago
    Total: 180s
    #227809
  • Pipeline finished with Success
    about 2 months ago
    Total: 199s
    #227845
  • Status changed to Needs review about 2 months ago
  • Hello everyone, I have created this Drupal Drush command which facilitates the management of circular redirects using Drush as mentioned in the issue. Firstly, It retrieves all redirect entities from the database using EntityTypeManagerInterface, constructs a map linking source URLs to their corresponding destinations, identifies circular redirect relationships where a redirect points back to its own source. I have also logged each detected circular redirect using Psr\Log\LoggerInterface and provides a user prompt to confirm the delete operation. Upon confirmation, it deletes all identified circular redirect records.

    Drush command for the purging circular redirects: drush redirect:purge-circular-redirects

    Please review this.

  • Assigned to Sourav_Paul
  • Issue was unassigned.
  • Status changed to Needs work 10 days ago
  • 🇮🇳India Sourav_Paul Kolkata

    MR was applied successfully but got a fatal error on running the command drush redirect:purge-circular-redirects
    Using redirect 8.x-1.10 & D10.3
    Sharing ss:

    Please fix the logger issue...

Production build 0.71.5 2024