Skip to content
Snippets Groups Projects
Verified Commit e18f8b9d authored by Alberto Paderno's avatar Alberto Paderno
Browse files

Issue #3461880: Use drupal_register_shutdown_function() to register shutdown callbacks

parent 167befca
No related branches found
No related tags found
1 merge request!8Issue #3461880: Use drupal_register_shutdown_function() to register shutdown callbacks
Pipeline #225829 passed
......@@ -7,6 +7,79 @@
// phpcs:disable SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator.NullCoalesceOperatorNotUsed
/**
* Implements hook_init().
*/
function apc_init() {
global $user;
if (($user->uid == 0) || !variable_get('apc_show_debug', FALSE)
|| !user_access('access apc statistics') || strstr($_SERVER['PHP_SELF'], 'update.php')
|| strstr($_GET['q'], 'autocomplete')) {
return;
}
drupal_register_shutdown_function('apc_shutdown');
}
/**
* Implements hook_permission().
*/
function apc_permission() {
return array(
'access apc statistics' => array(
'title' => t('Access APC statistics'),
'description' => t('Allows access to the APC statistics reports.'),
),
);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function apc_form_system_performance_settings_alter(&$form, $form_state) {
$form['clear_cache']['clear']['#submit'][] = 'apc_clear_user_cache';
$form['clear_cache']['clear']['#submit'][] = 'apc_clear_opcode_cache';
$form['clear_cache']['apc_user'] = array(
'#type' => 'submit',
'#value' => t('Clear APC user cache'),
'#submit' => array('apc_clear_user_cache'),
);
if (!extension_loaded('apcu')) {
$form['clear_cache']['apc_opcode'] = array(
'#type' => 'submit',
'#value' => t('Clear APC opcode cache'),
'#submit' => array('apc_clear_opcode_cache'),
);
}
}
/**
* Helper function to clear user cache.
*/
function apc_clear_user_cache() {
if (apc_clear_cache('user')) {
drupal_set_message(t('Cleared APC user cache.'));
}
else {
drupal_set_message(t('Unable to clear APC user cache.'), 'error');
}
}
/**
* Helper function to clear opcode cache.
*/
function apc_clear_opcode_cache() {
if (apc_clear_cache()) {
drupal_set_message(t('Cleared APC opcode cache.'));
}
else {
drupal_set_message(t('Unable to clear APC opcode cache.'), 'error');
}
}
/**
* Implements hook_xmlrpc().
*/
......@@ -52,33 +125,6 @@ function apc_drush_flush($variables) {
}
}
/**
* Implements hook_init().
*/
function apc_init() {
global $user;
if (($user->uid == 0) || !variable_get('apc_show_debug', FALSE)
|| !user_access('access apc statistics') || strstr($_SERVER['PHP_SELF'], 'update.php')
|| strstr($_GET['q'], 'autocomplete')) {
return;
}
register_shutdown_function('apc_shutdown');
}
/**
* Implements hook_permission().
*/
function apc_permission() {
return array(
'access apc statistics' => array(
'title' => t('Access APC statistics'),
'description' => t('Allows access to the APC statistics reports.'),
),
);
}
/**
* Shutdown function: Displays APC stats in the footer.
*/
......@@ -123,49 +169,3 @@ function apc_shutdown() {
print '</div>';
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function apc_form_system_performance_settings_alter(&$form, $form_state) {
$form['clear_cache']['clear']['#submit'][] = 'apc_clear_user_cache';
$form['clear_cache']['clear']['#submit'][] = 'apc_clear_opcode_cache';
$form['clear_cache']['apc_user'] = array(
'#type' => 'submit',
'#value' => t('Clear APC user cache'),
'#submit' => array('apc_clear_user_cache'),
);
if (!extension_loaded('apcu')) {
$form['clear_cache']['apc_opcode'] = array(
'#type' => 'submit',
'#value' => t('Clear APC opcode cache'),
'#submit' => array('apc_clear_opcode_cache'),
);
}
}
/**
* Helper function to clear user cache.
*/
function apc_clear_user_cache() {
if (apc_clear_cache('user')) {
drupal_set_message(t('Cleared APC user cache.'));
}
else {
drupal_set_message(t('Unable to clear APC user cache.'), 'error');
}
}
/**
* Helper function to clear opcode cache.
*/
function apc_clear_opcode_cache() {
if (apc_clear_cache()) {
drupal_set_message(t('Cleared APC opcode cache.'));
}
else {
drupal_set_message(t('Unable to clear APC opcode cache.'), 'error');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment