diff -u b/core/modules/comment/tests/src/Functional/CommentOrphanedTest.php b/core/modules/comment/tests/src/Functional/CommentOrphanedTest.php --- b/core/modules/comment/tests/src/Functional/CommentOrphanedTest.php +++ b/core/modules/comment/tests/src/Functional/CommentOrphanedTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\comment\Functional; -use Drupal\comment\CommentStorage; use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; use Drupal\Tests\EntityViewTrait; @@ -97,55 +95,0 @@ - - /** - * Comment storage handler for creating orphan comments. - */ -class CommentTestSqlEntityStorage extends CommentStorage { - - /** - * Creates orphaned comments. - * - * Intentionally makes reference data (commented entity, parent comment, - * author) invalid, in the SQL storage backend. - * - * @param array $comment_ids - * IDs of comments to orphan. If empty, invalidate the most recent comment. - * @param array $fields - * Names of fields to change. Allowed values: 'pid', 'entity_id', 'uid'. If - * empty, all fields will be changed. - */ - public function orphanComments(array $comment_ids = [], array $fields = []) { - - // Get the maximum parent/author and set it one higher; this emulates - // a parent/author which has been deleted after creating. - $query = $this->database->select('comment_field_data', 'c'); - $query->addExpression('MAX(cid)', 'cid_max'); - $query->addExpression('MAX(pid)', 'pid_max'); - $query->addExpression('MAX(uid)', 'uid_max'); - $query->addExpression('MAX(entity_id)', 'entity_id_max'); - $row = $query->execute()->fetchObject(); - if (!isset($row->pid_max) && isset($row->cid_max)) { - $row->pid_max = $row->cid_max; - } - - if (empty($comment_ids) && isset($row->cid_max)) { - $comment_ids = [$row->cid_max]; - } - - if (!empty($comment_ids)) { - $update_values = [ - 'entity_id' => $row->entity_id_max + 1, - 'pid' => $row->cid_max + 1, - 'uid' => $row->uid_max + 1, - ]; - if ($fields) { - $update_values = array_intersect_key($update_values, array_flip($fields)); - } - $this->database->update('comment_field_data') - ->fields($update_values) - ->condition('cid', $comment_ids) - ->execute(); - - $this->resetCache(); - } - } - -} only in patch2: unchanged: --- /dev/null +++ b/core/modules/comment/tests/src/Functional/CommentTestSqlEntityStorage.php @@ -0,0 +1,60 @@ +database->select('comment_field_data', 'c'); + $query->addExpression('MAX(cid)', 'cid_max'); + $query->addExpression('MAX(pid)', 'pid_max'); + $query->addExpression('MAX(uid)', 'uid_max'); + $query->addExpression('MAX(entity_id)', 'entity_id_max'); + $row = $query->execute()->fetchObject(); + if (!isset($row->pid_max) && isset($row->cid_max)) { + $row->pid_max = $row->cid_max; + } + + if (empty($comment_ids) && isset($row->cid_max)) { + $comment_ids = [$row->cid_max]; + } + + if (!empty($comment_ids)) { + $update_values = [ + 'entity_id' => $row->entity_id_max + 1, + 'pid' => $row->cid_max + 1, + 'uid' => $row->uid_max + 1, + ]; + if ($fields) { + $update_values = array_intersect_key($update_values, array_flip($fields)); + } + $this->database->update('comment_field_data') + ->fields($update_values) + ->condition('cid', $comment_ids) + ->execute(); + + $this->resetCache(); + } + } + +}