<?php
/**
* @file
* Provides drush overrides for cache rebuild cli tasks to fix D8 core cache rebuilding tasks.
*/
/**
* Execute script prior to cache-rebuild command.
*/
function drush_cli_pre_cache_rebuild() {
$domain=$_SERVER['HTTP_HOST'];
drush_log(dt(' Removing stale cache objects prior to rebuilding.'), 'ok');
$target_env = $_ENV['AH_SITE_GROUP'] .'.' . $_ENV['AH_SITE_ENVIRONMENT'];
// delete static twig storage
exec('drush @' . $target_env .' --uri=' . $domain . ' ev '\Drupal\Core\PhpStorage\PhpStorageFactory::get("twig")->deleteAll();'');
// Truncate theme cache tables in case cr ran prior in other deploy tasks.
$bins = [
'bootstrap',
'config',
'data',
'default',
'discovery',
'dynamic_page_cache',
'entity',
'menu',
'migrate',
'render',
'rest',
'toolbar',
];
foreach ($bins as $bin) {
if (\Drupal::hasService("cache.$bin")) {
\Drupal::cache($bin)->deleteAll();
}
}
drush_log(dt('Rebuilt cache data'), 'ok');
drupal_flush_all_caches();
}