-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos2web_meetings.install
219 lines (186 loc) · 9.29 KB
/
os2web_meetings.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
<?php
/**
* @file
* Install, uninstall and update hooks for page builder module.
*/
use Drupal\Core\Config\FileStorage;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\os2web_meetings\Form\SettingsForm;
use Symfony\Component\Yaml\Yaml;
use Drupal\field\Entity\FieldConfig;
function os2web_meetings_read_in_new_config($config_name) {
$path = drupal_get_path('module', 'os2web_meetings');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
$active_storage->write($config_name, Yaml::parse(file_get_contents($path . '/config/install/' . $config_name . '.yml')));
}
/**
* Make Start date field required.
*/
function os2web_meetings_update_8001() {
os2web_meetings_read_in_new_config('field.field.node.os2web_meetings_meeting.field_os2web_m_start_date');
}
/**
* Updates Meeting node. Added Participants fields.
*/
function os2web_meetings_update_8002() {
$path = drupal_get_path('module', 'os2web_meetings');
// Create field storage.
$field_media_image_storage_yml = Yaml::parse(file_get_contents($path . '/config/optional/field.storage.node.field_os2web_m_partic.yml'));
if (!FieldStorageConfig::loadByName($field_media_image_storage_yml['entity_type'], $field_media_image_storage_yml['field_name'])) {
FieldStorageConfig::create($field_media_image_storage_yml)->save();
}
// Create field instance.
$field_media_image_yml = Yaml::parse(file_get_contents($path . '/config/optional/field.field.node.os2web_meetings_meeting.field_os2web_m_partic.yml'));
if (!FieldConfig::loadByName($field_media_image_yml['entity_type'], $field_media_image_yml['bundle'], $field_media_image_yml['field_name'])) {
FieldConfig::create($field_media_image_yml)->save();
}
// Create field storage.
$field_media_image_storage_yml = Yaml::parse(file_get_contents($path . '/config/optional/field.storage.node.field_os2web_m_partic_cancel.yml'));
if (!FieldStorageConfig::loadByName($field_media_image_storage_yml['entity_type'], $field_media_image_storage_yml['field_name'])) {
FieldStorageConfig::create($field_media_image_storage_yml)->save();
}
// Create field instance.
$field_media_image_yml = Yaml::parse(file_get_contents($path . '/config/optional/field.field.node.os2web_meetings_meeting.field_os2web_m_partic_cancel.yml'));
if (!FieldConfig::loadByName($field_media_image_yml['entity_type'], $field_media_image_yml['bundle'], $field_media_image_yml['field_name'])) {
FieldConfig::create($field_media_image_yml)->save();
}
}
/**
* Add meeting document view.
*/
function os2web_meetings_update_8003() {
$path = drupal_get_path('module', 'os2web_meetings');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
$active_storage->write('views.view.os2web_meetings_meeting_document', Yaml::parse(file_get_contents($path . '/config/optional/views.view.os2web_meetings_meeting_document.yml')));
}
/**
* Updating paragraph os2web_meetings_search.
*/
function os2web_meetings_update_8004() {
$path = drupal_get_path('module', 'os2web_meetings');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
// Updating view.
$active_storage->write('views.view.os2web_meetings_search', Yaml::parse(file_get_contents($path . '/config/optional/views.view.os2web_meetings_search.yml')));
$module_handler = \Drupal::moduleHandler();
$config_storage = new FileStorage($module_handler->getModule('os2web_meetings')->getPath() . '/config/optional');
// Create field storage and field storage.
foreach (['field.storage.paragraph.field_os2web_meetings_sp_view', 'field.field.paragraph.os2web_meetings_search.field_os2web_meetings_sp_view'] as $config_name) {
$config_record = $config_storage->read($config_name);
$entity_type = \Drupal::service('config.manager')->getEntityTypeIdByName($config_name);
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
$storage = \Drupal::entityTypeManager()->getStorage($entity_type);
$entity = $storage->createFromStorageRecord($config_record);
$entity->save();
}
// Updating view and form displays.
$active_storage->write('core.entity_view_display.paragraph.os2web_meetings_search.default', Yaml::parse(file_get_contents($path . '/config/optional/core.entity_view_display.paragraph.os2web_meetings_search.default.yml')));
$active_storage->write('core.entity_form_display.paragraph.os2web_meetings_search.default', Yaml::parse(file_get_contents($path . '/config/optional/core.entity_form_display.paragraph.os2web_meetings_search.default.yml')));
}
/**
* Creating paragraph os2web_meetings.
*/
function os2web_meetings_update_8005() {
$path = drupal_get_path('module', 'os2web_meetings');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
//Creating paragraph.
$active_storage->write('paragraphs.paragraphs_type.os2web_meetings', Yaml::parse(file_get_contents($path . '/config/optional/paragraphs.paragraphs_type.os2web_meetings.yml')));
// Updating view.
$active_storage->write('views.view.os2web_meetings', Yaml::parse(file_get_contents($path . '/config/optional/views.view.os2web_meetings.yml')));
$module_handler = \Drupal::moduleHandler();
$config_storage = new FileStorage($module_handler->getModule('os2web_meetings')->getPath() . '/config/optional');
// Create field storage and field storage.
foreach (['field.storage.paragraph.field_os2web_meetings_par_view', 'field.field.paragraph.os2web_meetings.field_os2web_meetings_par_view'] as $config_name) {
$config_record = $config_storage->read($config_name);
$entity_type = \Drupal::service('config.manager')->getEntityTypeIdByName($config_name);
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
$storage = \Drupal::entityTypeManager()->getStorage($entity_type);
$entity = $storage->createFromStorageRecord($config_record);
$entity->save();
}
// Updating view and form displays.
$active_storage->write('core.entity_view_display.paragraph.os2web_meetings.default', Yaml::parse(file_get_contents($path . '/config/optional/core.entity_view_display.paragraph.os2web_meetings.default.yml')));
$active_storage->write('core.entity_form_display.paragraph.os2web_meetings.default', Yaml::parse(file_get_contents($path . '/config/optional/core.entity_form_display.paragraph.os2web_meetings.default.yml')));
}
/**
* Add new date format.
*/
function os2web_meetings_update_8006() {
$path = drupal_get_path('module', 'os2web_meetings');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
$active_storage->write('core.date_format.os2_month', Yaml::parse(file_get_contents($path . '/config/optional/core.date_format.os2_month.yml')));
}
/**
* Setting dot after BP number by default.
*
* Renaming config value.
*/
function os2web_meetings_update_8007() {
$config = \Drupal::service('config.factory')->getEditable(SettingsForm::$configName);
// Renaming config value.
$config->set('text_before_bp_number', $config->get('text_before_bpa_number'));
// Setting default to true.
$config->set('dot_after_bp_number', TRUE);
$config->save();
}
/**
* Updating views os2web_meetings_search.
*/
function os2web_meetings_update_8008() {
$path = drupal_get_path('module', 'os2web_meetings');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
// Updating view.
$active_storage->write('views.view.os2web_meetings_search', Yaml::parse(file_get_contents($path . '/config/optional/views.view.os2web_meetings_search.yml')));
}
/**
* Make sure that imported pdf files did get .pdf extension.
*/
function os2web_meetings_update_8009() {
$field_name = 'field_os2web_m_doc';
$bundle = 'os2web_meetings_meeting';
$connection = \Drupal::database();
$result_m = $connection->select('node__' . $field_name, 'f')
->fields('f', array($field_name . '_target_id'))
->distinct(TRUE)
->condition('bundle', $bundle)
->execute()->fetchCol();
$field_name = 'field_os2web_m_bp_enclosures';
$bundle = 'os2web_meetings_bp';
$connection = \Drupal::database();
$result_bp = $connection->select('node__' . $field_name, 'f')
->fields('f', array($field_name . '_target_id'))
->distinct(TRUE)
->condition('bundle', $bundle)
->execute()->fetchCol();
$field_name = 'field_os2web_m_bpa_file';
$bundle = 'os2web_meetings_bpa';
$connection = \Drupal::database();
$result_bpa = $connection->select('node__' . $field_name, 'f')
->fields('f', array($field_name . '_target_id'))
->distinct(TRUE)
->condition('bundle', $bundle)
->execute()->fetchCol();
$result = array_merge($result_m, $result_bp, $result_bpa);
$messenger = \Drupal::messenger();
$counter = 0;
foreach ($result as $id) {
$file = \Drupal\file\Entity\File::load($id);
$filename = $file->getFilename();
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if ($ext != 'pdf' && $file->getMimeType() == 'application/pdf') {
$new_filename = $filename .'.pdf';
$file->setFilename($new_filename);
$file->save();
$counter++;
}
}
$messenger->addStatus(sprintf(
'%s files has been updated with correct extension',
$counter
));
}