Commit be70033e authored by alexpott's avatar alexpott

Issue #2151427 by andypost, TR: Convert COMMENT_NOT_PUBLISHED &...

Issue #2151427 by andypost, TR: Convert COMMENT_NOT_PUBLISHED & COMMENT_PUBLISHED to a constant on the comment interface.
parent dd663c40
......@@ -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();
}
......
......@@ -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');
......
......@@ -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':
......
......@@ -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.'));
}
......
......@@ -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.
*
......
......@@ -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()
......
......@@ -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.
......
......@@ -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',
......
......@@ -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)));
}
......
......@@ -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);
}
}
......
......@@ -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();
}
......
......@@ -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;
}
......
......@@ -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();
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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.');
}
}
......@@ -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.');
......
......@@ -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');
......
......@@ -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,
......
......@@ -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,
......
......@@ -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,
),
......
......@@ -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(
......
......@@ -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',
));
......
......@@ -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();
}
......
......@@ -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()),
));
......
......@@ -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.');
}
......
......@@ -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();
}
......
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