Issue #3052147 by Sam152, amateescu, Dropa, alexpott, larowlan, catch, xjm: comment_update_8701 fails if there are comments without field_name
parent
28ce151a65
commit
e52604b4d2
|
|
@ -11,6 +11,33 @@ use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
|
|||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
function comment_requirements($phase) {
|
||||
$requirements = [];
|
||||
if ($phase === 'update' && drupal_get_installed_schema_version('comment') < 8701) {
|
||||
$has_empty_columns = \Drupal::entityQuery('comment', 'OR')
|
||||
->condition('entity_type', NULL, 'IS NULL')
|
||||
->condition('field_name', NULL, 'IS NULL')
|
||||
->range(0, 1)
|
||||
->accessCheck(FALSE)
|
||||
->execute();
|
||||
if ($has_empty_columns) {
|
||||
$requirements['comment_update_8701'] = [
|
||||
'title' => t('Comment required fields update'),
|
||||
'description' => t('The comment_update_8701() function requires that the %field_1 and %field_2 fields have values for all comment entities. See the <a href=":change_record">change record</a> for more information.', [
|
||||
'%field_1' => 'entity_type',
|
||||
'%field_2' => 'field_name',
|
||||
':change_record' => 'https://www.drupal.org/node/3053046',
|
||||
]),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
];
|
||||
}
|
||||
}
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
|
|
|
|||
128
core/modules/comment/tests/fixtures/update/drupal-8.empty-comment-fields.3052147.php
vendored
Normal file
128
core/modules/comment/tests/fixtures/update/drupal-8.empty-comment-fields.3052147.php
vendored
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains database additions to drupal-8-rc1.filled.standard.php.gz for the
|
||||
* upgrade path in https://www.drupal.org/project/drupal/issues/2885809.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
$connection->insert('comment')
|
||||
->fields([
|
||||
'cid',
|
||||
'comment_type',
|
||||
'uuid',
|
||||
'langcode',
|
||||
])
|
||||
->values([
|
||||
'cid' => '5',
|
||||
'comment_type' => 'comment',
|
||||
'uuid' => '2f0505ad-fdc7-49fc-9d39-571bfc3e0f88',
|
||||
'langcode' => 'en',
|
||||
])
|
||||
->values([
|
||||
'cid' => '6',
|
||||
'comment_type' => 'comment',
|
||||
'uuid' => '3be94e6b-4506-488a-a861-9742a18f0507',
|
||||
'langcode' => 'en',
|
||||
])
|
||||
->execute();
|
||||
|
||||
$connection->insert('comment__comment_body')
|
||||
->fields([
|
||||
'bundle',
|
||||
'deleted',
|
||||
'entity_id',
|
||||
'revision_id',
|
||||
'langcode',
|
||||
'delta',
|
||||
'comment_body_value',
|
||||
'comment_body_format',
|
||||
])
|
||||
->values([
|
||||
'bundle' => 'comment',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '5',
|
||||
'revision_id' => '5',
|
||||
'langcode' => 'en',
|
||||
'delta' => '0',
|
||||
'comment_body_value' => "<p>Comment body</p>\r\n",
|
||||
'comment_body_format' => 'basic_html',
|
||||
])
|
||||
->values([
|
||||
'bundle' => 'comment',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '6',
|
||||
'revision_id' => '6',
|
||||
'langcode' => 'en',
|
||||
'delta' => '0',
|
||||
'comment_body_value' => "<p>Comment body</p>\r\n",
|
||||
'comment_body_format' => 'basic_html',
|
||||
])
|
||||
->execute();
|
||||
|
||||
$connection->insert('comment_field_data')
|
||||
->fields([
|
||||
'cid',
|
||||
'comment_type',
|
||||
'langcode',
|
||||
'pid',
|
||||
'entity_id',
|
||||
'subject',
|
||||
'uid',
|
||||
'name',
|
||||
'mail',
|
||||
'homepage',
|
||||
'hostname',
|
||||
'created',
|
||||
'changed',
|
||||
'status',
|
||||
'thread',
|
||||
'entity_type',
|
||||
'field_name',
|
||||
'default_langcode',
|
||||
])
|
||||
->values([
|
||||
'cid' => '5',
|
||||
'comment_type' => 'comment',
|
||||
'langcode' => 'en',
|
||||
'pid' => NULL,
|
||||
'entity_id' => '8',
|
||||
'subject' => 'Comment with no entity_type',
|
||||
'uid' => '1',
|
||||
'name' => 'drupal',
|
||||
'mail' => NULL,
|
||||
'homepage' => NULL,
|
||||
'hostname' => '127.0.0.1',
|
||||
'created' => '1557218256',
|
||||
'changed' => '1557218256',
|
||||
'status' => '1',
|
||||
'thread' => '02/',
|
||||
'entity_type' => NULL,
|
||||
'field_name' => 'field_test_2',
|
||||
'default_langcode' => '1',
|
||||
])
|
||||
->values([
|
||||
'cid' => '6',
|
||||
'comment_type' => 'comment',
|
||||
'langcode' => 'en',
|
||||
'pid' => NULL,
|
||||
'entity_id' => '8',
|
||||
'subject' => 'Comment with no field_name',
|
||||
'uid' => '1',
|
||||
'name' => 'drupal',
|
||||
'mail' => NULL,
|
||||
'homepage' => NULL,
|
||||
'hostname' => '127.0.0.1',
|
||||
'created' => '1557218266',
|
||||
'changed' => '1557218266',
|
||||
'status' => '1',
|
||||
'thread' => '03/',
|
||||
'entity_type' => 'node',
|
||||
'field_name' => NULL,
|
||||
'default_langcode' => '1',
|
||||
])
|
||||
->execute();
|
||||
|
|
@ -118,4 +118,25 @@ class CommentUpdateTest extends UpdatePathTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the update hook requirements check for 8701.
|
||||
*
|
||||
* @see comment_update_8701()
|
||||
* @see comment_requirements()
|
||||
*/
|
||||
public function testCommentEntityTypeAndFieldUpdateRequirementsCheck() {
|
||||
require_once __DIR__ . '/../../../fixtures/update/drupal-8.empty-comment-fields.3052147.php';
|
||||
$this->writeSettings([
|
||||
'settings' => [
|
||||
'update_free_access' => (object) [
|
||||
'value' => TRUE,
|
||||
'required' => TRUE,
|
||||
],
|
||||
],
|
||||
]);
|
||||
$this->drupalGet($this->updateUrl);
|
||||
$this->assertSession()->pageTextContains('Errors found');
|
||||
$this->assertSession()->elementContains('css', '.system-status-report__entry--error', 'The comment_update_8701() function requires that the <em class="placeholder">entity_type</em> and <em class="placeholder">field_name</em> fields have values for all comment entities.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue