You are here

function drush_advagg_clear_all_files in Advanced CSS/JS Aggregation 8.4

Same name and namespace in other branches
  1. 8.2 advagg.drush.inc \drush_advagg_clear_all_files()
  2. 8.3 advagg.drush.inc \drush_advagg_clear_all_files()
  3. 7.2 advagg.drush.inc \drush_advagg_clear_all_files()

Callback function for drush advagg-clear-all-files.

Related topics

1 call to drush_advagg_clear_all_files()
drush_advagg_force_new_aggregates in ./advagg.drush.inc
Callback function for drush advagg-force-new-aggregates.

File

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

Code

function drush_advagg_clear_all_files() {
  $file_system = \Drupal::service('file_system');

  // Clear out the cache.
  Cache::invalidateTags([
    'library_info',
  ]);
  \Drupal::cache('advagg')
    ->invalidateAll();
  $pub = $file_system
    ->realpath('public://');
  $css_count = count(glob($pub . '/css/optimized/*.css'));
  $js_count = count(glob($pub . '/js/optimized/*.js'));
  foreach ([
    'public://js/optimized',
    'public://css/optimized',
  ] as $path) {
    if (file_exists($path)) {
      $file_system
        ->deleteRecursive($path);
    }
  }

  // Report back the results.
  \Drupal::logger(dt('All AdvAgg optimized files have been deleted. %css_count CSS files and %js_count JS files have been removed.', [
    '%css_count' => $css_count,
    '%js_count' => $js_count,
  ]));
}