drupal/core/modules/rdf/rdf.install

61 lines
1.9 KiB
Plaintext
Raw Normal View History

<?php
/**
* @file
* Install, update and uninstall functions for the rdf module.
*/
use Drupal\Component\Uuid\Uuid;
/**
* 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 = 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'] = $value['callback'] : NULL;
}
}
$config->set('fieldMappings', $field_mappings);
// Save the mapping config object.
$config->save();
}
}