You are here

public function OperationsForm::clearAggregates in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::clearAggregates()
  2. 8.2 src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::clearAggregates()

Clear out all advagg cache bins and clear out all advagg aggregated files.

2 calls to OperationsForm::clearAggregates()
OperationsForm::incrementCounter in src/Form/OperationsForm.php
Increment the global counter. Also full cache clear.
OperationsForm::toggleBypassCookie in src/Form/OperationsForm.php
Set or remove the AdvAggDisabled cookie.

File

src/Form/OperationsForm.php, line 255

Class

OperationsForm
Configure advagg settings for this site.

Namespace

Drupal\advagg\Form

Code

public function clearAggregates() {

  // 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->messenger
    ->addMessage($this
    ->t('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,
  ]));
}