-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphicsmagick.install
131 lines (117 loc) · 5.89 KB
/
graphicsmagick.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
<?php
/**
* @file
* Install, update, and uninstall hooks for the GraphicsMagick module.
*/
declare(strict_types=1);
/**
* Implements hook_requirements().
*/
function graphicsmagick_requirements($phase): array {
$requirements = array();
// Ensure translations don't break during installation.
$t = get_t();
if (extension_loaded('gmagick') && class_exists('Gmagick')) {
try {
$version_array = (new Gmagick)->getVersion();
$version = $version_array['versionString'] ?? ($version_array['versionNumber'] ?? NULL);
$requirements['graphicsmagick_extension']['severity'] = REQUIREMENT_OK;
$requirements['graphicsmagick_extension']['value'] = (isset($version) ? $t('Version: %version', ['%version' => $version]) : $t('Version: unknown'));
$requirements['graphicsmagick_extension']['description'] = $t(
'The <a href="@gmagick_link">Gmagick</a> extension has been enabled and loaded.',
array('@gmagick_link' => 'https://www.php.net/manual/en/book.gmagick.php')
);
}
catch (\GmagickException|\Error) {
$requirements['graphicsmagick_extension']['severity'] = REQUIREMENT_ERROR;
$requirements['graphicsmagick_extension']['value'] = $t('Version: unknown');
$requirements['graphicsmagick_extension']['description'] = $t(
'The <a href="@gmagick_link">Gmagick</a> extension has been loaded, but there has been an error when using the class it implements.',
['@gmagick_link' => 'https://www.php.net/manual/en/book.gmagick.php']
);
return $requirements;
}
try {
$handler = new \Gmagick();
// Verify the undocumented methods used by the toolkit are implemented.
$missing_methods = FALSE;
$missing_methods |= !method_exists($handler, 'getNumberImages');
$missing_methods |= !method_exists($handler, 'coalesceImages');
$missing_methods |= !method_exists($handler, 'deconstructImages');
if ($missing_methods) {
$requirements['graphicsmagick_extension']['severity'] = REQUIREMENT_ERROR;
$requirements['graphicsmagick_extension']['description'] = $t(
'The <a href="@gmagick_link">Gmagick</a> extension has been loaded, but the <code>Gmagick</code> class it implements does not have the methods necessary to the gmagick toolkit.',
['@gmagick_link' => 'https://www.php.net/manual/en/book.gmagick.php']
);
}
}
catch (\GmagickException|\Error) {
$requirements['graphicsmagick_extension']['severity'] = REQUIREMENT_ERROR;
$requirements['graphicsmagick_extension']['description'] = $t(
'The <a href="@gmagick_link">Gmagick</a> extension has been loaded, but there has been an error when using the class it implements.',
['@gmagick_link' => 'https://www.php.net/manual/en/book.gmagick.php']
);
}
}
else {
if (!extension_loaded('gmagick')) {
$requirements['graphicsmagick_extension']['severity'] = REQUIREMENT_ERROR;
$requirements['graphicsmagick_extension']['value'] = $t('Not found');
$requirements['graphicsmagick_extension']['description'] = $t(
'The <a href="@gmagick_link">Gmagick</a> extension is required by the GraphicsMagick module. See the <a href="@gmagick_installation">installation</a> page for more information.',
[
'@gmagick_link' => 'https://www.php.net/manual/en/book.gmagick.php',
'@gmagick_installation' => 'https://www.php.net/manual/en/gmagick.installation.php',
]
);
}
elseif (!class_exists('Gmagick')) {
// In the case the Gmagick extension has been loaded, but the Gmagick
// class has not found, give a more specific error that explains that.
$requirements['graphicsmagick_extension']['severity'] = REQUIREMENT_ERROR;
$requirements['graphicsmagick_extension']['value'] = $t('Not found');
$requirements['graphicsmagick_extension']['description'] = $t(
'The <a href="@gmagick_link">Gmagick</a> extension has been loaded, but the <code>Gmagick</code> class it should define has not been found.',
[
'@gmagick_link' => 'https://www.php.net/manual/en/book.gmagick.php',
]
);
}
}
if ($phase == 'runtime' && module_exists('graphicsmagick_effects')) {
// Give a warning if the GraphicsMagick Effects module is installed.
$path = backdrop_get_path('module', 'graphicsmagick_effects');
$requirements['graphicsmagick_effects']['title'] = $t('GraphicMagick Effects');
$requirements['graphicsmagick_effects']['severity'] = REQUIREMENT_WARNING;
$requirements['graphicsmagick_effects']['value'] = $t('Installed');
$requirements['graphicsmagick_effects']['description'] = $t(
'The contributed <em>GraphicsMagick Effects</em> module located at %path is no longer necessary, since its functionality is now provided by the <em>GraphicsMagick</em> module. It is recommended to !operation the <em>GraphicsMagick Effects</em> module from your site.',
array('!operation' => t('uninstall'), '%path' => BACKDROP_ROOT . "/$path")
);
}
return $requirements;
}
/**
* Uninstall the GraphicsMagick Effects module.
*/
function graphicsmagick_update_1101(): void {
if (module_exists('graphicsmagick_effects')) {
$path = backdrop_get_path('module', 'graphicsmagick_effects');
backdrop_uninstall_modules(array('graphicsmagick_effects'));
backdrop_set_message(
t(
'The contributed <em>GraphicsMagick Effects</em> module located at %path is no longer necessary, since its functionality is now provided by the <em>GraphicsMagick</em> module. It is recommended to !operation the <em>GraphicsMagick Effects</em> module from your site.',
array('!operation' => t('remove'), '%path' => BACKDROP_ROOT . "/$path")
),
'warning'
);
}
}
/**
* Clear the image effect definitions cache.
*/
function graphicsmagick_update_1102(): void {
backdrop_static_reset('image_effect_definitions');
cache()->deletePrefix('image_effect_definitions:');
}