2009-10-19 18:28:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Install, update and uninstall functions for the rdf module.
|
|
|
|
*/
|
|
|
|
|
2013-06-24 22:21:37 +00:00
|
|
|
use Drupal\Component\Uuid\Uuid;
|
|
|
|
|
2009-10-19 18:28:16 +00:00
|
|
|
/**
|
2013-06-24 22:21:37 +00:00
|
|
|
* Convert RDF mappings to configuration.
|
|
|
|
*
|
|
|
|
* @ingroup config_upgrade
|
2009-10-19 18:28:16 +00:00
|
|
|
*/
|
2013-06-24 22:21:37 +00:00
|
|
|
function rdf_update_8000() {
|
|
|
|
$uuid = new Uuid();
|
|
|
|
$query = db_query("SELECT * FROM {rdf_mapping}");
|
2009-10-19 18:28:16 +00:00
|
|
|
|
2013-06-24 22:21:37 +00:00
|
|
|
// Iterate through all the stored mappings.
|
|
|
|
while ($row = $query->fetchAssoc()) {
|
|
|
|
$mapping = unserialize($row['mapping']);
|
|
|
|
$entity_type = $row['type'];
|
|
|
|
$bundle = $row['bundle'];
|
2009-10-19 18:28:16 +00:00
|
|
|
|
2013-06-24 22:21:37 +00:00
|
|
|
// 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();
|
|
|
|
}
|
2009-10-19 18:28:16 +00:00
|
|
|
}
|