From 721e626e1e9e454eb9736e1b7e41ee44d5678588 Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 15 Apr 2021 16:23:38 +0200 Subject: [PATCH] popsu_migrate: d7_node_programme started --- ...grate_plus.migration.d7_node_programme.yml | 50 +++++ .../migrate_plus.migration.d7_users.yml | 1 - ...=> migrate_plus.migration_group.popsu.yml} | 0 .../Plugin/migrate/source/D7NodeProgramme.php | 187 ++++++++++++++++++ 4 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_node_programme.yml rename web/modules/custom/popsu_migrate/config/install/{migrate_plus.migration_group.d7_popsu.yml => migrate_plus.migration_group.popsu.yml} (100%) create mode 100644 web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7NodeProgramme.php diff --git a/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_node_programme.yml b/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_node_programme.yml new file mode 100644 index 00000000..fc75e9be --- /dev/null +++ b/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_node_programme.yml @@ -0,0 +1,50 @@ +id: d7_node_programme +label: Node Programme +migration_group: popsu +audit: true +migration_tags: + - Drupal 7 + - Content + - Popsu + +source: + plugin: d7_node_programme + node_type: popsu_special + batch_size: 500 + high_water_property: + name: changed + alias: n + +destination: + plugin: entity:node + + +process: + # nid: nid + type: + plugin: default_value + default_value: programme + created: created + changed: changed + + uid: + plugin: default_value + default_value: 34 + + title: term_title + + 'body/value': body + 'body/summary': body_summary + 'body/format': + plugin: default_value + default_value: 'wysiwyg' + + # field_textes (PARAGRAPH) + # 'field_texte/value': text + # 'field_texte/summary': text_summary + # field_titre: title + +migration_dependencies: + required: + - d7_allpublicfiles + - d7_users diff --git a/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_users.yml b/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_users.yml index 20d22a18..355b03df 100644 --- a/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_users.yml +++ b/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_users.yml @@ -57,7 +57,6 @@ process: method: row value: - 5 - - 3 - plugin: static_map source: roles diff --git a/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration_group.d7_popsu.yml b/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration_group.popsu.yml similarity index 100% rename from web/modules/custom/popsu_migrate/config/install/migrate_plus.migration_group.d7_popsu.yml rename to web/modules/custom/popsu_migrate/config/install/migrate_plus.migration_group.popsu.yml diff --git a/web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7NodeProgramme.php b/web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7NodeProgramme.php new file mode 100644 index 00000000..b5fe6675 --- /dev/null +++ b/web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7NodeProgramme.php @@ -0,0 +1,187 @@ +moduleHandler = $module_handler; + $this->logger = $loggerFactory->get('popsu_migration'); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('state'), + $container->get('entity_type.manager'), + $container->get('module_handler'), + $container->get('logger.factory') + ); + } + + /** + * The join options between the node and the node_revisions table. + */ + const JOIN = 'n.vid = nr.vid'; + + /** + * {@inheritdoc} + */ + public function query() { + // Select node in its last revision. + $query = $this->select('node_revision', 'nr') + ->fields('n', [ + 'nid', + 'type', + 'uid', + 'language', + 'status', + 'created', + 'changed', + ]) + ->fields('nr', [ + 'vid', + 'title', + 'log', + 'timestamp', + ]) + ->orderBy('changed'); + + $query->addField('n', 'uid', 'node_uid'); + $query->addField('nr', 'uid', 'revision_uid'); + $query->innerJoin('node', 'n', static::JOIN); + + if (isset($this->configuration['node_type'])) { + $query->condition('n.type', $this->configuration['node_type']); + } + + // field_popsu_special_typetaxo 31 + $query->leftJoin('field_revision_field_popsu_special_typetaxo', 'ff', 'ff.revision_id = n.vid'); + $query->fields('ff', [ + 'field_popsu_special_typetaxo_tid' + ]); + $query->condition('ff.field_popsu_special_typetaxo_tid', 31); + + return $query; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $nid = $row->getSourceProperty('nid'); + $vid = $row->getSourceProperty('vid'); + $type = $row->getSourceProperty('type'); + // $title = $row->getSourceProperty('title'); + // drush_print('-- '.$nid."\t".$title); + + // Get Field API field values. + foreach ($this->getFields('node', $type) as $field_name => $field) { + // Ensure we're using the right language if the entity and the field are + // translatable. + // $field_language = $entity_translatable && $field['translatable'] ? $language : NULL; + $row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, NULL)); + } + + // title from taxo term + $field_popsu_special_popsu_tid = $row->getSourceProperty('field_popsu_special_popsu')[0]['tid']; + Drush::output()->writeln('tid:' . $field_popsu_special_popsu_tid); + $q = $this->select('taxonomy_term_data', 'ttd') + ->fields('ttd', ['tid','name']) + ->condition('tid', $field_popsu_special_popsu_tid); + $term = $q->execute()->fetchAll(); + Drush::output()->writeln(dump($term)); + $row->setSourceProperty('term_title', $term[0]['name']); + + // text intro + $body = $row->getSourceProperty('field_popsu_special_body'); + $row->setSourceProperty('body', $body[0]['value']); + $row->setSourceProperty('body_summary', $body[0]['summary']); + + // texts + // $text = $row->getSourceProperty('field_popsu_special_text') + // $row->setSourceProperty('text', $text[0]['value']); + // $row->setSourceProperty('text_summary', $text[0]['summary']); + + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = [ + 'nid' => $this->t('Node ID'), + 'type' => $this->t('Type'), + 'title' => $this->t('Title'), + 'node_uid' => $this->t('Node authored by (uid)'), + 'revision_uid' => $this->t('Revision authored by (uid)'), + 'created' => $this->t('Created timestamp'), + 'changed' => $this->t('Modified timestamp'), + 'status' => $this->t('Published'), + 'promote' => $this->t('Promoted to front page'), + 'sticky' => $this->t('Sticky at top of lists'), + 'revision' => $this->t('Create new revision'), + 'language' => $this->t('Language (fr, en, ...)'), + 'tnid' => $this->t('The translation set id for this node'), + 'timestamp' => $this->t('The timestamp the latest revision of this node was created.'), + ]; + return $fields; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['nid']['type'] = 'integer'; + $ids['nid']['alias'] = 'n'; + return $ids; + } + +}