Skip to content
rdf.install 1.87 KiB
Newer Older
<?php

/**
 * @file
 * Install, update and uninstall functions for the rdf module.
 */

 * Convert RDF mappings to configuration.
 *
 * @ingroup config_upgrade
function rdf_update_8000() {
  $uuid = new Uuid();
  $query = db_query("SELECT * FROM {rdf_mapping}");
  // Iterate through all the stored mappings.
  while ($row = $query->fetchAssoc()) {
    $mapping = unserialize($row['mapping']);
    $entity_type = $row['type'];
    $bundle = $row['bundle'];
    // Create a config object for the mapping.
    $config = Drupal::config("rdf.mapping.$entity_type.$bundle")
      ->set('id', "$entity_type.$bundle")
      ->set('uuid', $uuid->generate())
      ->set('targetEntityType', $entity_type)
      ->set('bundle', $bundle);

    // Add the bundle and field mappings.
    $field_mappings = array();
    foreach ($mapping as $key => $value) {
      // If this is the rdftype entry, add the types to the config object.
      if ($key == 'rdftype') {
        $config->set('types', $value);
      }
      // Otherwise, this key is a field. Process the field mapping into the new
      // structure.
      else {
        // Since reverse relations are not supported in D8, drop any mappings
        // which use the 'rev' type.
        if (!empty($value['type'])) {
          if ($value['type'] == 'rev') {
            continue;
          }
          $field_mappings[$key]['mapping_type'] = $value['type'];
        }
        !empty($value['predicates']) ? $field_mappings[$key]['properties'] = $value['predicates'] : NULL;
        !empty($value['datatype']) ? $field_mappings[$key]['datatype'] = $value['datatype'] : NULL;
        !empty($value['callback']) ? $field_mappings[$key]['datatype_callback']['callable'] = $value['callback'] : NULL;
      }
    }
    $config->set('fieldMappings', $field_mappings);

    // Save the mapping config object.
    $config->save();
  }