Issue #3065663 by phenaproxima, alexpott, amateescu, tim.plunkett, Wim Leers: Several post-update functions try to update config entity types without checking if they exist
parent
7cb3afdcdd
commit
24d99ffdb1
|
|
@ -11,8 +11,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*
|
||||
* Use this in a post update function like so:
|
||||
* @code
|
||||
* // Update the dependencies of all Vocabulary configuration entities.
|
||||
* \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'taxonomy_vocabulary');
|
||||
* // Ensure Taxonomy module installed before trying to update vocabularies.
|
||||
* if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
|
||||
* // Update the dependencies of all Vocabulary configuration entities.
|
||||
* \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'taxonomy_vocabulary');
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* The number of entities processed in each batch is determined by the
|
||||
|
|
@ -65,6 +68,9 @@ class ConfigEntityUpdater implements ContainerInjectionInterface {
|
|||
* Stores information for batch updates.
|
||||
* @param string $entity_type_id
|
||||
* The configuration entity type ID. For example, 'view' or 'vocabulary'.
|
||||
* The calling code should ensure that the entity type exists beforehand
|
||||
* (i.e., by checking that the entity type is defined or that the module
|
||||
* that provides it is installed).
|
||||
* @param callable $callback
|
||||
* (optional) A callback to determine if a configuration entity should be
|
||||
* saved. The callback will be passed each entity of the provided type that
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
|||
* Adds a 'reusable' filter to all Custom Block views.
|
||||
*/
|
||||
function block_content_post_update_add_views_reusable_filter(&$sandbox = NULL) {
|
||||
// If Views is not installed, there is nothing to do.
|
||||
if (!\Drupal::moduleHandler()->moduleExists('views')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity_type = \Drupal::entityTypeManager()->getDefinition('block_content');
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('block_content');
|
||||
|
||||
|
|
|
|||
|
|
@ -150,4 +150,12 @@ class BlockContentReusableUpdateTest extends UpdatePathTestBase {
|
|||
$assert_session->statusCodeEquals('403');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the update succeeds even if Views is not installed.
|
||||
*/
|
||||
public function testReusableFieldAdditionWithoutViews() {
|
||||
$this->container->get('module_installer')->uninstall(['views']);
|
||||
$this->runUpdates();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,6 +175,11 @@ function content_moderation_post_update_entity_display_dependencies(&$sandbox) {
|
|||
* Update the moderation state views field plugin ID.
|
||||
*/
|
||||
function content_moderation_post_update_views_field_plugin_id(&$sandbox) {
|
||||
// If Views is not installed, there is nothing to do.
|
||||
if (!\Drupal::moduleHandler()->moduleExists('views')) {
|
||||
return;
|
||||
}
|
||||
|
||||
\Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'view', function ($view) {
|
||||
/** @var \Drupal\views\ViewEntityInterface $view */
|
||||
$updated = FALSE;
|
||||
|
|
|
|||
|
|
@ -39,4 +39,12 @@ class ModerationStateViewsFieldUpdateTest extends UpdatePathTestBase {
|
|||
$this->assertEquals('moderation_state_field', $views_display['display_options']['fields']['moderation_state']['plugin_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the update succeeds even if Views is not installed.
|
||||
*/
|
||||
public function testViewsFieldIdUpdateWithoutViews() {
|
||||
$this->container->get('module_installer')->uninstall(['views']);
|
||||
$this->runUpdates();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ function taxonomy_post_update_clear_entity_bundle_field_definitions_cache() {
|
|||
* existing ones that were using the 'content_translation_status' field.
|
||||
*/
|
||||
function taxonomy_post_update_handle_publishing_status_addition_in_views(&$sandbox = NULL) {
|
||||
// If Views is not installed, there is nothing to do.
|
||||
if (!\Drupal::moduleHandler()->moduleExists('views')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$entity_type = $definition_update_manager->getEntityType('taxonomy_term');
|
||||
$published_key = $entity_type->getKey('published');
|
||||
|
|
|
|||
|
|
@ -91,6 +91,22 @@ class TaxonomyTermUpdatePathTest extends UpdatePathTestBase {
|
|||
$this->assertEquals('Another message', (string) taxonomy_update_8601());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests taxonomy term views updates succeed even if Views is not installed.
|
||||
*/
|
||||
public function testPublishingStatusUpdateForTaxonomyTermViewsWithoutViews() {
|
||||
// Uninstalling Views will trigger some activity in the menu tree storage
|
||||
// system, which will cause errors until system_update_8001() is run. This
|
||||
// is because, in the drupal-8.filled.standard database fixture used for
|
||||
// this update test, the menu link titles are not serialized (this is what
|
||||
// gets done by system_update_8001()). Since this method is not testing
|
||||
// anything relating to menu links, it's OK to just truncate the menu_tree
|
||||
// table before uninstalling Views.
|
||||
$this->container->get('database')->truncate('menu_tree')->execute();
|
||||
$this->container->get('module_installer')->uninstall(['views']);
|
||||
$this->runUpdates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests handling of the publishing status in taxonomy term views updates.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -36,4 +36,18 @@ class ExposedFilterBlocksUpdateTest extends UpdatePathTestBase {
|
|||
$this->assertEquals('0', $config['label_display']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the update succeeds even if Block is not installed.
|
||||
*/
|
||||
public function testViewsPostUpdateExposedFilterBlocksWithoutBlock() {
|
||||
// This block is created during the update process, but since we are
|
||||
// uninstalling the Block module for this test, it will fail config schema
|
||||
// validation. Since that's okay for the purposes of this test, just make
|
||||
// the config schema checker ignore the block.
|
||||
static::$configSchemaCheckerExclusions[] = 'block.block.seven_secondary_local_tasks';
|
||||
|
||||
$this->container->get('module_installer')->uninstall(['block']);
|
||||
$this->runUpdates();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -371,6 +371,11 @@ function views_post_update_table_display_cache_max_age(&$sandbox = NULL) {
|
|||
* Update exposed filter blocks label display to be disabled.
|
||||
*/
|
||||
function views_post_update_exposed_filter_blocks_label_display(&$sandbox = NULL) {
|
||||
// If Block is not installed, there's nothing to do.
|
||||
if (!\Drupal::moduleHandler()->moduleExists('block')) {
|
||||
return;
|
||||
}
|
||||
|
||||
\Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'block', function ($block) {
|
||||
/** @var \Drupal\block\BlockInterface $block */
|
||||
if (strpos($block->getPluginId(), 'views_exposed_filter_block:') === 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue