-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisqus.install
76 lines (66 loc) · 2.52 KB
/
disqus.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
<?php
/**
* @file
* Provides any upgrade path requirements.
*/
/**
* Updates from Drupal 6 to 7.
*/
function disqus_update_7000() {
// Nothing.
}
/**
* Updates Disqus with support for toggling comments per node.
*/
function disqus_update_7001() {
if (!db_table_exists('disqus')) {
drupal_install_schema('disqus');
}
}
/**
* Remove deprecated variable.
*/
function disqus_update_7002() {
variable_del('disqus_userapikey');
}
/**
* Add identifier to field storage definition.
*/
function disqus_update_8001() {
\Drupal::entityTypeManager()->clearCachedDefinitions();
$database = \Drupal::database();
$property_name = 'identifier';
$fields = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->loadByProperties(['type' => 'disqus_comment']);
/** @var \Drupal\field\Entity\FieldStorageConfig $field */
foreach ($fields as $field) {
$schema = $field->getSchema();
$target_entity_type = \Drupal::entityTypeManager()
->getDefinition($field->getTargetEntityTypeId());
$stored_schema = \Drupal::keyValue('entity.storage_schema.sql')
->get($target_entity_type->id() . '.field_schema_data.' . $field->getName());
/** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $storage */
$storage = \Drupal::entityTypeManager()->getStorage($target_entity_type->id());
$table_mapping = $storage->getTableMapping();
$column_name = $table_mapping->getFieldColumnName($field, $property_name);
// Data table.
$data_table = $table_mapping->getDedicatedDataTableName($field);
if (!$database->schema()->fieldExists($data_table, $column_name)) {
$database->schema()->addField($data_table, $column_name, $schema['columns'][$property_name]);
$stored_schema[$data_table]['fields'][$column_name] = $schema['columns'][$property_name];
}
// Revision table is relevant.
if ($target_entity_type->isRevisionable()) {
$revision_table = $table_mapping->getDedicatedRevisionTableName($field);
if (!$database->schema()->fieldExists($revision_table, $column_name)) {
$database->schema()->addField($revision_table, $column_name, $schema['columns'][$property_name]);
$stored_schema[$revision_table]['fields'][$column_name] = $schema['columns'][$property_name];
}
}
\Drupal::service('entity.last_installed_schema.repository')
->setLastInstalledFieldStorageDefinition($field);
\Drupal::keyValue('entity.storage_schema.sql')
->set($target_entity_type->id() . '.field_schema_data.' . $field->getName(), $stored_schema);
}
}