5 * Handles Advanced Aggregation installation and upgrade tasks.
11 * Implements hook_install().
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');
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');
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']);
30 if (isset($stat_js['uid']) && $stat_public['uid'] != $stat_js['uid']) {
31 @chown($stat_js[0], $stat_public['uid']);
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']);
38 if (isset($stat_js['uid']) && $stat_public['gid'] != $stat_js['gid']) {
39 @chgrp($stat_js[0], $stat_public['gid']);
46 * Implements hook_uninstall().
48 function advagg_uninstall() {
49 \Drupal::service('state.advagg.files')->deleteAll();
53 * Implements hook_requirements().
55 function advagg_requirements($phase) {
58 // Ensure translations don't break at install time.
61 // Always check these, independent of the current phase.
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,
80 // If not at runtime, return here.
81 if ($phase !== 'runtime') {
84 $config = \Drupal::config('advagg.settings');
85 $system_config = \Drupal::config('system.performance');
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()]),
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()]),
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()]);
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()]);
116 if ($config->get('cache_level') < 0) {
117 $description .= ' ' . $t('Currently running in development mode.');
120 $requirements['advagg_ok'] = [
121 'title' => $t('Adv CSS/JS Agg'),
122 'severity' => REQUIREMENT_OK,
124 'description' => $t('Advanced CSS/JS Aggregator should be working correctly.') . ' ' . $description,
127 return $requirements;
131 * Implements hook_update_N().
133 * Updates all the stored file information.
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);
144 * Implements hook_update_N().
146 * Remove unused configuration keys.
148 function advagg_update_8202() {
149 \Drupal::configFactory()->getEditable('advagg.settings')
151 ->clear('advagg_clear_scripts')
156 * Implements hook_update_N().
158 * Remove depracated configuration.
160 function advagg_update_8203() {
161 \Drupal::configFactory()->getEditable('advagg.settings')
162 ->clear('path.convert.absolute_to_relative')