Hooks.php in Lightning Core 8.3
Same filename and directory in other branches
Namespace
Drupal\lightning_core\CommandsFile
src/Commands/Hooks.phpView source
<?php
namespace Drupal\lightning_core\Commands;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drush\Commands\DrushCommands;
/**
* Implements Drush command hooks.
*/
class Hooks extends DrushCommands {
/**
* The plugin cache clearer service.
*
* @var \Drupal\Core\Plugin\CachedDiscoveryClearerInterface
*/
private $pluginCacheClearer;
/**
* Hooks constructor.
*
* @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer
* The plugin cache clearer service.
*/
public function __construct(CachedDiscoveryClearerInterface $plugin_cache_clearer) {
$this->pluginCacheClearer = $plugin_cache_clearer;
}
/**
* Clears all plugin caches before database updates begin.
*
* A common cause of errors during database updates is update hooks
* inadvertently using stale data from the myriad caches in Drupal core and
* contributed modules. To migitate this, we do a bit of cache pruning before
* database updates begin.
*
* drupal_flush_all_caches() is extremely aggressive because it rebuilds the
* router and other things, but it's a bit too much of a sledgehammer for our
* purposes. A good compromise is to clear all plugin discovery caches (which
* will include entity type definitions).
*
* @hook pre-command updatedb
*/
public function preUpdate() {
$this->pluginCacheClearer
->clearCachedDefinitions();
}
}