-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowntracks.install
238 lines (207 loc) · 7.05 KB
/
owntracks.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
* @file
* Install functions of the module.
*/
use Drupal\Core\Url;
use Symfony\Component\Yaml\Yaml;
/**
* Implements hook_requirements().
*/
function owntracks_requirements($phase) {
if ($phase === 'runtime') {
$settings = \Drupal::config('owntracks.map.settings')->get();
return [
'owntracks' => [
'title' => 'OwnTracks Map Configuration',
'value' => empty($settings) ? t('Not configured') : t('Configured'),
'severity' => empty($settings) ? REQUIREMENT_ERROR : REQUIREMENT_OK,
'description' => empty($settings) ? t('OwnTracks Map is not configured. <a href=":url">Add configuration</a>', [':url' => Url::fromRoute('owntracks.map_settings')]) : t('OwnTracks Map is configured.'),
],
];
}
}
/**
* Truncate table {cache_data} to allow p (Ping) location trigger value.
*/
function owntracks_update_8001() {
\Drupal::database()->query('TRUNCATE table {cache_data}');
}
/**
* Fix cache contexts of owntracks entities views.
*/
function owntracks_update_8002() {
$names = [
'views.view.owntracks_location',
'views.view.owntracks_waypoint',
'views.view.owntracks_transition',
];
foreach ($names as $name) {
$update = FALSE;
$config = \Drupal::configFactory()->getEditable($name);
$contexts = (array) $config->get('display.user.cache_metadata.contexts');
foreach ($contexts as $key => $value) {
if ($value === 'user.permissions') {
$contexts[$key] = 'user';
$update = TRUE;
break;
}
}
if ($update) {
$config->set('display.user.cache_metadata.contexts', $contexts)->save();
}
}
}
/**
* Truncate table {cache_data} to allow v (Frequent) location trigger value.
*/
function owntracks_update_8003() {
\Drupal::database()->query('TRUNCATE table {cache_data}');
}
/**
* Update owntracks_location view.
*/
function owntracks_update_8004() {
$file = implode(DIRECTORY_SEPARATOR, [
drupal_get_path('module', 'owntracks'),
'config',
'optional',
'views.view.owntracks_location.yml',
]);
$data = Yaml::parse(file_get_contents($file));
\Drupal::configFactory()->getEditable('views.view.owntracks_location')
->setData($data)
->save();
}
/**
* Update owntracks entity types definitions.
*/
function owntracks_update_8005() {
$entity_type_manager = \Drupal::entityTypeManager();
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$owntracks_location = $entity_type_manager->getDefinition('owntracks_location');
$entity_definition_update_manager->updateEntityType($owntracks_location);
$owntracks_transition = $entity_type_manager->getDefinition('owntracks_transition');
$entity_definition_update_manager->updateEntityType($owntracks_transition);
$owntracks_waypoint = $entity_type_manager->getDefinition('owntracks_waypoint');
$entity_definition_update_manager->updateEntityType($owntracks_waypoint);
}
/**
* Update owntracks entity field definitions.
*/
function owntracks_update_8006() {
// Update has to be performed a second time to add indexes.
owntracks_update_8005();
}
/**
* Reinstall owntracks views.
*/
function owntracks_update_8007() {
$views = [
'views.view.owntracks_location',
'views.view.owntracks_transition',
'views.view.owntracks_waypoint',
];
foreach ($views as $view) {
\Drupal::configFactory()->getEditable($view)->delete();
}
\Drupal::service('config.installer')
->installdefaultConfig('module', 'owntracks');
}
/**
* Remove _type fields.
*/
function owntracks_update_8008() {
$entity_type_ids = [
'owntracks_location',
'owntracks_transition',
'owntracks_waypoint',
];
$manager = \Drupal::entityDefinitionUpdateManager();
$database = \Drupal::database();
foreach ($entity_type_ids as $entity_type_id) {
$database->update($entity_type_id)
->fields(['_type' => NULL])
->execute();
$field = $manager->getFieldStorageDefinition('_type', $entity_type_id);
$manager->uninstallFieldStorageDefinition($field);
}
}
/**
* Allow NULL on optional fields.
*/
function owntracks_update_8009() {
$spec = [
'fields' => [
'uid' => [
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
],
'tid' => [
'type' => 'varchar',
'not null' => FALSE,
'length' => 255,
],
'acc' => [
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
],
'rad' => [
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
],
'description' => [
'type' => 'varchar',
'not null' => FALSE,
'length' => 255,
],
],
];
$schema = \Drupal::database()->schema();
$schema->dropIndex('owntracks_location', 'owntracks_location_field__acc');
$schema->changeField('owntracks_location', 'acc', 'acc', $spec['fields']['acc']);
$schema->addIndex('owntracks_location', 'owntracks_location_field__acc', ['acc'], $spec);
$schema->dropIndex('owntracks_location', 'owntracks_location_field__tid');
$schema->dropIndex('owntracks_location', 'owntracks_location__uid_tid');
$schema->changeField('owntracks_location', 'tid', 'tid', $spec['fields']['tid']);
$schema->addIndex('owntracks_location', 'owntracks_location_field__tid', ['tid'], $spec);
$schema->addIndex('owntracks_location', 'owntracks_location__uid_tid', ['uid', 'tid'], $spec);
$schema->dropIndex('owntracks_transition', 'owntracks_transition_field__tid');
$schema->dropIndex('owntracks_transition', 'owntracks_transition__uid_tid');
$schema->changeField('owntracks_transition', 'tid', 'tid', $spec['fields']['tid']);
$schema->addIndex('owntracks_transition', 'owntracks_transition_field__tid', ['tid'], $spec);
$schema->addIndex('owntracks_transition', 'owntracks_transition__uid_tid', ['uid', 'tid'], $spec);
$schema->dropIndex('owntracks_waypoint', 'owntracks_waypoint_field__rad');
$schema->changeField('owntracks_waypoint', 'rad', 'rad', $spec['fields']['rad']);
$schema->addIndex('owntracks_waypoint', 'owntracks_waypoint_field__rad', ['rad'], $spec);
$schema->dropIndex('owntracks_waypoint', 'owntracks_waypoint_field__description');
$schema->changeField('owntracks_waypoint', 'description', 'description', $spec['fields']['description']);
$schema->addIndex('owntracks_waypoint', 'owntracks_waypoint_field__description', ['description'], $spec);
}
/**
* Set field description mandatory on owntracks_waypoint entities.
*/
function owntracks_update_8010() {
$spec = [
'fields' => [
'description' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => 255,
],
],
];
$schema = \Drupal::database()->schema();
$schema->dropIndex('owntracks_waypoint', 'owntracks_waypoint_field__description');
$schema->changeField('owntracks_waypoint', 'description', 'description', $spec['fields']['description']);
$schema->addIndex('owntracks_waypoint', 'owntracks_waypoint_field__description', ['description'], $spec);
}
/**
* Flush caches to allow l (Location) transition trigger value.
*/
function owntracks_update_8011() {
drupal_flush_all_caches();
}