Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / rdf / src / Plugin / migrate / source / d7 / RdfMapping.php
diff --git a/web/core/modules/rdf/src/Plugin/migrate/source/d7/RdfMapping.php b/web/core/modules/rdf/src/Plugin/migrate/source/d7/RdfMapping.php
new file mode 100644 (file)
index 0000000..2dca9e0
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+namespace Drupal\rdf\Plugin\migrate\source\d7;
+
+use Drupal\migrate\Row;
+use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
+
+/**
+ * Drupal 7 rdf source from database.
+ *
+ * @MigrateSource(
+ *   id = "d7_rdf_mapping",
+ *   source_module = "rdf"
+ * )
+ */
+class RdfMapping extends DrupalSqlBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function query() {
+    return $this->select('rdf_mapping', 'r')->fields('r');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function prepareRow(Row $row) {
+    $field_mappings = [];
+    foreach (unserialize($row->getSourceProperty('mapping')) as $field => $mapping) {
+      if ($field === 'rdftype') {
+        $row->setSourceProperty('types', $mapping);
+      }
+      else {
+        $field_mappings[$field] = $mapping;
+      }
+    }
+    $row->setSourceProperty('fieldMappings', $field_mappings);
+
+    return parent::prepareRow($row);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function fields() {
+    return [
+      'type' => $this->t('The name of the entity type a mapping applies to (node, user, comment, etc.'),
+      'bundle' => $this->t('The name of the bundle a mapping applies to.'),
+      'mapping' => $this->t('The serialized mapping of the bundle type and fields to RDF terms.'),
+      'types' => $this->t('RDF types.'),
+      'fieldMappings' => $this->t('RDF field mappings.'),
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getIds() {
+    return [
+      'type' => [
+        'type' => 'string',
+      ],
+      'bundle' => [
+        'type' => 'string',
+      ],
+    ];
+  }
+
+}