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

Issue #3472904: Move all the code in apc.module to apc_admin.module

parent b78c6544
No related branches found
No related tags found
1 merge request!80Issue #3472904: Move all the code in apc.module to apc_admin.module
Pipeline #277371 passed
......@@ -3,88 +3,7 @@
/**
* @file
* Hook implementations for the Alternative PHP Cache module.
*
* This file is intentionally empty, as all the hooks are implemented in an
* optional module.
*/
declare(strict_types=1);
/**
* Implements hook_permission().
*/
function apc_permission(): array {
return array(
'access apc statistics' => array(
'title' => t('Access APC statistics'),
'description' => t('Allows access to the APC statistics reports.'),
),
);
}
/**
* Implements hook_page_alter().
*/
function apc_page_alter(&$page): void {
if (variable_get('apc_show_debug', FALSE) && user_access('access apc statistics')) {
$operations = ApcCache::operations();
$rows = array();
if (!empty($operations)) {
foreach ($operations as $row) {
if (is_array($row[2])) {
$row[2] = implode(',<br />', $row[2]);
}
$rows[] = $row;
}
}
$page['page_top']['apc_cache_info'] = array(
'#type' => 'markup',
'#prefix' => '<div class="apc-cache-info">',
'#suffix' => '</div>',
'#markup' => '<h2>' . t('APCu information') . '</h2>',
);
$page['page_bottom']['apc_cache_info']['operations'] = array(
'#type' => 'table',
'#header' => array(t('Operation'), t('Bin'), t('Cache IDs')),
'#rows' => $rows,
'#empty' => t('No APC cache operations have been performed.'),
);
drupal_page_is_cacheable(FALSE);
}
}
/**
* Implements hook_form_FORM_ID_alter() for system_performance_settings().
*/
function apc_form_system_performance_settings_alter(&$form, &$form_state): void {
if (extension_loaded('apcu')) {
$form['clear_cache']['clear']['#submit'][] = 'apc_clear_apcu_cache';
$form['clear_cache']['apcu_cache'] = array(
'#type' => 'submit',
'#value' => t('Clear APCu cache'),
'#submit' => array('apc_clear_apcu_cache'),
);
}
}
/**
* Submission form handler for system_performance_settings().
*/
function apc_clear_apcu_cache(): void {
if (extension_loaded('apcu') && apcu_enabled()) {
$iterator = new APCUIterator("/^apc_cache::[a-zA-Z0-9-_]{20,}::[a-zA-Z0-9-_]{20,}/", APC_ITER_KEY);
if (apcu_delete($iterator)) {
drupal_set_message(t('The APCu cache has been cleared.'));
}
else {
drupal_set_message(t('The APCu cache could not be cleared.'), 'error');
}
}
else {
drupal_set_message(t('APCu is not enabled.'), 'warning');
}
}
name = Alternative PHP Cache - Admin pages
description = Administration pages for the Alternative PHP Cache module.
package = Performance and scalability
core = 7.x
php = 8.2
dependencies[] = apc
<?php
/**
* @file
* Hooks implementations for the Alternative PHP Cache - Admin pages module.
*/
declare(strict_types=1);
/**
* Implements hook_permission().
*/
function apc_admin_permission(): array {
return array(
'access apc statistics' => array(
'title' => t('Access APC statistics'),
'description' => t('Allows access to the APC statistics reports.'),
),
);
}
/**
* Implements hook_page_alter().
*/
function apc_admin_page_alter(&$page): void {
if (variable_get('apc_show_debug', FALSE) && user_access('access apc statistics')) {
$operations = ApcCache::operations();
$rows = array();
if (!empty($operations)) {
foreach ($operations as $row) {
if (is_array($row[2])) {
$row[2] = implode(',<br />', $row[2]);
}
$rows[] = $row;
}
}
$page['page_top']['apc_cache_info'] = array(
'#type' => 'markup',
'#prefix' => '<div class="apc-admin-cache-info">',
'#suffix' => '</div>',
'#markup' => '<h2>' . t('APCu information') . '</h2>',
);
$page['page_bottom']['apc_admin_cache_info']['operations'] = array(
'#type' => 'table',
'#header' => array(t('Operation'), t('Bin'), t('Cache IDs')),
'#rows' => $rows,
'#empty' => t('No APC cache operations have been performed.'),
);
drupal_page_is_cacheable(FALSE);
}
}
/**
* Implements hook_form_FORM_ID_alter() for system_performance_settings().
*/
function apc_admin_form_system_performance_settings_alter(&$form, &$form_state): void {
if (extension_loaded('apcu')) {
$form['clear_cache']['clear']['#submit'][] = 'apc_admin_clear_apcu_cache';
$form['clear_cache']['apc_admin_apcu_cache'] = array(
'#type' => 'submit',
'#value' => t('Clear APCu cache'),
'#submit' => array('apc_admin_clear_apcu_cache'),
);
}
}
/**
* Submission form handler for system_performance_settings().
*/
function apc_admin_clear_apcu_cache(): void {
if (extension_loaded('apcu') && apcu_enabled()) {
$iterator = new APCUIterator("/^apc_cache::[a-zA-Z0-9-_]{20,}::[a-zA-Z0-9-_]{20,}/", APC_ITER_KEY);
if (apcu_delete($iterator)) {
drupal_set_message(t('The APCu cache has been cleared.'));
}
else {
drupal_set_message(t('The APCu cache could not be cleared.'), 'error');
}
}
else {
drupal_set_message(t('APCu is not enabled.'), 'warning');
}
}
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