advagg.admin.inc

  1. nittany7 modules/contrib/advagg/advagg.admin.inc
  2. cis7 modules/contrib/advagg/advagg.admin.inc
  3. mooc7 modules/contrib/advagg/advagg.admin.inc

Admin page callbacks for the advanced CSS/JS aggregation module.

Functions

Namesort descending Description
advagg_admin_clear_all_caches_button Clear out all advagg cache bins.
advagg_admin_clear_all_files_button Clear out all advagg cache bins and clear out all advagg aggregated files.
advagg_admin_flush_cache_button Perform a smart flush.
advagg_admin_flush_stale_files_button Clear out all stale advagg aggregated files.
advagg_admin_get_file_info Get detailed info about the given filename.
advagg_admin_get_file_info_callback Display file info via ajax callback.
advagg_admin_get_file_info_submit Display file info in a drupal message.
advagg_admin_get_file_info_validate Verify that the filename is correct.
advagg_admin_increment_global_counter Clear out all advagg cache bins and increment the counter.
advagg_admin_info_form Form builder; Show info about advagg and advagg settings.
advagg_admin_operations_form Form builder; Do advagg operations.
advagg_admin_remove_missing_files_from_db_button Scan for missing files and remove the associated entries in the database.
advagg_admin_remove_old_unused_aggregates_button Delete aggregates that have not been accessed in the last 6 weeks.
advagg_admin_settings_form Form builder; Configure advagg settings.
advagg_admin_settings_form_submit Clear out the advagg cache bin when the save configuration button is pressed.
advagg_admin_toggle_bypass_cookie Set or remove the AdvAggDisabled cookie.

File

