From 104c0c2931926150acacc805df9523e20a95daeb Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Wed, 17 Jan 2024 08:54:54 -0800 Subject: [PATCH] Remove some row properties that cause unwanted content updates --- stanford_migrate.module | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/stanford_migrate.module b/stanford_migrate.module index 4fe9beb..2e44f41 100755 --- a/stanford_migrate.module +++ b/stanford_migrate.module @@ -8,9 +8,11 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Entity\Entity\EntityViewDisplay; +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\migrate\Plugin\MigrateSourceInterface; use Drupal\migrate\Plugin\MigrationInterface; +use Drupal\migrate\Row; use Drupal\migrate_plus\Entity\Migration; use Drupal\node\NodeInterface; use Drupal\ultimate_cron\CronJobInterface; @@ -31,6 +33,23 @@ function stanford_migrate_help($route_name, RouteMatchInterface $route_match) { } } +/** + * Implements hook_migrate_prepare_row(). + */ +function stanford_migrate_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { + // Oauth2 authentication adds a token query parameter into the data urls that changes frequently. Since it + // changes, the hash of the row changes without any data actually changing. Fix the row data so that it doesn't + // contain those tokens. + $authentication = $row->getSourceProperty('authentication/plugin'); + $current_url = $row->getSourceProperty('current_feed_url'); + if ($current_url && $authentication == 'oauth2') { + $row->setSourceProperty('current_feed_url', preg_replace('/access_token=.*?&/', '', $current_url)); + } + // In case the list of urls changes dynamically, lets just remove it from the source data to avoid unnecessary hash + // changes. + $row->setSourceProperty('urls', []); +} + /** * Get the migration that imported the given node. *