Skip to content
Snippets Groups Projects
Commit b85de9ac authored by Adam G-H's avatar Adam G-H
Browse files

Make the updatedb pre-command hook clear plugin discovery caches only, rather than all caches.

parent 67c622e7
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ services:
arguments:
- '@extension.list.profile'
- '%install_profile%'
- '@plugin.cache_clearer'
tags:
- { name: drush.command }
......
......@@ -5,6 +5,7 @@ namespace Drupal\lightning_core\Commands;
use Consolidation\AnnotatedCommand\CommandData;
use Consolidation\OutputFormatters\Options\FormatterOptions;
use Drupal\Core\Extension\ProfileExtensionList;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drush\Commands\DrushCommands;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
......@@ -27,6 +28,13 @@ class Hooks extends DrushCommands {
*/
private $installProfile;
/**
* The plugin cache clearer service.
*
* @var \Drupal\Core\Plugin\CachedDiscoveryClearerInterface
*/
private $pluginCacheClearer;
/**
* Hooks constructor.
*
......@@ -34,25 +42,32 @@ class Hooks extends DrushCommands {
* The profile extension list service.
* @param string $install_profile
* The install_profile parameter.
* @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer
* The plugin cache clearer service.
*/
public function __construct(ProfileExtensionList $profile_list, $install_profile) {
public function __construct(ProfileExtensionList $profile_list, $install_profile, CachedDiscoveryClearerInterface $plugin_cache_clearer) {
$this->profileList = $profile_list;
$this->installProfile = $install_profile;
$this->pluginCacheClearer = $plugin_cache_clearer;
}
/**
* Clears all caches before database updates begin.
* 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. Clearing all caches before updates begin ensures that
* the system always has the freshest and most accurate data to work with,
* which is especially helpful during major surgery like a database update.
* 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() {
drupal_flush_all_caches();
$this->pluginCacheClearer->clearCachedDefinitions();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment