forked from ymcatwincities/openy_activity_finder
-
Notifications
You must be signed in to change notification settings - Fork 14
/
openy_activity_finder.install
295 lines (269 loc) · 9.14 KB
/
openy_activity_finder.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
/**
* @file
* Contains install and update routines.
*/
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Implements hook_install().
*/
function openy_activity_finder_install() {
// Add permissions to anonymous and authenticated roles.
$permissions = [
'restful get openy_activity_finder_session_data',
];
$roles = Role::loadMultiple([
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,
]);
foreach ($roles as $role) {
foreach ($permissions as $permission) {
$role->grantPermission($permission);
}
$role->save();
}
}
/**
* Implements hook_update_dependencies().
*/
function openy_activity_finder_update_dependencies() {
$dependencies['openy_activity_finder'] = [
8006 => [
'search_api_solr' => 8332,
],
];
return $dependencies;
}
/**
* Update configs.
*/
function openy_activity_finder_update_8001() {
$openy_activity_finder_dir = \Drupal::service('extension.list.module')->getPath('openy_activity_finder');
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory($openy_activity_finder_dir . '/config/install');
$cim->importConfigs(['openy_activity_finder.settings']);
$cim->setDirectory($openy_activity_finder_dir . '/config/optional');
$config = \Drupal::config('search_api.index.default');
if (!$config->isNew()) {
// Import config only in case it already exist.
$cim->importConfigs(['search_api.index.default']);
}
}
/**
* Update configs.
*/
function openy_activity_finder_update_8002() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/optional');
$config = \Drupal::config('search_api.index.default');
if (!$config->isNew()) {
// Import config only in case it already exist.
$cim->importConfigs(['search_api.index.default']);
}
}
/**
* Update configs.
*/
function openy_activity_finder_update_8003() {
\Drupal::service('module_installer')->install(['openy']);
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/install');
$cim->importConfigs(['openy_activity_finder.settings']);
}
/**
* Update Activity Finder configs.
*/
function openy_activity_finder_update_8004(&$sandbox) {
\Drupal::configFactory()
->getEditable('openy_activity_finder.settings')
->set('index', 'default')
->save();
}
/**
* Update configs.
*/
function openy_activity_finder_update_8005() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/optional');
$config = \Drupal::config('search_api.index.default');
if (!$config->isNew()) {
// Import config only in case it already exist.
$cim->importConfigs(['search_api.index.default']);
}
}
/**
* Enable Search API Solr legacy if needed.
*/
function openy_activity_finder_update_8006() {
$messages = [];
if (openy_enable_search_api_solr_legacy()) {
$messages[] = '***';
$messages[] = '*** You are using a legacy version of Apache Solr. Enabling the Search API Solr Legacy module. ***';
$messages[] = '***';
$messages[] = '';
}
$messages[] = '* MAJOR SOLR SEARCH MODULE UPGRADE (1.x to 4.x).';
$messages[] = '*';
$messages[] = '* Download the updated Apache Solr configuration form the Search API module <a href="/admin/config/search/search-api">configuration page</a>.';
$messages[] = '** On the page, find each individual Search server, click its name and download the config.zip using "Get config.zip" button.';
$messages[] = '** Alternatively, use `drush solr-gsc YOUR_SEARCH_API_SERVER_ID` command.';
$messages[] = '** Alternatively, use a jump-start configuration from https://git.drupalcode.org/project/search_api_solr/-/tree/4.x/jump-start';
$messages[] = '* Apply the new Solr configuration. Ask your server administrator or a hosting support for assistance.';
$messages[] = '* Reindex the associated Search API indexes.';
$messages[] = '*';
$messages[] = '* For more details see https://www.drupal.org/docs/8/modules/search-api-solr/search-api-solr-howtos/migrate-from-8x-1x-to-4x';
$messages[] = '*';
$messenger = \Drupal::messenger();
foreach ($messages as $message) {
$messenger->addMessage($message, 'warning');
if (function_exists('drush_print')) {
drush_print($message);
}
}
}
/**
* Update Activity Finder configs.
*/
function openy_activity_finder_update_8007(&$sandbox) {
$config = \Drupal::configFactory()->getEditable('openy_activity_finder.settings');
if ($config && empty($config->get('weeks'))) {
$config->set('weeks', '');
$config->save();
}
}
/**
* Update configs for af4.
*/
function openy_activity_finder_update_8008() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/optional');
$config = \Drupal::config('search_api.index.default');
if (!$config->isNew()) {
// Import config only in case it already exist.
$cim->importConfigs(['search_api.index.default']);
}
}
/**
* Update configs for af4.
*/
function openy_activity_finder_update_8009() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/optional');
$config = \Drupal::config('search_api.index.default');
if (!$config->isNew()) {
// Import config only in case it already exist.
$cim->importConfigs(['search_api.index.default']);
}
}
/**
* Add Session Data rest endpoint config and permissions.
*/
function openy_activity_finder_update_8400() {
// Import config for rest endpoint.
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/install');
$cim->importConfigs(['rest.resource.openy_activity_finder_session_data']);
// Add permissions to anonymous and authenticated roles.
$permissions = [
'restful get openy_activity_finder_session_data',
];
$roles = Role::loadMultiple([
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,
]);
foreach ($roles as $role) {
foreach ($permissions as $permission) {
$role->grantPermission($permission);
}
$role->save();
}
}
/**
* Update configs for search index.
*/
function openy_activity_finder_update_8401() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/optional');
$config = \Drupal::config('search_api.index.default');
if (!$config->isNew()) {
// Import config only in case it already exists.
$cim->importConfigs(['search_api.index.default']);
}
}
/**
* Update Bootstrap version in Activity Finder configs.
*/
function openy_activity_finder_update_8402() {
\Drupal::configFactory()
->getEditable('openy_activity_finder.settings')
->set('bs_version', 3)
->save();
}
/**
* Update configs for search index.
*/
function openy_activity_finder_update_8403() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/optional');
$config = \Drupal::config('search_api.index.default');
if (!$config->isNew()) {
// Import config only in case it already exists.
$cim->importConfigs(['search_api.index.default']);
}
}
/**
* Update configs for search index.
*/
function openy_activity_finder_update_8404() {
_af_config_import();
}
/**
* Update configs for search index. Configs should be sent in an array where the
* key is the directory and the value is an array of config files.
*/
function _af_config_import($import = ['optional' => ['search_api.index.default']]) {
$cim = \Drupal::service('config_import.importer');
// Loop through keys as directories...
foreach ($import as $dir => $configs) {
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/' . $dir);
// Now process each config to be imported.
foreach ($configs as $name) {
$config = \Drupal::config($name);
if (!$config->isNew()) {
// Import config only in the case that it already exists.
$cim->importConfigs([$name]);
}
}
}
}
/**
* Update config.
*/
function openy_activity_finder_update_8405() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/install');
$config = \Drupal::config('openy_activity_finder.settings');
if (!$config->isNew()) {
// Import config only in case it already exists.
$cim->importConfigs(['openy_activity_finder.settings']);
}
}
/**
* Update configs for search index.
*/
function openy_activity_finder_update_9001() {
_af_config_import();
}
/**
* Update config.
*/
function openy_activity_finder_update_9002() {
openy_activity_finder_update_8405();
}
/**
* Update config.
*/
function openy_activity_finder_update_9004() {
_af_config_import();
}