acquia_purge.install in Acquia Purge 7
Same filename and directory in other branches
Installation file for the Acquia Purge module.
File
acquia_purge.installView source
<?php
/**
* @file
* Installation file for the Acquia Purge module.
*/
/**
* Implements hook_install().
*/
function acquia_purge_install() {
// Enable Expire 7.x-2.x's most important expiration rules by default.
$defaults = array(
'expire_status' => EXPIRE_STATUS_ENABLED_EXTERNAL,
'expire_debug' => EXPIRE_DEBUG_DISABLED,
'expire_include_base_url' => FALSE,
'expire_node_actions' => array(
1,
2,
3,
),
'expire_node_front_page' => 1,
'expire_node_term_pages' => 1,
'expire_comment_actions' => array(
1,
2,
3,
4,
5,
),
'expire_comment_front_page' => 1,
'expire_comment_node_term_pages' => 1,
'expire_user_actions' => array(
1,
2,
3,
4,
),
'expire_user_front_page' => 1,
'expire_file_actions' => array(
1,
2,
),
'expire_file_front_page' => 1,
);
foreach ($defaults as $variable => $values) {
$value = is_array($values) ? array() : $values;
if (is_array($values)) {
foreach ($values as $int) {
$value[(string) $int] = (string) $int;
}
}
variable_set($variable, $value);
}
}
/**
* Implements hook_uninstall().
*/
function acquia_purge_uninstall() {
drupal_load('module', 'acquia_purge');
_acquia_purge_service()
->clear();
_acquia_purge_service()
->oddities()
->wipe();
}
/**
* Implements hook_requirements().
*/
function acquia_purge_requirements($phase) {
if ($phase == 'runtime') {
$status_item_name = '_acquia_purge_diagnostics_status';
$diagnostics = _acquia_purge_service()
->diagnostics();
$requirements = $diagnostics
->get();
// Remove noisy INFO and OK results (except for the status item).
foreach ($requirements as $name => $result) {
if ($name === $status_item_name) {
continue;
}
if ($result['severity'] === ACQUIA_PURGE_SEVLEVEL_INFO) {
unset($requirements[$name]);
}
if ($result['severity'] === ACQUIA_PURGE_SEVLEVEL_OK) {
unset($requirements[$name]);
}
}
// Hide the status item when ERROR-level problems exist.
if ($diagnostics
->isSystemBlocked()) {
unset($requirements[$status_item_name]);
}
return $requirements;
}
return array();
}
/**
* Remove the 'acquia_purge_reportpurges' variable.
*
* The variable disappeared as of version 7.x-1.0-beta2. Its functionality has
* been replaced by the 'purge notification' permission. Which is more granular
* and increases simplicity.
*/
function acquia_purge_update_7100(&$sandbox) {
variable_del('acquia_purge_reportpurges');
}
/**
* Rename variable 'acquia_purge_queue_owner' to 'acquia_purge_queue_owners'.
*
* Because we are allowing multiple users to trigger purges concurrently as of
* version 7.x-1.0-beta2.
*/
function acquia_purge_update_7101(&$sandbox) {
variable_del('acquia_purge_queue_owner');
variable_set('acquia_purge_queue_owners', array());
}
/**
* Remove two variables used for state data instead of configuration.
*
* As of version 7.x-1.0, these two variables aren't necessary anymore and
* were used as frequently changing state data keys. As rightfully explained
* on https://www.drupal.org/node/2205015, these shouldn't belong here
* anymore. BEWARE, THIS UPDATE CLEARS YOUR QUEUE!
*/
function acquia_purge_update_7102(&$sandbox) {
variable_del('acquia_purge_queue_counter');
variable_del('acquia_purge_queue_owners');
// As we are losing our old counter and owners state, also clear the queue
// as this will otherwise inevitably lead to sites with queue zombies.
drupal_load('module', 'acquia_purge');
_acquia_purge_service()
->clear();
}
/**
* Rename the 'purge notification' permission into 'purge on-screen'.
*
* Since version 7.x-1.0, this permission got renamed as its name became
* too specific. Before it only reflected on the on-screen purging progress bar
* but is now also used for permission to the manual purge form blocks.
*/
function acquia_purge_update_7103(&$sandbox) {
$old = 'purge notification';
$new = 'purge on-screen';
// Query the old 'purge notification' permission to rename it to the new one.
$old_permissions = db_select('role_permission', 'r')
->fields('r')
->condition('permission', $old)
->execute();
foreach ($old_permissions as $old_permission) {
// Prevent duplicate entries by prequering if the new permission exists.
$already_exists = db_select('role_permission', 'r')
->fields('r')
->condition('permission', $new)
->condition('module', $old_permission->module)
->condition('rid', $old_permission->rid)
->execute()
->fetchAssoc();
if ($already_exists) {
db_delete('role_permission')
->condition('permission', $old_permission->permission)
->condition('module', $old_permission->module)
->condition('rid', $old_permission->rid)
->execute();
}
else {
db_update('role_permission')
->fields(array(
'permission' => $new,
))
->condition('permission', $old_permission->permission)
->condition('module', $old_permission->module)
->condition('rid', $old_permission->rid)
->execute();
}
}
// Asure the role permissions are reset.
drupal_static_reset('user_role_permissions');
}
/**
* Set 'expire_status', 'expire_debug' and 'expire_include_base_url' correctly.
*
* Before version 7.x-1.0, these variables were set in a hook_boot()
* implementation that did more bad than good, and it turned out to not even
* always work (Acquia #137455). Now diagnostics report badly whenever these
* settings change as well, so hard-forcing them is no longer needed.
*/
function acquia_purge_update_7104(&$sandbox) {
variable_set('expire_status', EXPIRE_STATUS_ENABLED_EXTERNAL);
variable_set('expire_debug', EXPIRE_DEBUG_DISABLED);
variable_set('expire_include_base_url', FALSE);
}
/**
* Locks are stored in Acquia Purge's state API now, remove old left over locks.
*/
function acquia_purge_update_7105(&$sandbox) {
lock_release('_acquia_purge_queue_lock');
}
/**
* Introduce the new permission 'use manual purge blocks'.
*
* Assign the new permission 'use manual purge blocks' to all roles already
* holding the 'purge on-screen' permission. The blocks used the latter first,
* but got its own permission as of version 7.x-1.2.
*/
function acquia_purge_update_7106(&$sandbox) {
// See if there are roles that already have the new permission, unlikely.
$rids_to_avoid = array();
$roles_manualpurgeblocks = db_select('role_permission', 'r')
->fields('r')
->condition('permission', 'use manual purge blocks')
->execute();
foreach ($roles_manualpurgeblocks as $role) {
$rids_to_avoid[] = $role->rid;
}
// Get the roles that have 'purge on-screen' and assign them the new one.
$roles_onscreen = db_select('role_permission', 'r')
->fields('r')
->condition('permission', 'purge on-screen')
->execute();
foreach ($roles_onscreen as $role) {
if (!in_array($role->rid, $rids_to_avoid)) {
db_merge('role_permission')
->key(array(
'rid' => $role->rid,
'permission' => 'use manual purge blocks',
))
->fields(array(
'module' => 'acquia_purge',
))
->execute();
}
}
// Clear the user access cache.
drupal_static_reset('user_access');
drupal_static_reset('user_role_permissions');
}
Functions
Name | Description |
---|---|
acquia_purge_install | Implements hook_install(). |
acquia_purge_requirements | Implements hook_requirements(). |
acquia_purge_uninstall | Implements hook_uninstall(). |
acquia_purge_update_7100 | Remove the 'acquia_purge_reportpurges' variable. |
acquia_purge_update_7101 | Rename variable 'acquia_purge_queue_owner' to 'acquia_purge_queue_owners'. |
acquia_purge_update_7102 | Remove two variables used for state data instead of configuration. |
acquia_purge_update_7103 | Rename the 'purge notification' permission into 'purge on-screen'. |
acquia_purge_update_7104 | Set 'expire_status', 'expire_debug' and 'expire_include_base_url' correctly. |
acquia_purge_update_7105 | Locks are stored in Acquia Purge's state API now, remove old left over locks. |
acquia_purge_update_7106 | Introduce the new permission 'use manual purge blocks'. |