From be70033ea1e33da35d2fcc545714ef644df6f262 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 13 Dec 2013 13:45:37 +0000 Subject: [PATCH] Issue #2151427 by andypost, TR: Convert COMMENT_NOT_PUBLISHED & COMMENT_PUBLISHED to a constant on the comment interface. --- core/modules/comment/comment.admin.inc | 8 +++-- core/modules/comment/comment.module | 32 +++++++------------ .../comment/CommentAccessController.php | 2 +- .../Drupal/comment/CommentFormController.php | 10 +++--- .../lib/Drupal/comment/CommentInterface.php | 10 ++++++ .../comment/CommentStorageController.php | 4 +-- .../CommentStorageControllerInterface.php | 1 - .../lib/Drupal/comment/CommentViewBuilder.php | 2 +- .../comment/Controller/CommentController.php | 4 +-- .../lib/Drupal/comment/Entity/Comment.php | 4 +-- .../comment/Plugin/Action/PublishComment.php | 3 +- .../Action/UnpublishByKeywordComment.php | 3 +- .../Plugin/Action/UnpublishComment.php | 3 +- .../selection/CommentSelection.php | 3 +- .../Plugin/views/field/LinkApprove.php | 3 +- .../Plugin/views/field/NodeNewComments.php | 3 +- .../comment/Tests/CommentActionsTest.php | 10 +++--- .../Drupal/comment/Tests/CommentCSSTest.php | 9 +++--- .../comment/Tests/CommentInterfaceTest.php | 4 ++- .../Drupal/comment/Tests/CommentLinksTest.php | 3 +- .../comment/Tests/CommentNewIndicatorTest.php | 3 +- .../EntityReferenceSelectionAccessTest.php | 7 ++-- .../forum/lib/Drupal/forum/ForumManager.php | 5 +-- .../Drupal/forum/Tests/ForumUninstallTest.php | 3 +- .../Drupal/node/Tests/NodeAccessPagerTest.php | 3 +- .../Tests/Theme/EntityFilteringThemeTest.php | 3 +- .../lib/Drupal/tracker/Tests/TrackerTest.php | 3 +- core/modules/tracker/tracker.module | 9 +++--- 28 files changed, 89 insertions(+), 68 deletions(-) diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 8f618e52f99a..99bb6b0a31f2 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -5,6 +5,8 @@ * Admin page callbacks for the Comment module. */ +use Drupal\comment\CommentInterface; + /** * Page callback: Presents an administrative comment listing. * @@ -70,7 +72,7 @@ function comment_admin_overview($form, &$form_state, $arg) { ); // Load the comments that need to be displayed. - $status = ($arg == 'approval') ? COMMENT_NOT_PUBLISHED : COMMENT_PUBLISHED; + $status = ($arg == 'approval') ? CommentInterface::NOT_PUBLISHED : CommentInterface::PUBLISHED; $header = array( 'subject' => array('data' => t('Subject'), 'field' => 'subject'), 'author' => array('data' => t('Author'), 'field' => 'name', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), @@ -218,10 +220,10 @@ function comment_admin_overview_submit($form, &$form_state) { $comment = comment_load($value); if ($operation == 'unpublish') { - $comment->status->value = COMMENT_NOT_PUBLISHED; + $comment->status->value = CommentInterface::NOT_PUBLISHED; } elseif ($operation == 'publish') { - $comment->status->value = COMMENT_PUBLISHED; + $comment->status->value = CommentInterface::PUBLISHED; } $comment->save(); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8debaef99c6f..145690b34f01 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -19,16 +19,6 @@ use Drupal\field\FieldInterface; use Drupal\file\FileInterface; -/** - * Comment is awaiting approval. - */ -const COMMENT_NOT_PUBLISHED = 0; - -/** - * Comment is published. - */ -const COMMENT_PUBLISHED = 1; - /** * Comments are displayed in a flat list - expanded. */ @@ -232,7 +222,7 @@ function comment_menu_alter(&$items) { */ function comment_count_unpublished() { $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array( - ':status' => COMMENT_NOT_PUBLISHED, + ':status' => CommentInterface::NOT_PUBLISHED, ))->fetchField(); return t('Unapproved comments (@count)', array('@count' => $count)); } @@ -328,7 +318,7 @@ function comment_get_recent($number = 10) { $query = db_select('comment', 'c'); $query->addMetaData('base_table', 'comment'); $query->fields('c') - ->condition('c.status', COMMENT_PUBLISHED); + ->condition('c.status', CommentInterface::PUBLISHED); if (\Drupal::moduleHandler()->moduleExists('node')) { // Special case to filter by published content. $query->innerJoin('node_field_data', 'n', "n.nid = c.entity_id AND c.entity_type = 'node'"); @@ -391,7 +381,7 @@ function comment_new_page_count($num_comments, $new_replies, EntityInterface $en ->condition('entity_id', $entity->id()) ->condition('entity_type', $entity->entityType()) ->condition('field_id', $entity->entityType() . '__' . $field_name) - ->condition('status', COMMENT_PUBLISHED) + ->condition('status', CommentInterface::PUBLISHED) ->orderBy('created', 'DESC') ->orderBy('cid', 'DESC') ->range(0, $new_replies); @@ -412,7 +402,7 @@ function comment_new_page_count($num_comments, $new_replies, EntityInterface $en AND entity_type = :entity_type AND field_id = :field_id AND status = :status AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array( - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ':entity_id' => $entity->id(), ':field_id' => $entity->entityType() . '__' . $field_name, ':entity_type' => $entity->entityType(), @@ -722,8 +712,8 @@ function comment_get_thread(EntityInterface $entity, $field_name, $mode, $commen ->addMetaData('field_name', $field_name); if (!user_access('administer comments')) { - $query->condition('c.status', COMMENT_PUBLISHED); - $count_query->condition('c.status', COMMENT_PUBLISHED); + $query->condition('c.status', CommentInterface::PUBLISHED); + $count_query->condition('c.status', CommentInterface::PUBLISHED); } if ($mode == COMMENT_MODE_FLAT) { $query->orderBy('c.cid', 'ASC'); @@ -1195,7 +1185,7 @@ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestam $query->addExpression('COUNT(cid)'); $query->condition('c.entity_type', $entity_type) ->condition('c.entity_id', $entity_id) - ->condition('c.status', COMMENT_PUBLISHED) + ->condition('c.status', CommentInterface::PUBLISHED) ->condition('c.created', $timestamp, '>'); if ($field_name) { // Limit to a particular field. @@ -1236,7 +1226,7 @@ function comment_get_display_ordinal($cid, $instance) { $query->addExpression('COUNT(*)', 'count'); $query->condition('c2.cid', $cid); if (!user_access('administer comments')) { - $query->condition('c1.status', COMMENT_PUBLISHED); + $query->condition('c1.status', CommentInterface::PUBLISHED); } if ($instance->getSetting('default_mode') == COMMENT_MODE_FLAT) { @@ -1313,7 +1303,7 @@ function comment_preview(CommentInterface $comment, array &$form_state) { if ($comment->pid->target_id) { $build = array(); $parent = $comment->pid->entity; - if ($parent && $parent->status->value == COMMENT_PUBLISHED) { + if ($parent && $parent->status->value == CommentInterface::PUBLISHED) { $build = comment_view($parent); } } @@ -1478,7 +1468,7 @@ function template_preprocess_comment(&$variables) { $variables['status'] = 'preview'; } else { - $variables['status'] = ($comment->status->value == COMMENT_NOT_PUBLISHED) ? 'unpublished' : 'published'; + $variables['status'] = ($comment->status->value == CommentInterface::NOT_PUBLISHED) ? 'unpublished' : 'published'; } // Gather comment classes. @@ -1659,7 +1649,7 @@ function comment_ranking() { */ function comment_file_download_access($field, EntityInterface $entity, FileInterface $file) { if ($entity->entityType() == 'comment') { - if (user_access('access comments') && $entity->status->value == COMMENT_PUBLISHED || user_access('administer comments')) { + if (user_access('access comments') && $entity->status->value == CommentInterface::PUBLISHED || user_access('administer comments')) { $commented_entity = entity_load($entity->entity_type->value, $entity->entity_id->value); // Check access to parent entity. return $commented_entity->access('view'); diff --git a/core/modules/comment/lib/Drupal/comment/CommentAccessController.php b/core/modules/comment/lib/Drupal/comment/CommentAccessController.php index 800991f6fa0e..ce25a1caeba3 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentAccessController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentAccessController.php @@ -28,7 +28,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A break; case 'update': - return ($account->id() && $account->id() == $entity->uid->value && $entity->status->value == COMMENT_PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account); + return ($account->id() && $account->id() == $entity->uid->value && $entity->status->value == CommentInterface::PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account); break; case 'delete': diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index d0066a89810a..8a5d52f9c8a4 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -117,7 +117,7 @@ public function form(array $form, array &$form_state) { // Prepare default values for form elements. if ($is_admin) { $author = $comment->name->value; - $status = (isset($comment->status->value) ? $comment->status->value : COMMENT_NOT_PUBLISHED); + $status = (isset($comment->status->value) ? $comment->status->value : CommentInterface::NOT_PUBLISHED); if (empty($form_state['comment_preview'])) { $form['#title'] = $this->t('Edit comment %title', array( '%title' => $comment->subject->value, @@ -131,7 +131,7 @@ public function form(array $form, array &$form_state) { else { $author = ($comment->name->value ? $comment->name->value : ''); } - $status = ($this->currentUser->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED); + $status = ($this->currentUser->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED); } $date = ''; @@ -195,8 +195,8 @@ public function form(array $form, array &$form_state) { '#title' => $this->t('Status'), '#default_value' => $status, '#options' => array( - COMMENT_PUBLISHED => $this->t('Published'), - COMMENT_NOT_PUBLISHED => $this->t('Not published'), + CommentInterface::PUBLISHED => $this->t('Published'), + CommentInterface::NOT_PUBLISHED => $this->t('Not published'), ), '#access' => $is_admin, ); @@ -383,7 +383,7 @@ public function save(array $form, array &$form_state) { watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->subject->value), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id()))); // Explain the approval queue if necessary. - if ($comment->status->value == COMMENT_NOT_PUBLISHED) { + if ($comment->status->value == CommentInterface::NOT_PUBLISHED) { if (!$this->currentUser->hasPermission('administer comments')) { drupal_set_message($this->t('Your comment has been queued for review by site administrators and will be published after approval.')); } diff --git a/core/modules/comment/lib/Drupal/comment/CommentInterface.php b/core/modules/comment/lib/Drupal/comment/CommentInterface.php index fe7f40d0c2df..28ec9fb4359e 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php @@ -15,6 +15,16 @@ */ interface CommentInterface extends ContentEntityInterface, EntityChangedInterface { + /** + * Comment is awaiting approval. + */ + const NOT_PUBLISHED = 0; + + /** + * Comment is published. + */ + const PUBLISHED = 1; + /** * Returns the permalink URL for this comment. * diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 0d93c6560879..e23af78c7dfa 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -62,7 +62,7 @@ public function updateEntityStatistics(CommentInterface $comment) { $count = $query->condition('c.entity_id', $comment->entity_id->value) ->condition('c.entity_type', $comment->entity_type->value) ->condition('c.field_id', $comment->field_id->value) - ->condition('c.status', COMMENT_PUBLISHED) + ->condition('c.status', CommentInterface::PUBLISHED) ->execute() ->fetchField(); @@ -73,7 +73,7 @@ public function updateEntityStatistics(CommentInterface $comment) { ->condition('c.entity_id', $comment->entity_id->value) ->condition('c.entity_type', $comment->entity_type->value) ->condition('c.field_id', $comment->field_id->value) - ->condition('c.status', COMMENT_PUBLISHED) + ->condition('c.status', CommentInterface::PUBLISHED) ->orderBy('c.created', 'DESC') ->range(0, 1) ->execute() diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php b/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php index 69ba909d43a3..4583f20883c0 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php @@ -9,7 +9,6 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; -use Drupal\comment\CommentInterface; /** * Defines a common interface for comment entity controller classes. diff --git a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php index be9c41f27dde..dc4cd61f4c4d 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php @@ -231,7 +231,7 @@ protected static function buildLinks(CommentInterface $entity, EntityInterface $ 'html' => TRUE, ); } - if ($entity->status->value == COMMENT_NOT_PUBLISHED && $entity->access('approve')) { + if ($entity->status->value == CommentInterface::NOT_PUBLISHED && $entity->access('approve')) { $links['comment-approve'] = array( 'title' => t('Approve'), 'route_name' => 'comment.approve', diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index ccb3a4aee3f5..b1b127f8bb1a 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -97,7 +97,7 @@ public static function create(ContainerInterface $container) { * @return \Symfony\Component\HttpFoundation\RedirectResponse. */ public function commentApprove(CommentInterface $comment) { - $comment->status->value = COMMENT_PUBLISHED; + $comment->status->value = CommentInterface::PUBLISHED; $comment->save(); drupal_set_message($this->t('Comment approved.')); @@ -246,7 +246,7 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_ // Load the parent comment. $comment = $this->entityManager()->getStorageController('comment')->load($pid); // Check if the parent comment is published and belongs to the current nid. - if (($comment->status->value == COMMENT_NOT_PUBLISHED) || ($comment->entity_id->value != $entity->id())) { + if (($comment->status->value == CommentInterface::NOT_PUBLISHED) || ($comment->entity_id->value != $entity->id())) { drupal_set_message($this->t('The comment you are replying to does not exist.'), 'error'); return new RedirectResponse($this->urlGenerator()->generateFromPath($uri['path'], array('absolute' => TRUE))); } diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 1b29d84b1169..d2c79bdc338a 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -219,7 +219,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { parent::preSave($storage_controller); if (!isset($this->status->value)) { - $this->status->value = \Drupal::currentUser()->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED; + $this->status->value = \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; } if ($this->isNew()) { // Add the comment to database. This next section builds the thread field. @@ -306,7 +306,7 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ $this->releaseThreadLock(); // Update the {comment_entity_statistics} table prior to executing the hook. $storage_controller->updateEntityStatistics($this); - if ($this->status->value == COMMENT_PUBLISHED) { + if ($this->status->value == CommentInterface::PUBLISHED) { module_invoke_all('comment_publish', $this); } } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php index 93b9a99a3ea3..9c11291d8c4a 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Action; use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ActionBase; +use Drupal\comment\CommentInterface; /** * Publishes a comment. @@ -26,7 +27,7 @@ class PublishComment extends ActionBase { * {@inheritdoc} */ public function execute($comment = NULL) { - $comment->status->value = COMMENT_PUBLISHED; + $comment->status->value = CommentInterface::PUBLISHED; $comment->save(); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php index b7d735e0f0af..f8350cc9d979 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Action; use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ConfigurableActionBase; +use Drupal\comment\CommentInterface; /** * Unpublishes a comment containing certain keywords. @@ -30,7 +31,7 @@ public function execute($comment = NULL) { $text = drupal_render($build); foreach ($this->configuration['keywords'] as $keyword) { if (strpos($text, $keyword) !== FALSE) { - $comment->status->value = COMMENT_NOT_PUBLISHED; + $comment->status->value = CommentInterface::NOT_PUBLISHED; $comment->save(); break; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php index 4857d3efe06f..29a0b975b66b 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Action; use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ActionBase; +use Drupal\comment\CommentInterface; /** * Unpublishes a comment. @@ -26,7 +27,7 @@ class UnpublishComment extends ActionBase { * {@inheritdoc} */ public function execute($comment = NULL) { - $comment->status->value = COMMENT_NOT_PUBLISHED; + $comment->status->value = CommentInterface::NOT_PUBLISHED; $comment->save(); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php b/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php index 13ce3d091a3e..83ebc377ce26 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php @@ -9,6 +9,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Database\Query\SelectInterface; +use Drupal\comment\CommentInterface; use Drupal\entity_reference\Annotation\EntityReferenceSelection; use Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase; @@ -35,7 +36,7 @@ public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') { // core requires us to also know about the concept of 'published' and // 'unpublished'. if (!user_access('administer comments')) { - $query->condition('status', COMMENT_PUBLISHED); + $query->condition('status', CommentInterface::PUBLISHED); } return $query; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php index 5fd785a2dac4..6344b9e13942 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\comment\CommentInterface; use Drupal\views\ResultRow; use Drupal\Component\Annotation\PluginID; @@ -39,7 +40,7 @@ protected function renderLink($data, ResultRow $values) { $status = $this->getValue($values, 'status'); // Don't show an approve link on published nodes. - if ($status == COMMENT_PUBLISHED) { + if ($status == CommentInterface::PUBLISHED) { return; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php index 3ce1d29ed009..270136e0070f 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php @@ -9,6 +9,7 @@ use Drupal\Component\Annotation\PluginID; use Drupal\Core\Database\Connection; +use Drupal\comment\CommentInterface; use Drupal\views\Plugin\views\field\Numeric; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; @@ -121,7 +122,7 @@ public function preRender(&$values) { $result = $this->database->query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comment} c ON n.nid = c.entity_id AND c.entity_type = 'node' LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN (:nids) AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp) AND c.status = :status GROUP BY n.nid", array( - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ':h_uid' => $user->id(), ':nids' => $nids, ':timestamp' => HISTORY_READ_LIMIT, diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php index 94a1651b0c0d..ea892c87be1e 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\comment\CommentInterface; + /** * Tests actions provided by the Comment module. */ @@ -39,12 +41,12 @@ function testCommentPublishUnpublishActions() { // Unpublish a comment. $action = entity_load('action', 'comment_unpublish_action'); $action->execute(array($comment)); - $this->assertEqual($comment->status->value, COMMENT_NOT_PUBLISHED, 'Comment was unpublished'); + $this->assertEqual($comment->status->value, CommentInterface::NOT_PUBLISHED, 'Comment was unpublished'); // Publish a comment. $action = entity_load('action', 'comment_publish_action'); $action->execute(array($comment)); - $this->assertEqual($comment->status->value, COMMENT_PUBLISHED, 'Comment was published'); + $this->assertEqual($comment->status->value, CommentInterface::PUBLISHED, 'Comment was published'); } /** @@ -70,10 +72,10 @@ function testCommentUnpublishByKeyword() { // Load the full comment so that status is available. $comment = comment_load($comment->id()); - $this->assertTrue($comment->status->value == COMMENT_PUBLISHED, 'The comment status was set to published.'); + $this->assertTrue($comment->status->value == CommentInterface::PUBLISHED, 'The comment status was set to published.'); $action->execute(array($comment)); - $this->assertTrue($comment->status->value == COMMENT_NOT_PUBLISHED, 'The comment status was set to not published.'); + $this->assertTrue($comment->status->value == CommentInterface::NOT_PUBLISHED, 'The comment status was set to not published.'); } } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php index 1e9828706ea9..91b9d45eda70 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; /** * Tests comment CSS classes. @@ -40,7 +41,7 @@ function testCommentClasses() { $parameters = array( 'node_uid' => array(0, $this->web_user->id()), 'comment_uid' => array(0, $this->web_user->id(), $this->admin_user->id()), - 'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED), + 'comment_status' => array(CommentInterface::PUBLISHED, CommentInterface::NOT_PUBLISHED), 'user' => array('anonymous', 'authenticated', 'admin'), ); $permutations = $this->generatePermutations($parameters); @@ -90,7 +91,7 @@ function testCommentClasses() { $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-id="' . $node->id() . '"]')), 'data-history-node-id attribute is set on node.'); // Verify classes if the comment is visible for the current user. - if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') { + if ($case['comment_status'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') { // Verify the by-anonymous class. $comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "by-anonymous")]'); if ($case['comment_uid'] == 0) { @@ -119,7 +120,7 @@ function testCommentClasses() { // Verify the unpublished class. $comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "unpublished")]'); - if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') { + if ($case['comment_status'] == CommentInterface::NOT_PUBLISHED && $case['user'] == 'admin') { $this->assertTrue(count($comments) == 1, 'unpublished class found.'); } else { @@ -130,7 +131,7 @@ function testCommentClasses() { // drupal.comment-new-indicator library to add a "new" indicator to each // comment that was created or changed after the last time the current // user read the corresponding node. - if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') { + if ($case['comment_status'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') { $this->assertIdentical(1, count($this->xpath('//*[contains(@class, "comment")]/*[@data-comment-timestamp="' . $comment->changed->value . '"]')), 'data-comment-timestamp attribute is set on comment'); $expectedJS = ($case['user'] !== 'anonymous'); $this->assertIdentical($expectedJS, isset($settings['ajaxPageState']['js']['core/modules/comment/js/comment-new-indicator.js']), 'drupal.comment-new-indicator library is present.'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index b0311cba66f5..1e13ddb8901a 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\comment\CommentInterface; + /** * Tests the comment module administrative and end-user-facing interfaces. */ @@ -146,7 +148,7 @@ function testCommentInterface() { $this->setCommentsPerPage(50); // Attempt to reply to an unpublished comment. - $reply_loaded->status->value = COMMENT_NOT_PUBLISHED; + $reply_loaded->status->value = CommentInterface::NOT_PUBLISHED; $reply_loaded->save(); $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $reply_loaded->id()); $this->assertText(t('The comment you are replying to does not exist.'), 'Replying to an unpublished comment'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php index c529ab9c1073..6eabd64f5292 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; /** * Tests comment links based on environment configurations. @@ -146,7 +147,7 @@ function setEnvironment(array $info) { 'field_name' => 'comment', 'pid' => 0, 'uid' => 0, - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomName(), 'hostname' => '127.0.0.1', 'langcode' => Language::LANGCODE_NOT_SPECIFIED, diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php index cdf658ac2c0e..17e358c4b43b 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; /** * Tests the 'new' marker on comments. @@ -94,7 +95,7 @@ public function testCommentNewCommentsIndicator() { 'field_name' => 'comment', 'pid' => 0, 'uid' => $this->loggedInUser->id(), - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomName(), 'hostname' => '127.0.0.1', 'langcode' => Language::LANGCODE_NOT_SPECIFIED, diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php index 98373ae2b9ae..3fb64605d634 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -407,7 +408,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => 'Comment Published <&>', 'language' => Language::LANGCODE_NOT_SPECIFIED, ), @@ -418,7 +419,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => COMMENT_NOT_PUBLISHED, + 'status' => CommentInterface::NOT_PUBLISHED, 'subject' => 'Comment Unpublished <&>', 'language' => Language::LANGCODE_NOT_SPECIFIED, ), @@ -429,7 +430,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => COMMENT_NOT_PUBLISHED, + 'status' => CommentInterface::NOT_PUBLISHED, 'subject' => 'Comment Published on Unpublished node <&>', 'language' => Language::LANGCODE_NOT_SPECIFIED, ), diff --git a/core/modules/forum/lib/Drupal/forum/ForumManager.php b/core/modules/forum/lib/Drupal/forum/ForumManager.php index cdf9a5e48ea6..5c530c7e6856 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManager.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\comment\CommentInterface; use Drupal\field\FieldInfo; use Drupal\node\NodeInterface; @@ -518,14 +519,14 @@ public function unreadTopics($term, $uid) { public function updateIndex($nid) { $count = $this->connection->query("SELECT COUNT(cid) FROM {comment} c INNER JOIN {forum_index} i ON c.entity_id = i.nid WHERE c.entity_id = :nid AND c.field_id = 'node__comment_forum' AND c.entity_type = 'node' AND c.status = :status", array( ':nid' => $nid, - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ))->fetchField(); if ($count > 0) { // Comments exist. $last_reply = $this->connection->queryRange("SELECT cid, name, created, uid FROM {comment} WHERE entity_id = :nid AND field_id = 'node__comment_forum' AND entity_type = 'node' AND status = :status ORDER BY cid DESC", 0, 1, array( ':nid' => $nid, - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ))->fetchObject(); $this->connection->update('forum_index') ->fields( array( diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php index d1f0e65c1fb8..fed13531063f 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php @@ -7,6 +7,7 @@ namespace Drupal\forum\Tests; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -62,7 +63,7 @@ function testForumUninstallWithField() { 'field_name' => 'comment_forum', 'pid' => 0, 'uid' => 0, - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomName(), 'hostname' => '127.0.0.1', )); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php index 579626a9a1f5..74cd9c742aa6 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php @@ -8,6 +8,7 @@ namespace Drupal\node\Tests; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -55,7 +56,7 @@ public function testCommentPager() { 'comment_body' => array( array('value' => $this->randomName()), ), - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, )); $comment->save(); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php index 411f6fee6ca5..8a96631d2f0d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Theme; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -112,7 +113,7 @@ function setUp() { 'entity_id' => $this->node->id(), 'entity_type' => 'node', 'field_name' => 'comment', - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => $this->xss_label, 'comment_body' => array($this->randomName()), )); diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php index 7a3983e36a7f..0abd95e13a05 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php @@ -7,6 +7,7 @@ namespace Drupal\tracker\Tests; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -121,7 +122,7 @@ function testTrackerUser() { // Verify that unpublished comments are removed from the tracker. $admin_user = $this->drupalCreateUser(array('post comments', 'administer comments', 'access user profiles')); $this->drupalLogin($admin_user); - $this->drupalPostForm('comment/1/edit', array('status' => COMMENT_NOT_PUBLISHED), t('Save')); + $this->drupalPostForm('comment/1/edit', array('status' => CommentInterface::NOT_PUBLISHED), t('Save')); $this->drupalGet('user/' . $this->user->id() . '/track'); $this->assertNoText($other_published_my_comment->label(), 'Unpublished comments are not counted on the tracker listing.'); } diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module index eca8ccc944de..b1be0414a3e0 100644 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\comment\CommentInterface; use Drupal\node\NodeInterface; use Drupal\Core\Session\AccountInterface; @@ -92,7 +93,7 @@ function tracker_cron() { ->condition('c.entity_id', $row->nid) ->condition('c.entity_type', 'node') ->condition('c.uid', $row->uid, '<>') - ->condition('c.status', COMMENT_PUBLISHED); + ->condition('c.status', CommentInterface::PUBLISHED); // Insert the user-level data for the commenters (except if a commenter // is the node's author). @@ -193,7 +194,7 @@ function tracker_node_predelete(EntityInterface $node, $arg = 0) { function tracker_comment_update($comment) { // $comment->save() calls hook_comment_publish() for all published comments // so we need to handle all other values here. - if ($comment->status->value != COMMENT_PUBLISHED && $comment->entity_type->value == 'node') { + if ($comment->status->value != CommentInterface::PUBLISHED && $comment->entity_type->value == 'node') { _tracker_remove($comment->entity_id->target_id, $comment->uid->target_id, $comment->changed->value); } } @@ -285,7 +286,7 @@ function _tracker_calculate_changed($nid) { $changed = db_query('SELECT changed FROM {node_field_data} WHERE nid = :nid AND default_langcode = 1 ORDER BY changed DESC', array(':nid' => $nid), array('target' => 'slave'))->fetchField(); $latest_comment = db_query_range("SELECT cid, changed FROM {comment} WHERE entity_type = 'node' AND entity_id = :nid AND status = :status ORDER BY changed DESC", 0, 1, array( ':nid' => $nid, - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ), array('target' => 'slave'))->fetchObject(); if ($latest_comment && $latest_comment->changed > $changed) { $changed = $latest_comment->changed; @@ -319,7 +320,7 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) { $keep_subscription = db_query_range("SELECT COUNT(*) FROM {comment} WHERE entity_type = 'node' AND entity_id = :nid AND uid = :uid AND status = :status", 0, 1, array( ':nid' => $nid, ':uid' => $uid, - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ))->fetchField(); } -- GitLab