Commit 65740f76 authored by xjm's avatar xjm

Issue #3052318 by AndyF, mikelutz, andypost, jungle, catch, AbdeI, mr_fenix,...

Issue #3052318 by AndyF, mikelutz, andypost, jungle, catch, AbdeI, mr_fenix, crifi, plach, xjm, vuil, amateescu, jedgar1mx, John_B, waverate, alexpott, owenbush, azovsky: Update from 8.6 to 8.7 fails due to corrupt  menu_link_content or taxonomy_term entity data
parent 786fd7c6
......@@ -5,6 +5,40 @@
* Install, update and uninstall functions for the menu_link_content module.
*/
/**
* Implements hook_requirements().
*/
function menu_link_content_requirements($phase) {
$requirements = [];
if ($phase === 'update') {
// Check for invalid data before making links revisionable.
/** @var \Drupal\Core\Update\UpdateRegistry $registry */
$registry = \Drupal::service('update.post_update_registry');
$update_name = 'menu_link_content_post_update_make_menu_link_content_revisionable';
if (in_array($update_name, $registry->getPendingUpdateFunctions(), TRUE)) {
// The 'enabled' field is non-NULL - if we get a NULL value that indicates
// a failure to join on menu_link_content_data.
$is_broken = \Drupal::entityQuery('menu_link_content')
->condition('enabled', NULL, 'IS NULL')
->range(0, 1)
->accessCheck(FALSE)
->execute();
if ($is_broken) {
$requirements[$update_name] = [
'title' => t('Menu link content data'),
'value' => t('Integrity issues detected'),
'description' => t('The make_menu_link_content_revisionable database update cannot be run until the data has been fixed. See the <a href=":change_record">change record</a> for more information.', [
':change_record' => 'https://www.drupal.org/node/3117753',
]),
'severity' => REQUIREMENT_ERROR,
];
}
}
}
return $requirements;
}
/**
* Implements hook_install().
*/
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\menu_link_content\Functional\Update;
use Drupal\Core\Database\Database;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\user\Entity\User;
......@@ -102,6 +103,36 @@ public function testConversionToRevisionable() {
$this->assertTrue($menu_link->isPublished());
}
/**
* Test the update hook requirements check for revisionable menu links.
*
* @see menu_link_content_post_update_make_menu_link_content_revisionable()
* @see menu_link_content_requirements()
*/
public function testMissingDataUpdateRequirementsCheck() {
// Insert invalid data for a non-existent menu link.
Database::getConnection()->insert('menu_link_content')
->fields([
'id' => '3',
'bundle' => 'menu_link_content',
'uuid' => '15396f85-3c11-4f52-81af-44d2cb5e829f',
'langcode' => 'en',
])
->execute();
$this->writeSettings([
'settings' => [
'update_free_access' => (object) [
'value' => TRUE,
'required' => TRUE,
],
],
]);
$this->drupalGet($this->updateUrl);
$this->assertSession()->pageTextContains('Errors found');
$this->assertSession()->elementTextContains('css', '.system-status-report__entry--error', 'The make_menu_link_content_revisionable database update cannot be run until the data has been fixed.');
}
/**
* {@inheritdoc}
*/
......
......@@ -9,6 +9,40 @@
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Site\Settings;
/**
* Implements hook_requirements().
*/
function taxonomy_requirements($phase) {
$requirements = [];
if ($phase === 'update') {
// Check for invalid data before making terms revisionable.
/** @var \Drupal\Core\Update\UpdateRegistry $registry */
$registry = \Drupal::service('update.post_update_registry');
$update_name = 'taxonomy_post_update_make_taxonomy_term_revisionable';
if (in_array($update_name, $registry->getPendingUpdateFunctions(), TRUE)) {
// The 'name' field is non-NULL - if we get a NULL value that indicates a
// failure to join on taxonomy_term_field_data.
$is_broken = \Drupal::entityQuery('taxonomy_term')
->condition('name', NULL, 'IS NULL')
->range(0, 1)
->accessCheck(FALSE)
->execute();
if ($is_broken) {
$requirements[$update_name] = [
'title' => t('Taxonomy term data'),
'value' => t('Integrity issues detected'),
'description' => t('The make_taxonomy_term_revisionable database update cannot be run until the data has been fixed. See the <a href=":change_record">change record</a> for more information.', [
':change_record' => 'https://www.drupal.org/node/3117753',
]),
'severity' => REQUIREMENT_ERROR,
];
}
}
}
return $requirements;
}
/**
* Convert the custom taxonomy term hierarchy storage to a default storage.
*/
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\taxonomy\Functional\Update;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\user\Entity\User;
......@@ -208,6 +209,36 @@ public function testConversionToRevisionable() {
$this->assertTrue($term->isPublished());
}
/**
* Test the update hook requirements check for revisionable terms.
*
* @see taxonomy_post_update_make_taxonomy_term_revisionable()
* @see taxonomy_requirements()
*/
public function testMissingDataUpdateRequirementsCheck() {
// Insert invalid data for a non-existent taxonomy term.
Database::getConnection()->insert('taxonomy_term_data')
->fields([
'tid' => '6',
'vid' => 'tags',
'uuid' => 'd5fd282b-df66-4d50-b0d1-76bf9eede9c5',
'langcode' => 'en',
])
->execute();
$this->writeSettings([
'settings' => [
'update_free_access' => (object) [
'value' => TRUE,
'required' => TRUE,
],
],
]);
$this->drupalGet($this->updateUrl);
$this->assertSession()->pageTextContains('Errors found');
$this->assertSession()->elementTextContains('css', '.system-status-report__entry--error', 'The make_taxonomy_term_revisionable database update cannot be run until the data has been fixed.');
}
/**
* {@inheritdoc}
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment