Further modules included.
[yaffs-website] / web / modules / contrib / advagg / advagg.install
1 <?php
2
3 /**
4  * @file
5  * Handles Advanced Aggregation installation and upgrade tasks.
6  */
7
8 use Drupal\Core\Url;
9
10 /**
11  * Implements hook_install().
12  */
13 function advagg_install() {
14   // Make sure permissions for dirs are correct. Needed if installed via drush.
15   $stat_public = stat('public://');
16   // Check if this folder already exists - could be the case on re-install.
17   if (!file_exists('public://css')) {
18     \Drupal::service('file_system')->mkdir('public://css');
19   }
20   $stat_css = stat('public://css');
21   // Check if this folder already exists - could be the case on re-install.
22   if (!file_exists('public://js')) {
23     \Drupal::service('file_system')->mkdir('public://js');
24   }
25   $stat_js = stat('public://js');
26   if (isset($stat_public['uid'])) {
27     if (isset($stat_css['uid']) && $stat_public['uid'] != $stat_css['uid']) {
28       @chown($stat_css[0], $stat_public['uid']);
29     }
30     if (isset($stat_js['uid']) && $stat_public['uid'] != $stat_js['uid']) {
31       @chown($stat_js[0], $stat_public['uid']);
32     }
33   }
34   if (isset($stat_public['gid'])) {
35     if (isset($stat_css['gid']) && $stat_public['gid'] != $stat_css['gid']) {
36       @chgrp($stat_css[0], $stat_public['gid']);
37     }
38     if (isset($stat_js['uid']) && $stat_public['gid'] != $stat_js['gid']) {
39       @chgrp($stat_js[0], $stat_public['gid']);
40     }
41   }
42
43 }
44
45 /**
46  * Implements hook_uninstall().
47  */
48 function advagg_uninstall() {
49   \Drupal::service('state.advagg.files')->deleteAll();
50 }
51
52 /**
53  * Implements hook_requirements().
54  */
55 function advagg_requirements($phase) {
56   $requirements = [];
57
58   // Ensure translations don't break at install time.
59   $t = 't';
60
61   // Always check these, independent of the current phase.
62   $function_list = [
63     'rename',
64   ];
65   // Check each function to make sure it exists.
66   foreach ($function_list as $function_name) {
67     if (!function_exists($function_name)) {
68       $requirements['advagg_function_' . $function_name] = [
69         'title' => $t('Adv CSS/JS Agg - Function Disabled'),
70         'value' => $phase === 'install' ? FALSE : $function_name,
71         'severity' => REQUIREMENT_ERROR,
72         'description' => $t('<a href="!url">%name()</a> is disabled on this server. Please contact your hosting provider or server administrator and see if they can re-enable this function for you.', [
73           '!url' => 'http://php.net/' . str_replace('_', '-', $function_name),
74           '%name' => $function_name,
75         ]),
76       ];
77     }
78   }
79
80   // If not at runtime, return here.
81   if ($phase !== 'runtime') {
82     return $requirements;
83   }
84   $config = \Drupal::config('advagg.settings');
85   $system_config = \Drupal::config('system.performance');
86
87   if (!$config->get('skip_enabled_preprocess_check')) {
88     // Make sure variables are set correctly.
89     if (!$config->get('enabled')) {
90       $requirements['advagg_not_on'] = [
91         'title' => $t('Adv CSS/JS Agg - Enabled'),
92         'severity' => REQUIREMENT_WARNING,
93         'value' => $t('Advanced CSS/JS aggregation is disabled.'),
94         'description' => $t('Go to the Advanced CSS/JS aggregation <a href="@settings">settings page</a> and enable it.', ['@settings' => Url::fromRoute('advagg.settings')->toString()]),
95       ];
96     }
97     if (!$system_config->get('css.preprocess') || !$system_config->get('js.preprocess')) {
98       $requirements['advagg_core_off'] = [
99         'title' => $t('Adv CSS/JS Agg - Core Variables'),
100         'severity' => REQUIREMENT_ERROR,
101         'value' => $t('Cores CSS and/or JS aggregation is disabled.'),
102         'description' => $t('"Aggregate CSS files" and "Aggregate JavaScript files" on the <a href="@performance">performance page</a> should be enabled.', ['@performance' => Url::fromRoute('system.performance_settings')->toString()]),
103       ];
104     }
105   }
106
107   $description = '';
108
109   if (!$config->get('enabled')) {
110     $description .= ' ' . $t('Advanced CSS/JS aggregation is disabled. Go to the Advanced CSS/JS aggregation <a href="@settings">settings page</a> and enable it.', ['@settings' => Url::fromRoute('advagg.settings')->toString()]);
111   }
112   if (!$system_config->get('css.preprocess') || !$system_config->get('js.preprocess')) {
113     $description .= ' ' . $t('Cores CSS and/or JS aggregation is disabled. "Aggregate CSS files" and "Aggregate JavaScript files" on the <a href="@performance">performance page</a> should be enabled.', ['@performance' => Url::fromRoute('system.performance_settings')->toString()]);
114   }
115
116   if ($config->get('cache_level') < 0) {
117     $description .= ' ' . $t('Currently running in development mode.');
118   }
119
120   $requirements['advagg_ok'] = [
121     'title' => $t('Adv CSS/JS Agg'),
122     'severity' => REQUIREMENT_OK,
123     'value' => $t('OK'),
124     'description' => $t('Advanced CSS/JS Aggregator should be working correctly.') . ' ' . $description,
125   ];
126
127   return $requirements;
128 }
129
130 /**
131  * Implements hook_update_N().
132  *
133  * Updates all the stored file information.
134  */
135 function advagg_update_8201() {
136   $advagg_files = \Drupal::service('state.advagg.files');
137   $files = $advagg_files->getAll();
138   foreach ($files as $file => $cached) {
139     $advagg_files->scanFile($file, $cached);
140   }
141 }
142
143 /**
144  * Implements hook_update_N().
145  *
146  * Remove unused configuration keys.
147  */
148 function advagg_update_8202() {
149   \Drupal::configFactory()->getEditable('advagg.settings')
150     ->clear('separator')
151     ->clear('advagg_clear_scripts')
152     ->save();
153 }
154
155 /**
156  * Implements hook_update_N().
157  *
158  * Remove depracated configuration.
159  */
160 function advagg_update_8203() {
161   \Drupal::configFactory()->getEditable('advagg.settings')
162     ->clear('path.convert.absolute_to_relative')
163     ->save();
164 }