- 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.
- Merge request !1033419718-drush-command-to: Created drush command to remove circular redirects. → (Open) created by uttam
- Status changed to Needs review
about 2 months ago 1:52pm 18 July 2024 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 usingPsr\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 9:09am 29 August 2024 - 🇮🇳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...