From c9853c8108ac86a469e4ea8f20edd19e852af49e Mon Sep 17 00:00:00 2001 From: HongPong <hongpong@hongpong.com> Date: Mon, 31 Mar 2025 03:42:20 -0400 Subject: [PATCH] Issue #3491146 by ryumaou, HongPong: add migrate process plugin wordpress_migrate_log_term to put new terms in Drupal logger --- migrations/wordpress_categories.yml | 5 ++- migrations/wordpress_tags.yml | 5 ++- src/Plugin/migrate/process/LogTerm.php | 50 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/Plugin/migrate/process/LogTerm.php diff --git a/migrations/wordpress_categories.yml b/migrations/wordpress_categories.yml index 83136dd..9338d59 100644 --- a/migrations/wordpress_categories.yml +++ b/migrations/wordpress_categories.yml @@ -30,7 +30,10 @@ source: type: string process: # vid is populated dynamically. - name: cat_name + name: + #- plugin: wordpress_migrate_log_term # Uncomment to log terms. + - plugin: get + source: cat_name parent: plugin: migration_lookup migration: wordpress_categories diff --git a/migrations/wordpress_tags.yml b/migrations/wordpress_tags.yml index 2fa5031..65db7db 100644 --- a/migrations/wordpress_tags.yml +++ b/migrations/wordpress_tags.yml @@ -26,7 +26,10 @@ source: type: string process: # vid is populated dynamically. - name: tag_name + name: + #- plugin: wordpress_migrate_log_term # Uncomment to log terms. + - plugin: get + source: tag_name destination: plugin: entity:taxonomy_term migration_dependencies: {} diff --git a/src/Plugin/migrate/process/LogTerm.php b/src/Plugin/migrate/process/LogTerm.php new file mode 100644 index 0000000..ba5a70c --- /dev/null +++ b/src/Plugin/migrate/process/LogTerm.php @@ -0,0 +1,50 @@ +<?php +/** + * Provides migrate process plugin "wordpress_migrate_log_term". Will log term + * ID, Name, Slug, Destination. + */ +namespace Drupal\wordpress_migrate\Plugin\migrate\process; + +use Drupal\migrate\ProcessPluginBase; +use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\Row; +//use Drupal\migrate\MigrateSkipProcessException; + +/** +* @MigrateProcessPlugin( +* id = "wordpress_migrate_log_term" +* ) +*/ +class LogTerm extends ProcessPluginBase { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + $source = $row->getSource(); + + // Get original values for debugging + $term_id = ''; + $name = ''; + $slug = ''; + + if (isset($source['tag_slug'])) { + // This is a tag + $term_id = $source['term_id'] ?? 'unknown'; + $name = $source['tag_name'] ?? 'unknown'; + $slug = $source['tag_slug'] ?? 'unknown'; + } + elseif (isset($source['category_nicename'])) { + // This is a category + $term_id = $source['term_id'] ?? 'unknown'; + $name = $source['cat_name'] ?? 'unknown'; + $slug = $source['category_nicename'] ?? 'unknown'; + } + + \Drupal::logger('wordpress_migrate')->debug('Processing term: Term ID=@id, Name=@name, Slug=@slug, Destination=@dest, Value=@value', [ + '@id' => $term_id, + '@name' => $name, + '@slug' => $slug, + '@dest' => $destination_property, + '@value' => $value, + ]); + + return $value; + } +} -- GitLab