forked from drupal-media/media_entity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_entity.install
115 lines (103 loc) · 3.41 KB
/
media_entity.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
<?php
/**
* @file
* Install, uninstall and update hooks for Media entity module.
*/
/**
* Checks if required version of the Entity API is installed.
*
* @return bool
* TRUE if dependency is met and FALSE if not.
*/
function _media_entity_check_entity_version() {
if (\Drupal::moduleHandler()->moduleExists('entity')) {
$info = system_get_info('module', 'entity');
if (version_compare($info['version'], '8.x-1.0-alpha3') >= 0) {
return TRUE;
}
}
return FALSE;
}
/**
* Implements hook_requirements().
*/
function media_entity_requirements($phase) {
$requirements = [];
if ($phase == 'update' && !_media_entity_check_entity_version()) {
$requirements['entity'] = [
'title' => t('Media entity'),
'value' => t('Entity API missing'),
'description' => t(
'<a href=":url">Entity API >= 8.x-1.0-alpha3</a> module is now a dependency and needs to be installed before running updates.',
[':url' => 'https://www.drupal.org/project/entity']
),
'severity' => REQUIREMENT_ERROR,
];
}
if ($phase == 'install' && \Drupal::moduleHandler()->moduleExists('media')) {
$version = explode('.', \Drupal::VERSION);
if ($version[1] >= 4) {
$requirements['media_module_incompatibility'] = [
'title' => t('Media Entity'),
'value' => t('The Media Entity module is not compatible with media in core.'),
'description' => t('The 1.x branch of Media Entity cannot be used in conjunction with the media module in core. Please check the 2.x branch for an upgrade path.'),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}
/**
* Implements hook_install().
*/
function media_entity_install() {
$source = drupal_get_path('module', 'media_entity') . '/images/icons';
$destination = \Drupal::config('media_entity.settings')->get('icon_base');
media_entity_copy_icons($source, $destination);
}
/**
* Remove "type" base field.
*/
function media_entity_update_8001() {
$fields = \Drupal::database()->query('DESCRIBE {media_field_data}')->fetchCol();
if (in_array('type', $fields)) {
\Drupal::database()->update('media_field_data')
->fields(['type' => NULL])
->execute();
}
$manager = \Drupal::entityDefinitionUpdateManager();
if ($field = $manager->getFieldStorageDefinition('type', 'media')) {
$manager->uninstallFieldStorageDefinition($field);
}
}
/**
* Ensure media entity status value (defaulting to 1).
*/
function media_entity_update_8002() {
// Ensure status values in 'media_field_data' table.
if (\Drupal::database()->schema()->tableExists('media_field_data')) {
\Drupal::database()
->update('media_field_data')
->fields(['status' => 1])
->condition('status', NULL, 'IS NULL')
->execute();
}
// Ensure status values in 'media_field_revision' table.
if (\Drupal::database()->schema()->tableExists('media_field_revision')) {
\Drupal::database()
->update('media_field_revision')
->fields(['status' => 1])
->condition('status', NULL, 'IS NULL')
->execute();
}
// Flush all caches.
drupal_flush_all_caches();
}
/**
* Ensure Entity API is installed.
*/
function media_entity_update_8003() {
if (!_media_entity_check_entity_version()) {
throw new \Drupal\Core\Utility\UpdateException('Entity API >= 8.x-1.0-alpha3 (drupal.org/project/entity) module is now a dependency and needs to be installed before running updates.');
}
}