modules/contrib/advagg/advagg.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Admin page callbacks for the advanced CSS/JS aggregation module.
  5. */
  6. /**
  7. * Form builder; Configure advagg settings.
  8. *
  9. * @ingroup forms
  10. * @see system_settings_form()
  11. */
  12. function advagg_admin_settings_form($form, $form_state) {
  13. drupal_set_title(t('AdvAgg: Configuration'));
  14. // Simple checkbox settings.
  15. $form['global'] = array(
  16. '#type' => 'fieldset',
  17. '#title' => t('Global Options'),
  18. );
  19. $form['global']['advagg_enabled'] = array(
  20. '#type' => 'checkbox',
  21. '#title' => t('Enable advanced aggregation'),
  22. '#default_value' => variable_get('advagg_enabled', ADVAGG_ENABLED),
  23. );
  24. $form['global']['advagg_gzip'] = array(
  25. '#type' => 'checkbox',
  26. '#title' => t('Create .gz files'),
  27. '#default_value' => variable_get('advagg_gzip', ADVAGG_GZIP),
  28. );
  29. $form['global']['advagg_core_groups'] = array(
  30. '#type' => 'checkbox',
  31. '#title' => t('Use cores grouping logic'),
  32. '#default_value' => variable_get('advagg_core_groups', ADVAGG_CORE_GROUPS),
  33. );
  34. $form['global']['advagg_use_httprl'] = array(
  35. '#type' => 'checkbox',
  36. '#title' => t('Use HTTPRL to generate aggregates.'),
  37. '#default_value' => module_exists('httprl') ? variable_get('advagg_use_httprl', ADVAGG_USE_HTTPRL) : FALSE,
  38. '#disabled' => module_exists('httprl') ? FALSE : TRUE,
  39. );
  40. $options = array(
  41. -1 => t('Development ~ 100ms'),
  42. 0 => t('Disabled ~ 70ms'),
  43. 1 => t('Normal ~ 10ms'),
  44. 3 => t('Aggressive ~ 4ms'),
  45. );
  46. $form['global']['advagg_cache_level'] = array(
  47. '#type' => 'radios',
  48. '#title' => t('AdvAgg Cache Settings'),
  49. '#default_value' => variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL),
  50. '#options' => $options,
  51. '#description' => t('Development will scan all files for a change on every page load. Disabled is useful for testing hook_alters for CSS/JS. Normal is should be fine for all use cases. Aggressive might break depending on how various hook_alter for CSS/JS are implemented. As a reference, core takes about 7 ms to run.'),
  52. );
  53. $form['css'] = array(
  54. '#type' => 'fieldset',
  55. '#title' => t('CSS Options'),
  56. );
  57. $form['css']['advagg_combine_css_media'] = array(
  58. '#type' => 'checkbox',
  59. '#title' => t('Combine CSS files by using media queries'),
  60. '#default_value' => variable_get('advagg_combine_css_media', ADVAGG_COMBINE_CSS_MEDIA),
  61. '#description' => t('Use cores grouping logic needs to be unchecked in order for this to work. Also noted is that due to an issue with IE9, compatibility mode is forced off if this is enabled.'),
  62. );
  63. $form['css']['advagg_ie_css_selector_limiter'] = array(
  64. '#type' => 'checkbox',
  65. '#title' => t('Prevent more than 4095 CSS selectors in an aggregated CSS file'),
  66. '#default_value' => variable_get('advagg_ie_css_selector_limiter', ADVAGG_IE_CSS_SELECTOR_LIMITER),
  67. '#description' => t('Internet Explorer before version 10; IE9, IE8, IE7, & IE6 all have 4095 as the limit for the maximum number of css selectors that can be in a file. Enabling this will prevent CSS aggregates from being created that exceed this limit. <a href="@link">More info</a>.', array('@link' => 'http://blogs.msdn.com/b/ieinternals/archive/2011/05/14/10164546.aspx')),
  68. );
  69. $form['css']['advagg_css_fix_type'] = array(
  70. '#type' => 'checkbox',
  71. '#title' => t('Fix improperly set type'),
  72. '#default_value' => variable_get('advagg_css_fix_type', ADVAGG_CSS_FIX_TYPE),
  73. '#description' => t('If type is external but does not start with http, change it to be type file. If type is file but it starts with http, change type to be external.'),
  74. );
  75. $form['js'] = array(
  76. '#type' => 'fieldset',
  77. '#title' => t('JS Options'),
  78. );
  79. $form['js']['advagg_js_fix_type'] = array(
  80. '#type' => 'checkbox',
  81. '#title' => t('Fix improperly set type'),
  82. '#default_value' => variable_get('advagg_js_fix_type', ADVAGG_JS_FIX_TYPE),
  83. '#description' => t('If type is external but does not start with http, change it to be type file. If type is file but it starts with http, change type to be external.'),
  84. );
  85. // Clear the cache bins on submit.
  86. $form['#submit'][] = 'advagg_admin_settings_form_submit';
  87. return system_settings_form($form);
  88. }
  89. /**
  90. * Form builder; Do advagg operations.
  91. *
  92. * @ingroup forms
  93. */
  94. function advagg_admin_operations_form($form, $form_state) {
  95. drupal_set_title(t('AdvAgg: Operations'));
  96. // Buttons to do stuff.
  97. // Smart flushing.
  98. $form['smart_flush'] = array(
  99. '#type' => 'fieldset',
  100. '#title' => t('Smart Cache Flush'),
  101. '#description' => t('Scan all files referenced in aggregated files. If any of them have changed, clear that cache so the changes will go out.'),
  102. );
  103. $form['smart_flush']['advagg_flush'] = array(
  104. '#type' => 'submit',
  105. '#value' => t('Flush AdvAgg Cache'),
  106. '#submit' => array('advagg_admin_flush_cache_button'),
  107. );
  108. $form['smart_flush']['output'] = array(
  109. '#markup' => '<p>' . t('The following 3 functions get ran on cron but you can run them manually here.') . '</p>',
  110. );
  111. $form['smart_flush']['smart_file_flush'] = array(
  112. '#type' => 'fieldset',
  113. '#collapsible' => TRUE,
  114. '#collapsed' => TRUE,
  115. '#title' => t('Clear All Stale Files'),
  116. '#description' => t('Remove all stale files. Scan all files in the advagg_css/js directories and remove the ones that have not been accessed in the last 30 days.'),
  117. );
  118. $form['smart_flush']['smart_file_flush']['advagg_flush_stale_files'] = array(
  119. '#type' => 'submit',
  120. '#value' => t('Remove All Stale Files'),
  121. '#submit' => array('advagg_admin_flush_stale_files_button'),
  122. );
  123. $form['smart_flush']['remove_missing_files'] = array(
  124. '#type' => 'fieldset',
  125. '#collapsible' => TRUE,
  126. '#collapsed' => TRUE,
  127. '#title' => t('Clear Missing Files From Database'),
  128. '#description' => t('Scan for missing files and remove the associated entries in the database.'),
  129. );
  130. $form['smart_flush']['remove_missing_files']['advagg_remove_missing_files_from_db'] = array(
  131. '#type' => 'submit',
  132. '#value' => t('Clear Missing Files From Database'),
  133. '#submit' => array('advagg_admin_remove_missing_files_from_db_button'),
  134. );
  135. $form['smart_flush']['remove_old_aggregates'] = array(
  136. '#type' => 'fieldset',
  137. '#collapsible' => TRUE,
  138. '#collapsed' => TRUE,
  139. '#title' => t('Delete Unused Aggregates From Database'),
  140. '#description' => t('Delete aggregates that have not been accessed in the last 6 weeks.'),
  141. );
  142. $form['smart_flush']['remove_old_aggregates']['advagg_remove_old_unused_aggregates'] = array(
  143. '#type' => 'submit',
  144. '#value' => t('Delete Unused Aggregates From Database'),
  145. '#submit' => array('advagg_admin_remove_old_unused_aggregates_button'),
  146. );
  147. // Set/Remove Bypass Cookie.
  148. $form['bypass'] = array(
  149. '#type' => 'fieldset',
  150. '#title' => t('Aggregation Bypass Cookie'),
  151. '#description' => t('This will set or remove a cookie that disables aggregation for the remainder of the browser session.'),
  152. );
  153. $form['bypass']['submit'] = array(
  154. '#type' => 'submit',
  155. '#value' => t('Toggle the "aggregation bypass cookie" for this browser'),
  156. '#attributes' => array('onclick' => 'javascript:return advagg_toggle_cookie()'),
  157. '#submit' => array('advagg_admin_toggle_bypass_cookie'),
  158. );
  159. // Add in aggregation bypass cookie javascript.
  160. $form['#attached']['js'][] = array(
  161. 'data' => array('advagg' => array('key' => drupal_hash_base64(drupal_get_private_key()))),
  162. 'type' => 'setting',
  163. );
  164. $form['#attached']['js'][] = drupal_get_path('module', 'advagg') . '/advagg.admin.js';
  165. // Hide drastic measures as they should not be done unless you really need it.
  166. $form['drastic_measures'] = array(
  167. '#type' => 'fieldset',
  168. '#collapsible' => TRUE,
  169. '#collapsed' => TRUE,
  170. '#title' => t('Drastic Measures'),
  171. '#description' => t('The options below should normally never need to be done.'),
  172. );
  173. $form['drastic_measures']['dumb_cache_flush'] = array(
  174. '#type' => 'fieldset',
  175. '#collapsible' => TRUE,
  176. '#collapsed' => TRUE,
  177. '#title' => t('Clear All Caches'),
  178. '#description' => t('Remove all entries from the advagg cache bins. Useful if you suspect a cache is not getting cleared.'),
  179. );
  180. $form['drastic_measures']['dumb_cache_flush']['advagg_flush_all_caches'] = array(
  181. '#type' => 'submit',
  182. '#value' => t('Clear All Caches'),
  183. '#submit' => array('advagg_admin_clear_all_caches_button'),
  184. );
  185. $form['drastic_measures']['dumb_file_flush'] = array(
  186. '#type' => 'fieldset',
  187. '#collapsible' => TRUE,
  188. '#collapsed' => TRUE,
  189. '#title' => t('Clear All Files'),
  190. '#description' => t('Remove all generated files. Useful if you think some of the generated files got corrupted and thus need to be deleted.'),
  191. );
  192. $form['drastic_measures']['dumb_file_flush']['advagg_flush_all_files'] = array(
  193. '#type' => 'submit',
  194. '#value' => t('Remove All Generated Files'),
  195. '#submit' => array('advagg_admin_clear_all_files_button'),
  196. );
  197. $form['drastic_measures']['force_change'] = array(
  198. '#type' => 'fieldset',
  199. '#collapsible' => TRUE,
  200. '#collapsed' => TRUE,
  201. '#title' => t('Force new aggregates'),
  202. '#description' => t('Force the creation of all new aggregates by incrementing a global counter. Current value of counter: %value. This is useful if a CDN has cached an aggregate incorrectly as it will force new ones to be used even if nothing else has changed.', array('%value' => advagg_get_global_counter())),
  203. );
  204. $form['drastic_measures']['force_change']['increment_global_counter'] = array(
  205. '#type' => 'submit',
  206. '#value' => t('Increment Global Counter'),
  207. '#submit' => array('advagg_admin_increment_global_counter'),
  208. );
  209. return $form;
  210. }
  211. /**
  212. * Form builder; Show info about advagg and advagg settings.
  213. *
  214. * @ingroup forms
  215. * @see system_settings_form()
  216. */
  217. function advagg_admin_info_form($form, $form_state) {
  218. drupal_set_title(t('AdvAgg: Information'));
  219. // Get all hooks.
  220. drupal_theme_initialize();
  221. $core_hooks = theme_get_registry();
  222. $advagg_hooks = advagg_hooks_implemented();
  223. // Output html process functions hooks.
  224. $form['info'] = array(
  225. '#type' => 'fieldset',
  226. '#collapsible' => TRUE,
  227. '#collapsed' => TRUE,
  228. '#title' => t('Hook Theme Info'),
  229. );
  230. $data = implode("\n", $core_hooks['html']['process functions']);
  231. $form['info']['advagg_debug_info'] = array(
  232. '#markup' => '<pre>' . $data . '</pre>',
  233. );
  234. // Get all parent css and js files.
  235. $types = array('css', 'js');
  236. foreach ($types as $type) {
  237. $form[$type] = array(
  238. '#type' => 'fieldset',
  239. '#collapsible' => TRUE,
  240. '#collapsed' => TRUE,
  241. '#title' => t('@type files', array('@type' => drupal_strtoupper($type))),
  242. );
  243. // Get filename, filename_hash, and changes.
  244. $results = db_select('advagg_files', 'af')
  245. ->fields('af', array('filename', 'filename_hash', 'changes'))
  246. ->condition('filetype', $type)
  247. ->execute();
  248. while ($row = $results->fetchAssoc()) {
  249. $form[$type][$row['filename_hash']] = array(
  250. '#markup' => '<div>' . format_plural($row['changes'], 'changed 1 time - %file<br />', 'changed %changes times - %file<br /></div>', array(
  251. '%changes' => $row['changes'],
  252. '%file' => $row['filename'],
  253. )),
  254. );
  255. }
  256. }
  257. // Display as module -> hook instead of hook -> module.
  258. ksort($advagg_hooks);
  259. $module_hooks = array();
  260. foreach ($advagg_hooks as $hook => $values) {
  261. if (!empty($values)) {
  262. foreach ($values as $module_name) {
  263. if (!isset($module_hooks[$module_name])) {
  264. $module_hooks[$module_name] = array();
  265. }
  266. $module_hooks[$module_name][] = $hook;
  267. }
  268. }
  269. else {
  270. $module_hooks['not in use'][] = $hook;
  271. }
  272. }
  273. ksort($module_hooks);
  274. // Output all advagg hooks implemented.
  275. foreach ($module_hooks as $hook => $values) {
  276. if (empty($values)) {
  277. $form['modules_implementing_advagg'][$hook] = array(
  278. '#markup' => '<div><strong>' . check_plain($hook) . ':</strong> 0</div>',
  279. );
  280. }
  281. else {
  282. $form['modules_implementing_advagg'][$hook] = array(
  283. '#markup' => '<div><strong>' . check_plain($hook) . ':</strong> ' . count($values) . '<br />&nbsp;&nbsp;' . filter_xss(implode('<br />&nbsp;&nbsp;', $values), array('br')) . '</div>',
  284. );
  285. }
  286. }
  287. $form['modules_implementing_advagg'] += array(
  288. '#type' => 'fieldset',
  289. '#collapsible' => TRUE,
  290. '#collapsed' => TRUE,
  291. '#title' => t('Modules implementing AdvAgg CSS/JS hooks'),
  292. );
  293. // Output all advagg hooks implemented.
  294. foreach ($advagg_hooks as $hook => $values) {
  295. if (empty($values)) {
  296. $form['hooks_implemented'][$hook] = array(
  297. '#markup' => '<div><strong>' . check_plain($hook) . ':</strong> 0</div>',
  298. );
  299. }
  300. else {
  301. $form['hooks_implemented'][$hook] = array(
  302. '#markup' => '<div><strong>' . check_plain($hook) . ':</strong> ' . count($values) . '<br />&nbsp;&nbsp;' . filter_xss(implode('<br />&nbsp;&nbsp;', $values), array('br')) . '</div>',
  303. );
  304. }
  305. }
  306. $form['hooks_implemented'] += array(
  307. '#type' => 'fieldset',
  308. '#collapsible' => TRUE,
  309. '#collapsed' => TRUE,
  310. '#title' => t('AdvAgg CSS/JS hooks implemented by modules'),
  311. );
  312. // Output what is used inside of the advagg_get_current_hooks_hash() function.
  313. $form['hooks_variables_hash'] = array(
  314. '#type' => 'fieldset',
  315. '#collapsible' => TRUE,
  316. '#collapsed' => TRUE,
  317. '#title' => t('Hooks And Variables Used In Hash'),
  318. );
  319. $form['hooks_variables_hash']['description'] = array(
  320. '#markup' => t('Current Value: %value. Below is the listing of variables and hooks used to generate the 3rd hash of an aggregates filename.', array('%value' => advagg_get_current_hooks_hash())),
  321. );
  322. $form['hooks_variables_hash']['output'] = array(
  323. '#markup' => '<pre>' . print_r(advagg_current_hooks_hash_array(), TRUE) . '</pre>'
  324. );
  325. // Get info about a file.
  326. $form['get_info_about_agg'] = array(
  327. '#type' => 'fieldset',
  328. '#collapsible' => TRUE,
  329. '#collapsed' => FALSE,
  330. '#title' => t('Get detailed info about an aggregate file'),
  331. );
  332. $form['get_info_about_agg']['filename'] = array(
  333. '#type' => 'textfield',
  334. '#size' => 170,
  335. '#maxlength' => 256,
  336. '#default_value' => '',
  337. '#title' => t('Filename'),
  338. );
  339. $form['get_info_about_agg']['submit'] = array(
  340. '#type' => 'submit',
  341. '#value' => t('Lookup Details'),
  342. '#submit' => array('advagg_admin_get_file_info_submit'),
  343. '#validate' => array('advagg_admin_get_file_info_validate'),
  344. "#ajax" => array(
  345. "callback" => "advagg_admin_get_file_info_callback",
  346. "wrapper" => "advagg-file-info-ajax",
  347. "effect" => "fade",
  348. ),
  349. );
  350. $form['get_info_about_agg']["wrapper"] = array(
  351. "#markup" => "<div id='advagg-file-info-ajax'></div>",
  352. );
  353. return $form;
  354. }
  355. // Submit callback.
  356. /**
  357. * Clear out the advagg cache bin when the save configuration button is pressed.
  358. */
  359. function advagg_admin_settings_form_submit($form, &$form_state) {
  360. $cache_bins = advagg_flush_caches();
  361. foreach ($cache_bins as $bin) {
  362. cache_clear_all('*', $bin, TRUE);
  363. }
  364. }
  365. // Callbacks for buttons.
  366. /**
  367. * Set or remove the AdvAggDisabled cookie.
  368. */
  369. function advagg_admin_toggle_bypass_cookie() {
  370. $cookie_name = 'AdvAggDisabled';
  371. $key = drupal_hash_base64(drupal_get_private_key());
  372. // If the cookie does exist then remove it.
  373. if (!empty($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name] == $key) {
  374. setcookie($cookie_name, '', -1, $GLOBALS['base_path'], '.' . $_SERVER['HTTP_HOST']);
  375. unset($_COOKIE[$cookie_name]);
  376. drupal_set_message(t('AdvAgg Bypass Cookie Removed.'));
  377. }
  378. // If the cookie does not exist then set it.
  379. else {
  380. setcookie($cookie_name, $key, 0, $GLOBALS['base_path'], '.' . $_SERVER['HTTP_HOST']);
  381. $_COOKIE[$cookie_name] = $key;
  382. drupal_set_message(t('AdvAgg Bypass Cookie Set.'));
  383. }
  384. }
  385. /**
  386. * Display file info in a drupal message.
  387. */
  388. function advagg_admin_get_file_info_submit($form, &$form_state) {
  389. if (!empty($form_state['input']['ajax_page_state'])) {
  390. return;
  391. }
  392. $info = advagg_admin_get_file_info($form_state['values']['filename']);
  393. if (module_exists('httprl')) {
  394. $output = httprl_pr($info);
  395. }
  396. else {
  397. $output = '<pre>' . print_r($info, TRUE) . '</pre>';
  398. }
  399. drupal_set_message($output);
  400. }
  401. /**
  402. * Display file info via ajax callback.
  403. */
  404. function advagg_admin_get_file_info_callback($form, &$form_state) {
  405. if (!empty($form_state['values']['error'])) {
  406. return '<div id="advagg-file-info-ajax"></div>';
  407. }
  408. $info = advagg_admin_get_file_info($form_state['values']['filename']);
  409. if (empty($info)) {
  410. form_set_error('filename', 'Please input a valid aggregate filename.');
  411. return '<div id="advagg-file-info-ajax"></div>';
  412. }
  413. else {
  414. if (module_exists('httprl')) {
  415. $output = httprl_pr($info);
  416. }
  417. else {
  418. $output = '<pre>' . print_r($info, TRUE) . '</pre>';
  419. }
  420. return '<div id="advagg-file-info-ajax">' . $output . '</div>';
  421. }
  422. }
  423. /**
  424. * Verify that the filename is correct.
  425. */
  426. function advagg_admin_get_file_info_validate($form, &$form_state) {
  427. if (empty($form_state['values']['filename'])) {
  428. form_set_error('filename', 'Please input an aggregate filename.');
  429. $form_state['values']['error'] = TRUE;
  430. }
  431. }
  432. /**
  433. * Get detailed info about the given filename.
  434. *
  435. * @param $filename
  436. * Name of file to lookup.
  437. * @return array
  438. * Returns an array of detailed info about this file.
  439. */
  440. function advagg_admin_get_file_info($filename) {
  441. module_load_include('inc', 'advagg', 'advagg.missing');
  442. module_load_include('inc', 'advagg', 'advagg');
  443. $data = advagg_get_hashes_from_filename($filename);
  444. $output = array();
  445. if (is_array($data)) {
  446. list($type, $aggregate_filenames_hash, $aggregate_contents_hash, $aggregate_settings) = $data;
  447. // Get a list of files.
  448. $files = advagg_get_files_from_hashes($type, $aggregate_filenames_hash, $aggregate_contents_hash);
  449. $data['files'] = $files;
  450. // Get detailed info on each file.
  451. foreach ($data['files'] as $filename => &$info) {
  452. $info += advagg_get_info_on_file($filename);
  453. if (module_exists('advagg_bundler')) {
  454. $bundler = advagg_bundler_analysis($filename);
  455. $info['group_hash'] = $bundler['group_hash'];
  456. }
  457. }
  458. $output = $data;
  459. }
  460. else {
  461. $results = db_select('advagg_files', 'af')
  462. ->fields('af')
  463. ->condition('filename', '%' . db_like($filename), 'LIKE')
  464. ->execute();
  465. while ($row = $results->fetchAssoc()) {
  466. $row += advagg_get_info_on_file($row['filename']);
  467. if (module_exists('advagg_bundler')) {
  468. $bundler = advagg_bundler_analysis($row['filename']);
  469. $row['group_hash'] = $bundler['group_hash'];
  470. }
  471. $output[] = $row;
  472. }
  473. }
  474. return $output;
  475. }
  476. /**
  477. * Perform a smart flush.
  478. */
  479. function advagg_admin_flush_cache_button() {
  480. // Run the command.
  481. module_load_include('inc', 'advagg', 'advagg.cache');
  482. $flushed = advagg_push_new_changes();
  483. // Report back the results.
  484. if (empty($flushed)) {
  485. drupal_set_message(t('No changes found. Nothing was cleared.'));
  486. return;
  487. }
  488. foreach ($flushed as $filename => $data) {
  489. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  490. drupal_set_message(t('The file %filename has changed. %db_usage aggregates are using this file. %db_count db cache entries and all %type full cache entries have been flushed from the cache bins.', array(
  491. '%filename' => $filename,
  492. '%db_usage' => count($data[0]),
  493. '%db_count' => count($data[1]),
  494. '%type' => $ext,
  495. )));
  496. }
  497. }
  498. /**
  499. * Clear out all advagg cache bins.
  500. */
  501. function advagg_admin_clear_all_caches_button() {
  502. // Run the command.
  503. module_load_include('inc', 'advagg', 'advagg.cache');
  504. advagg_flush_all_cache_bins();
  505. // Report back the results.
  506. drupal_set_message(t('All AdvAgg cache bins have been cleared.'));
  507. }
  508. /**
  509. * Clear out all advagg cache bins and clear out all advagg aggregated files.
  510. */
  511. function advagg_admin_clear_all_files_button() {
  512. // Clear out the cache.
  513. advagg_admin_clear_all_caches_button();
  514. // Run the command.
  515. module_load_include('inc', 'advagg', 'advagg.cache');
  516. list($css_files, $js_files) = advagg_remove_all_aggregated_files();
  517. // Report back the results.
  518. drupal_set_message(t('All AdvAgg files have been deleted. %css_count CSS files and %js_count JS files have been removed.', array(
  519. '%css_count' => count($css_files),
  520. '%js_count' => count($js_files),
  521. )));
  522. }
  523. /**
  524. * Clear out all stale advagg aggregated files.
  525. */
  526. function advagg_admin_flush_stale_files_button() {
  527. // Run the command.
  528. module_load_include('inc', 'advagg', 'advagg.cache');
  529. list($css_files, $js_files) = advagg_delete_stale_aggregates();
  530. // Report back the results.
  531. if (count($css_files) > 0 || count($js_files) > 0) {
  532. drupal_set_message(t('All stale aggregates have been deleted. %css_count CSS files and %js_count JS files have been removed.', array(
  533. '%css_count' => count($css_files),
  534. '%js_count' => count($js_files),
  535. )));
  536. }
  537. else {
  538. drupal_set_message(t('No stale aggregates found. Nothing was deleted.'));
  539. }
  540. }
  541. /**
  542. * Clear out all advagg cache bins and increment the counter.
  543. */
  544. function advagg_admin_increment_global_counter() {
  545. // Clear out the cache.
  546. advagg_admin_clear_all_caches_button();
  547. // Increment counter.
  548. module_load_include('inc', 'advagg', 'advagg.cache');
  549. $new_value = advagg_increment_global_counter();
  550. drupal_set_message(t('Global counter is now set to %new_value', array('%new_value' => $new_value)));
  551. }
  552. /**
  553. * Scan for missing files and remove the associated entries in the database.
  554. */
  555. function advagg_admin_remove_missing_files_from_db_button() {
  556. module_load_include('inc', 'advagg', 'advagg.cache');
  557. // Remove aggregates that include missing files.
  558. $deleted = advagg_remove_missing_files_from_db();
  559. if (empty($deleted)) {
  560. drupal_set_message(t('No missing files found and/or could be safely cleared out of the database.'));
  561. }
  562. else {
  563. drupal_set_message(t('Some missing files were found and could be safely cleared out of the database. <pre> @raw </pre>', array('@raw' => print_r($deleted, TRUE))));
  564. }
  565. }
  566. /**
  567. * Delete aggregates that have not been accessed in the last 6 weeks.
  568. */
  569. function advagg_admin_remove_old_unused_aggregates_button() {
  570. module_load_include('inc', 'advagg', 'advagg.cache');
  571. // Remove unused aggregates.
  572. $count = advagg_remove_old_unused_aggregates();
  573. if (empty($count)) {
  574. drupal_set_message(t('No old and unused aggregates found. Nothing was deleted.'));
  575. }
  576. else {
  577. drupal_set_message(t('Some old and unused aggregates were found. A total of %count database entries were removed.', array('%count' => $count)));
  578. }
  579. }