You are here

class Hooks in Lightning Core 8.3

Same name and namespace in other branches
  1. 8.5 src/Commands/Hooks.php \Drupal\lightning_core\Commands\Hooks
  2. 8.2 src/Commands/Hooks.php \Drupal\lightning_core\Commands\Hooks
  3. 8.4 src/Commands/Hooks.php \Drupal\lightning_core\Commands\Hooks

Implements Drush command hooks.

Hierarchy

  • class \Drupal\lightning_core\Commands\Hooks extends \Drush\Commands\DrushCommands

Expanded class hierarchy of Hooks

1 string reference to 'Hooks'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses Hooks
lightning_core.hooks in ./drush.services.yml
\Drupal\lightning_core\Commands\Hooks

File

src/Commands/Hooks.php, line 11

Namespace

Drupal\lightning_core\Commands
View source
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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Hooks::$pluginCacheClearer private property The plugin cache clearer service.
Hooks::preUpdate public function Clears all plugin caches before database updates begin.
Hooks::__construct public function Hooks constructor.