Переглянути джерело

popsu_migrate: D7NodeStatic ok

bach 3 роки тому
батько
коміт
e9faec41fc

+ 1 - 1
config/sync/migrate_plus.migration.d7_allpublicfiles.yml

@@ -1,4 +1,4 @@
-uuid: 3b18c19c-bd38-4a42-b283-25f371788ec9
+uuid: e1cf47fe-1b42-4c9a-a3f9-80e79bac0005
 langcode: fr
 status: true
 dependencies: {  }

+ 1 - 1
config/sync/migrate_plus.migration.d7_node_programme.yml

@@ -1,4 +1,4 @@
-uuid: ff1ce5b3-a7b2-40b0-8e9e-2ec01681c77a
+uuid: b45c0dd4-f26e-46cc-b7bd-15ad9bcee8b1
 langcode: fr
 status: true
 dependencies: {  }

+ 1 - 1
config/sync/migrate_plus.migration.d7_node_projet.yml

@@ -1,4 +1,4 @@
-uuid: 2813009c-582e-402d-9e02-f0f05d12a3dd
+uuid: df23e80f-3155-40c8-87cf-c345ad055d9d
 langcode: fr
 status: true
 dependencies: {  }

+ 49 - 0
config/sync/migrate_plus.migration.d7_node_static.yml

@@ -0,0 +1,49 @@
+uuid: 28dfe1fe-90b9-4311-a46e-3ec3dbbd0053
+langcode: fr
+status: true
+dependencies: {  }
+_core:
+  default_config_hash: giLUW65Fkj4Orn9QcEvs9tTY5s_MZ66ETkDLSoU8btk
+id: d7_node_static
+class: null
+field_plugin_method: null
+cck_plugin_method: null
+migration_tags:
+  - 'Drupal 7'
+  - Content
+  - Popsu
+migration_group: popsu
+label: 'Node Static'
+source:
+  plugin: d7_node_static
+  batch_size: 500
+process:
+  type:
+    plugin: default_value
+    default_value: static
+  created: created
+  changed: changed
+  uid:
+    plugin: default_value
+    default_value: 34
+  title: title
+  field_textes: field_textes
+  field_pieces_jointes:
+    plugin: sub_process
+    source: field_popsu_pageneutral_insert
+    process:
+      target_id:
+        plugin: migration_lookup
+        migration: d7_allpublicfiles
+        source: fid
+        no_stub: true
+      display: display
+      description: description
+  field_memo: field_memo
+destination:
+  plugin: 'entity:node'
+migration_dependencies:
+  required:
+    - d7_allpublicfiles
+    - d7_users
+    - d7_taxonomy_term_type_theme

+ 1 - 1
config/sync/migrate_plus.migration.d7_node_theme.yml

@@ -1,4 +1,4 @@
-uuid: 9d6fb691-ce28-425c-af92-302d08a722fc
+uuid: 83bd4f30-716c-4ae8-918b-55bb56e0ea2e
 langcode: fr
 status: true
 dependencies: {  }

+ 1 - 1
config/sync/migrate_plus.migration.d7_taxonomy_term_type_theme.yml

@@ -1,4 +1,4 @@
-uuid: f7a74141-0abc-49d9-b16e-a5614c84c5f5
+uuid: 6d30ad1d-8450-451f-be72-efdae5dfb3c4
 langcode: fr
 status: true
 dependencies: {  }

+ 1 - 1
config/sync/migrate_plus.migration.d7_taxonomy_term_ville.yml

@@ -1,4 +1,4 @@
-uuid: e1ae926a-63cc-4c77-b7a4-033ef995bc22
+uuid: 55c6fb53-6dac-4ec7-a0f8-3f9655b0b1e4
 langcode: fr
 status: true
 dependencies: {  }

+ 1 - 1
config/sync/migrate_plus.migration.d7_users.yml

@@ -1,4 +1,4 @@
-uuid: d5f4eb4e-b259-4f8b-842d-62dad092b522
+uuid: 16730dbd-d94c-4962-ac1b-9acc603b7e8d
 langcode: fr
 status: true
 dependencies: {  }

+ 1 - 1
config/sync/migrate_plus.migration_group.popsu.yml

@@ -1,4 +1,4 @@
-uuid: ff4c5119-217d-405f-a438-c2badb8900c9
+uuid: beb0c7e2-2ff3-4eef-a325-aa30360a6817
 langcode: fr
 status: true
 dependencies:

+ 54 - 0
web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_node_static.yml

@@ -0,0 +1,54 @@
+id: d7_node_static
+label: Node Static
+migration_group: popsu
+audit: true
+migration_tags:
+  - Drupal 7
+  - Content
+  - Popsu
+
+source:
+  plugin: d7_node_static
+  batch_size: 500
+  # high_water_property:
+  #   name: changed
+  #   alias: n
+
+destination:
+  plugin: entity:node
+
+process:
+  # nid: nid
+  type:
+    plugin: default_value
+    default_value: static
+  created: created
+  changed: changed
+
+  uid:
+    plugin: default_value
+    default_value: 34
+
+  title: title
+
+  field_textes: field_textes
+
+  field_pieces_jointes:
+    plugin: sub_process
+    source: field_popsu_pageneutral_insert
+    process:
+      target_id:
+        plugin: migration_lookup
+        migration: d7_allpublicfiles
+        source: fid
+        no_stub: true
+      display: display
+      description: description
+
+  field_memo: field_memo
+
+migration_dependencies:
+  required:
+    - d7_allpublicfiles
+    - d7_users
+    - d7_taxonomy_term_type_theme

+ 201 - 0
web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7NodeStatic.php

@@ -0,0 +1,201 @@
+<?php
+namespace Drupal\popsu_migrate\Plugin\migrate\source;
+
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\migrate\Row;
+use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
+use Drupal\Core\Database\Query\SelectInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Extension\ModuleHandler;
+use Drupal\Core\State\StateInterface;
+use Drupal\migrate\Plugin\MigrationInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Logger\LoggerChannelFactoryInterface;
+use Drush\Drush;
+use Drupal\paragraphs\Entity\Paragraph;
+
+
+/**
+ * Drupal 7 node source from database.
+ *
+ * @MigrateSource(
+ *   id = "d7_node_static",
+ *   source_module = "node"
+ * )
+ */
+class D7NodeStatic extends FieldableEntity {
+  /**
+   * The module handler.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * The logger channel.
+   *
+   * @var \Drupal\Core\Logger\LoggerChannelInterface
+   */
+  protected $logger;
+
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_manager, ModuleHandlerInterface $module_handler,LoggerChannelFactoryInterface $loggerFactory) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
+    $this->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);
+
+    $query->condition('n.type', ['popsu_page_neutral'], 'IN');
+
+    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::output()->writeln('- - - - ' . $title . ' ('.$nid.')' . '- - - - ');
+
+    $memo = '';
+    $memo .= "#migration : old nid = ".$nid."\n";
+    $memo .= "#migration : old content type = ".$type."\n";
+
+    // Get Field API field values.
+    foreach ($this->getFields('node', $type) as $field_name => $field) {
+      $field_values = $this->getFieldValues('node', $field_name, $nid, $vid, NULL);
+      $row->setSourceProperty($field_name, $field_values);
+      // switch ($field_name) {
+      //   // ville
+      //   case 'field_popsu_ville_ville':
+      //     $ville = $field_values;
+      //     break;
+      // }
+    }
+
+    # Text paragraphe
+    $text_fields = array(
+      'field_popsu_pageneutral_body' => 'Texte de la page',
+      'field_popsu_pageneutral_col2' => 'Texte de la 2ème colone',
+    );
+    $textes_paragraphes = array();
+    foreach ($text_fields as $field_name => $title) {
+      if ($text = $row->getSourceProperty($field_name)){
+        // Drush::output()->writeln(dump($text));
+        $text[0]['format'] = 'wysiwyg';
+        $p = Paragraph::create(['type' => 'textes']);
+        $p->set('field_texte', $text)
+        ->set('field_titre', $title)
+        ->isNew();
+        $p->save();
+        $textes_paragraphes[] = array(
+          'target_id' => $p->id(),
+          'target_revision_id' => $p->getRevisionId(),
+        );
+      }
+    }
+    if (!empty($textes_paragraphes)) {
+      // Drush::output()->writeln(dump($textes_paragraphes));
+      $row->setSourceProperty('field_textes', $textes_paragraphes);
+    }
+
+    // record migration errors in field_memo
+    if(isset($memo)){
+      $field_memo = array(
+        array(
+          'value' => $memo
+        )
+      );
+      $row->setSourceProperty('field_memo', $field_memo);
+    }
+
+    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;
+  }
+
+}