boost.rules.inc 1.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php
// $Id$

/**
 * @file
 * Integration with the rules module
 */

/**
 * Implementation of hook_rules_action_info().
 *
 * @ingroup rules
 */
function boost_rules_action_info() {
  return array(
    'boost_rules_action_clear_page' => array(
      'label' => t('Clear a page from the boost cache.'),
      'arguments' => array(
        'page' => array('type' => 'string', 'label' => t('URL of page to clear')),
      ),
      'module' => 'Boost',
    ),
  );
}

/**
 * Clears a page from the Boost cache
 */
function boost_rules_action_clear_page($page, $settings) {
30 31 32
  if (file_exists(boost_file_path($page, FALSE))) {
    $expire_now = $settings['expire_now'];
    boost_cache_expire_derivative(array($page), $expire_now, $expire_now);
33
    if (BOOST_VERBOSE >= 5) {
34
      watchdog('boost', 'Rules flushed !page from static page cache.', array('!page' => $page));
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    }
  }
}

/**
 * Action clear page from cache configuration form.
 */
function boost_rules_action_clear_page_form($settings, &$form) {
  $settings += array('page' => '');

  $form['settings']['page'] = array(
    '#type' => 'textarea',
    '#title' => t('Page URL'),
    '#default_value' => $settings['page'],
    '#description' => t('The short URL of the page to clear from the Boost cache.'),
  );
51 52 53 54 55 56
  $form['settings']['expire_now'] = array(
    '#type' => 'checkbox',
    '#title' => t('Clear cache file(s) immediately.'),
    '#default_value' => $settings['expire_now'],
    '#description' => t('If unchecked, cache file(s) will be cleared on the next cron run.'),
  );
57
}