|
@@ -0,0 +1,124 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Drupal\edlp_migrate\Plugin\migrate\source;
|
|
|
+
|
|
|
+use Drupal\migrate\Row;
|
|
|
+use Drupal\node\Plugin\migrate\source\d6\Node as D6Node;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Source plugin for edlp corpus migration.
|
|
|
+ *
|
|
|
+ * @MigrateSource(
|
|
|
+ * id = "d6_edlp_corpus"
|
|
|
+ * )
|
|
|
+ */
|
|
|
+class D6EdlpCorpus extends D6Node {
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
+ public function query() {
|
|
|
+ $query = $this->select('node_revisions', 'nr');
|
|
|
+ $query->innerJoin('node', 'n', static::JOIN);
|
|
|
+ $this->handleTranslations($query);
|
|
|
+
|
|
|
+ $query->fields('n', [
|
|
|
+ 'nid',
|
|
|
+ 'type',
|
|
|
+ 'language',
|
|
|
+ 'status',
|
|
|
+ 'created',
|
|
|
+ 'changed',
|
|
|
+ 'comment',
|
|
|
+ 'promote',
|
|
|
+ 'moderate',
|
|
|
+ 'sticky',
|
|
|
+ 'tnid',
|
|
|
+ 'translate',
|
|
|
+ ])
|
|
|
+ ->fields('nr', [
|
|
|
+ 'title',
|
|
|
+ 'body',
|
|
|
+ 'teaser',
|
|
|
+ 'log',
|
|
|
+ 'timestamp',
|
|
|
+ 'format',
|
|
|
+ 'vid',
|
|
|
+ ]);
|
|
|
+ $query->addField('n', 'uid', 'node_uid');
|
|
|
+ $query->addField('nr', 'uid', 'revision_uid');
|
|
|
+
|
|
|
+ // If the content_translation module is enabled, get the source langcode
|
|
|
+ // to fill the content_translation_source field.
|
|
|
+ if ($this->moduleHandler->moduleExists('content_translation')) {
|
|
|
+ $query->leftJoin('node', 'nt', 'n.tnid = nt.nid');
|
|
|
+ $query->addField('nt', 'language', 'source_langcode');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($this->configuration['node_type'])) {
|
|
|
+ $query->condition('n.type', $this->configuration['node_type']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $query;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
+ public function fields() {
|
|
|
+
|
|
|
+ $fields = [
|
|
|
+ 'nid' => $this->t('Node ID'),
|
|
|
+ 'type' => $this->t('Type'),
|
|
|
+ 'title' => $this->t('Title'),
|
|
|
+ 'body' => $this->t('Body'),
|
|
|
+ 'format' => $this->t('Format'),
|
|
|
+ 'teaser' => $this->t('Teaser'),
|
|
|
+ '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 prepareRow(Row $row) {
|
|
|
+ // format = 0 can happen when the body field is hidden. Set the format to 1
|
|
|
+ // to avoid migration map issues (since the body field isn't used anyway).
|
|
|
+ if ($row->getSourceProperty('format') === '0') {
|
|
|
+ $row->setSourceProperty('format', $this->filterDefaultFormat);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->moduleExists('content') && $this->getModuleSchemaVersion('content') >= 6001) {
|
|
|
+ foreach ($this->getFieldValues($row) as $field => $values) {
|
|
|
+ $row->setSourceProperty($field, $values);
|
|
|
+ // \Drupal::logger('edlp_migrate')->debug(print_r($values));
|
|
|
+ // print_r($field);
|
|
|
+ // print_r("\n");
|
|
|
+ // print_r($values);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Make sure we always have a translation set.
|
|
|
+ if ($row->getSourceProperty('tnid') == 0) {
|
|
|
+ $row->setSourceProperty('tnid', $row->getSourceProperty('nid'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $row = parent::prepareRow($row);
|
|
|
+ return $row;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|