forked from openeuropa/rdf_entity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdf_entity.install
95 lines (83 loc) · 3.46 KB
/
rdf_entity.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* @file
* Includes installation functions for the rdf_entity module.
*/
use Drupal\Core\Serialization\Yaml;
use Drupal\rdf_entity\Entity\RdfEntityGraph;
use Drupal\rdf_entity\Entity\RdfEntityMapping;
use Drupal\rdf_entity\Entity\RdfEntitySparqlStorage;
/**
* Implements hook_requirements().
*/
function rdf_entity_requirements($phase) {
$requirements = [];
if ($phase !== 'runtime') {
return $requirements;
}
$requirements += rdf_entity_virtuoso_version_requirements();
// If the endpoint is not available, return early.
if (
isset($requirements['rdf_entity_endpoint']['severity']) &&
$requirements['rdf_entity_endpoint']['severity'] === REQUIREMENT_ERROR
) {
return $requirements;
}
$requirements += rdf_entity_virtuoso_permission_requirements();
return $requirements;
}
/**
* Move RDF entity mapping data from bundle entities into dedicated entities.
*/
function rdf_entity_update_8001() {
$entity_type_manager = \Drupal::entityTypeManager();
// Clear the cache, so the new entity type definitions are available.
$entity_type_manager->clearCachedDefinitions();
// Update or post-update scripts might need this config entity available when
// they run. We don't wait on configuration synchronization, because that runs
// usually after the database update, so we make this entity available in an
// early stage of updates.
$values = Yaml::decode(file_get_contents(__DIR__ . '/config/install/rdf_entity.graph.default.yml'));
RdfEntityGraph::create($values)->save();
// Iterate over all entities that are bundles of content entities with
// RdfEntitySparqlStorage and move their 3rd party settings belonging to
// rdf_entity module into their dedicated rdf_entity_mapping config entities.
foreach ($entity_type_manager->getDefinitions() as $entity_type_id => $entity_type) {
$storage = $entity_type_manager->getStorage($entity_type_id);
if (!$storage instanceof RdfEntitySparqlStorage) {
continue;
}
if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) {
$bundle_storage = $entity_type_manager->getStorage($bundle_entity_type_id);
/** @var \Drupal\Core\Config\Entity\ConfigEntityBase $bundle_entity */
foreach ($bundle_storage->loadMultiple() as $bundle => $bundle_entity) {
$third_party_settings = $bundle_entity->getThirdPartySettings('rdf_entity');
$values = [
'entity_type_id' => $entity_type_id,
'bundle' => $bundle,
] + $third_party_settings;
// Rename key 'mapping' to 'base_fields_mapping'.
$values['base_fields_mapping'] = $values['mapping'] ?? [];
unset($values['mapping']);
// Create and save the new 'rdf_entity_mapping' entity.
RdfEntityMapping::create($values)->save();
// Cleanup 3rd party settings from the bundle entity.
foreach ($third_party_settings as $key => $value) {
$bundle_entity->unsetThirdPartySetting('rdf_entity', $key);
}
$bundle_entity->save();
}
}
}
}
/**
* Install 'rdf_entity_graph' and 'rdf_entity_mapping' entity types.
*/
function rdf_entity_update_8002() {
$entity_type_manager = \Drupal::entityTypeManager();
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
foreach (['rdf_entity_graph', 'rdf_entity_mapping'] as $entity_type_id) {
$entity_type = $entity_type_manager->getDefinition($entity_type_id);
$entity_definition_update_manager->installEntityType($entity_type);
}
}