From 9108d898df0b9ab45676ad8da07b760066eaae90 Mon Sep 17 00:00:00 2001 From: David Valdez Date: Wed, 2 Oct 2019 13:44:29 -0500 Subject: [PATCH] Add the summary in the authors. The summary is just the bio of the author. --- .../upgrade_d7_node_story_author.yml | 1 + .../src/Plugin/migrate/source/Author.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/web/modules/custom/geo_upgrade/migrations/upgrade_d7_node_story_author.yml b/web/modules/custom/geo_upgrade/migrations/upgrade_d7_node_story_author.yml index 3b18232..e7bd9b5 100644 --- a/web/modules/custom/geo_upgrade/migrations/upgrade_d7_node_story_author.yml +++ b/web/modules/custom/geo_upgrade/migrations/upgrade_d7_node_story_author.yml @@ -28,6 +28,7 @@ process: - plugin: migration_lookup migration: upgrade_d7_taxonomy_term_custom_terms source: constants/author_type_source_id + field_summary: bio destination: plugin: 'entity:node' default_bundle: people diff --git a/web/modules/custom/geo_upgrade/src/Plugin/migrate/source/Author.php b/web/modules/custom/geo_upgrade/src/Plugin/migrate/source/Author.php index 215d5b6..70e6468 100644 --- a/web/modules/custom/geo_upgrade/src/Plugin/migrate/source/Author.php +++ b/web/modules/custom/geo_upgrade/src/Plugin/migrate/source/Author.php @@ -24,6 +24,30 @@ class Author extends SqlBase { // Make sure to all the author names are trimmed. $row->setSourceProperty('field_author_value', trim($field_author)); + // The bio value is going to be get from the last contribution of the user + // where the bio field is not empty. + $query = $this->database->query( + 'SELECT entity_id, revision_id FROM field_data_field_author WHERE field_author_value = :field_author ORDER BY entity_id DESC', + ['field_author' => $field_author] + ); + foreach ($query as $record) { + $bio_query = $this->database->query( + "SELECT field_author_bio_value FROM field_data_field_author_bio WHERE entity_id = :entity_id AND revision_id = :revision_id", + ['entity_id' => $record->entity_id, 'revision_id' => $record->revision_id] + ); + $bio_result = $bio_query->fetchAssoc(); + + // Once we find a bio no need to continue. + if (!empty($bio_result)) { + break; + } + } + + $row->setSourceProperty('bio', ["value" => '']); + if (!empty($bio_result)) { + $row->setSourceProperty('bio', ["value" => $bio_result['field_author_bio_value']]); + } + return parent::prepareRow($row); }