You are here

public function AdvaggCommands::clearAllFiles in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 src/Commands/AdvaggCommands.php \Drupal\advagg\Commands\AdvaggCommands::clearAllFiles()

Remove all generated files.

@command advagg-clear-all-files @usage Standard example drush advagg-clear-all-files @aliases advagg-caf

1 call to AdvaggCommands::clearAllFiles()
AdvaggCommands::forceNewAggregates in src/Commands/AdvaggCommands.php
Force the creation of all new files by incrementing a global counter.

File

src/Commands/AdvaggCommands.php, line 110

Class

AdvaggCommands
Advagg commands for Drush 9+.

Namespace

Drupal\advagg\Commands

Code

public function clearAllFiles() {

  // Clear out the cache.
  Cache::invalidateTags([
    'library_info',
  ]);
  $this->cache
    ->invalidateAll();
  $pub = $this->fileSystem
    ->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_unmanaged_delete_recursive($path);
    }
  }

  // Report back the results.
  $this
    ->logger()
    ->notice(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,
  ]));
}