- 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
4 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
3 months 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...
- Status changed to Needs review
2 months ago 7:15am 13 September 2024 @sourav_paul Hello I have resolved the fatal error and tested the same in d10 and d11, the circular redirects are successfully purging. Please review this once.
Moving this to Needs Review- 🇮🇳India sourav_paul Kolkata
Thanks @uttam for your contribution. I've retested the MR, which was applied cleanly.
Drush command working as expected.Attaching ss:
Hence Moving it to RTBC.