Skip to content

Commit

Permalink
Issue #3052318 by AndyF, mikelutz, andypost, jungle, AbdeI, mr_fenix,…
Browse files Browse the repository at this point in the history
… crifi, plach, catch, 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
  • Loading branch information
xjm committed Mar 8, 2020
1 parent d250735 commit b380cb1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
34 changes: 34 additions & 0 deletions modules/menu_link_content/menu_link_content.install
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
* Add the publishing status entity key to custom menu links.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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}
*/
Expand Down
34 changes: 34 additions & 0 deletions modules/taxonomy/taxonomy.install
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@ use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
*/
Expand Down

0 comments on commit b380cb1

Please sign in to comment.