You are here

function drush_advagg_smart_cache_flush in Advanced CSS/JS Aggregation 7.2

Same name and namespace in other branches
  1. 8.2 advagg.drush.inc \drush_advagg_smart_cache_flush()

Flush the correct caches so CSS/JS changes go live.

1 string reference to 'drush_advagg_smart_cache_flush'
advagg_drush_cache_clear in ./advagg.drush.inc
Implements hook_drush_cache_clear().

File

./advagg.drush.inc, line 218
Drush commands for Advanced CSS/JS Aggregation.

Code

function drush_advagg_smart_cache_flush() {

  // Clear the libraries cache.
  if (function_exists('libraries_flush_caches')) {
    $cache_tables = libraries_flush_caches();
    foreach ($cache_tables as $table) {
      cache_clear_all('*', $table, TRUE);
    }
  }

  // Run the command.
  module_load_include('inc', 'advagg', 'advagg.cache');
  $flushed = advagg_push_new_changes();
  if (variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL) >= 0) {

    // Display a simple message if not in Development mode.
    drush_log('Advagg Cache Cleared', 'ok');
  }
  else {
    list($css_path) = advagg_get_root_files_dir();
    $parts_uri = $css_path[1] . '/parts';

    // Report back the results.
    foreach ($flushed as $filename => $data) {
      if (strpos($filename, $parts_uri) === 0) {

        // Do not report on css files manged in the parts directory.
        unset($flushed[$filename]);
        continue;
      }
      $ext = pathinfo($filename, PATHINFO_EXTENSION);
      drush_log(dt('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. Trigger: @changes', array(
        '@filename' => $filename,
        '@db_usage' => $data[0],
        '@db_count' => $data[1],
        '@changes' => print_r($data[2], TRUE),
        '@type' => $ext,
      )), 'ok');
    }
    if (empty($flushed)) {
      drush_log(dt('No changes found. Nothing was cleared.'), 'ok');
      return;
    }
  }
}