-
Notifications
You must be signed in to change notification settings - Fork 5
/
ad_integration.install
49 lines (45 loc) · 1.44 KB
/
ad_integration.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
<?php
/**
* @file
* Contains updates.
*/
/**
* Update field schema.
*/
function ad_integration_update_8001() {
$database = \Drupal::database();
$database_schema = $database->schema();
$entity_types = \Drupal::entityTypeManager()->getDefinitions();
$schema = \Drupal::keyValue('entity.storage_schema.sql')->getAll();
$schema_copy = $schema;
foreach ($schema as $item_name => $item) {
list($entity_type_id, ,) = explode('.', $item_name);
if (!isset($entity_types[$entity_type_id])) {
continue;
}
foreach ($item as $table_name => $table_schema) {
foreach ($table_schema as $schema_key => $schema_data) {
if ($schema_key === 'fields') {
if (isset($schema_data['field_advertising_adsc_mode'])) {
$field_name = 'field_advertising_adsc_keyword';
$field_definition = array(
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
);
$schema_copy[$item_name][$table_name]['fields'][$field_name] = $field_definition;
if ($database->driver() == 'mysql') {
// $database_schema->addField();
try {
$database_schema->addField($table_name, $field_name, $field_definition);
}
catch (\Exception $e) {
}
}
}
}
}
}
}
\Drupal::keyValue('entity.storage_schema.sql')->setMultiple($schema_copy);
}