-
Notifications
You must be signed in to change notification settings - Fork 9
/
islandora_mirador.install
84 lines (74 loc) · 2.61 KB
/
islandora_mirador.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
<?php
/**
* @file
* Install/update hook implementations.
*/
use Drupal\taxonomy\Entity\Term;
/**
* Implements hook_install().
*/
function islandora_mirador_install($is_syncing) {
if (!_islandora_mirador_term_exists()) {
$callable = $is_syncing ? [\Drupal::messenger(), 'addStatus'] : [\Drupal::messenger(), 'addWarning'];
$callable(t('A term in the taxonomy @vid with the URI @uri does not appear to exist. The @migration_id migration can be executed to create it.', [
'@vid' => 'islandora_display',
'@uri' => 'https://projectmirador.org',
'@migration_id' => 'islandora_mirador_tags',
]));
}
}
/**
* Implements hook_requirements().
*/
function islandora_mirador_requirements($phase) : array {
$requirements = [];
if ($phase == 'runtime') {
$term_exists = _islandora_mirador_term_exists();
$requirements['islandora_mirador_term_exists'] = [
'title' => t('Mirador Term Exists'),
'value' => $term_exists ? t('Exists') : t('Does not exist'),
'description' => t('Whether or not a term with the URI targeted by default Mirador viewer configuration exists. If viewer configurations were made to target another URI, this can probably be ignored.'),
'severity' => $term_exists ? REQUIREMENT_OK : REQUIREMENT_WARNING
];
}
return $requirements;
}
/**
* Implements hook_update_last_removed.
*/
function islandora_mirador_update_last_removed() {
return 8001;
}
/**
* Set a default config value for mirador_library_installation_type
* @return void
*/
function islandora_mirador_update_20001() {
$config = \Drupal::configFactory()->getEditable('islandora_mirador.settings');
$config->set('mirador_library_installation_type', 'remote');
$config->save();
}
/**
* Helper; determine if a term with the target URI exists.
*
* @return bool
* TRUE if a term (at least one) with the target URI exists; otherwise, FALSE.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function _islandora_mirador_term_exists() {
$table_exists = \Drupal::database()->schema()->tableExists('taxonomy_term__field_external_uri');
if (!$table_exists) {
// XXX: If the table does not exist, then avoid attempting to make a query
// making use of the non-existent table.
return FALSE;
}
$query = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->getQuery()
->condition('vid', 'islandora_display')
->condition('field_external_uri.uri', 'https://projectmirador.org')
->accessCheck(FALSE)
->count();
$count = $query->execute();
return $count > 0;
}