-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgallerysite.install
71 lines (58 loc) · 2.19 KB
/
gallerysite.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
<?php
use Drupal\Core\Messenger\MessengerInterface as MessengerInterface;
function _gallerysite_replace_internal_url($table, $column, $field, $entity_type) {
// Get all websites where the URL starts with a slash.
$db = \Drupal::database();
$query = $db->select($table, 'fw')
->fields('fw', array('entity_id', $column));
$query->condition($column, "%" . $query->escapeLike('internal') . "%", 'LIKE');
$result = $query->execute()->fetchAll();
foreach ($result as $row) {
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($row->entity_id);
// Get the field value.
$website = $entity->get($field)->getValue();
// Fix the URL.
$website[0]['uri'] = str_replace('internal:/', 'http://', $row->{$column});
$entity->set($field, $website);
// Save the node.
$entity->save();
}
}
/**
* Fix all gallery websites which start with a slash.
*/
function gallerysite_update_8001() {
_gallerysite_replace_internal_url('node__field_website', 'field_website_uri', 'field_website', 'node');
}
/**
* Fix all exhibition websites which start with a slash.
*/
function gallerysite_update_8002() {
_gallerysite_replace_internal_url('node__field_exhib_website', 'field_exhib_website_uri', 'field_exhib_website', 'node');
}
/**
* Delete tags with no related content.
*/
function gallerysite_update_8003() {
$connection = \Drupal::database();
$result = $query = $connection->query("SELECT tid, name FROM {taxonomy_term_field_data} WHERE vid = 'tags'
AND tid NOT IN (SELECT tid FROM {taxonomy_index})
AND tid NOT IN (SELECT field_tags_target_id FROM {taxonomy_term__field_tags})
AND tid NOT IN (SELECT field_tags_target_id FROM {node__field_tags})");
$count = 0;
foreach ($result as $row) {
$count++;
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($row->tid);
$term->delete();
$message = 'Term ' . $row->tid . ' - ' . $row->name . ' deleted';
\Drupal::logger('gallerysite')->notice($message);
}
\Drupal::messenger()->addMessage($count . ' tags deleted');
}
/**
* Updates for Drupal 10.
*/
function gallerysite_update_10001() {
$installer = \Drupal::service('theme_installer');
$installer->install(['classy']);
}