Problem/Motivation

Keyword lists could be long

for each keywork, it re-renders the node and comment in loop

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because it is not a bug, and not a feature request. (maybe if scalability ... it could be a bug) per https://www.drupal.org/core/issue-category
Issue priority Normal because problem is localized in one small area (unpublish by keyword action) . Not critical because it doesn't make the whole system unusable. Not minor, because it is is not just cosmetic. per https://www.drupal.org/core/issue-priority
Unfrozen changes NOT Unfrozen only changes.
Prioritized changes The main goal of this issue is performance.
Disruption NOT Disruptive for core/contributed and custom modules/themes because it will not require a BC break/deprecation/internal refactoring/widespread changes.

So allowed in the beta because it is only about performance.

Proposed resolution

render once and reuse the result in the loop.

Remaining tasks

User interface changes

No.

API changes

No.

Comments

andypost’s picture

StatusFileSize
new2 KB

Also $comment->subject should be checked for keywords as node's action does

andypost’s picture

D6 affected too.
Seems test of comment-subject was lost in development so #1 returns it back
http://api.drupal.org/api/function/comment_unpublish_by_keyword_action/6

andypost’s picture

StatusFileSize
new929 bytes

Patch for D6

andypost’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
StatusFileSize
new1.71 KB

Re-roll for D8

andypost’s picture

#4: 874624-unpublish-action.patch queued for re-testing.

catch’s picture

Patch looks good but are these actions tested at all? If they are then great, but going by #244093: Node and comment actions are (still) completely broken and have broken tests too a lot of actions aren't.

xjm’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs review » Needs work
Issue tags: -Needs backport to D7 +Needs tests

#764558: Remove Trigger module from core has been committed, so moving back to D7. Tagging for test coverage based on #6. Thanks everyone!

tayzlor’s picture

Status: Needs review » Needs work
StatusFileSize
new2.51 KB
new1.56 KB

Uploading a test and a patch against d8 to cover off the comment part of this issue. I had to change the original patch slightly since it did not work properly.

There are currently no tests for node actions, so looks like a bit more work needs to be done there. If I can, I will try uploading a separate patch for the node issue along with node actions tests.

tayzlor’s picture

Status: Needs work » Needs review
tayzlor’s picture

woops, didnt notice the d8 comment about actions disappearing (re-rolling against 7)

tayzlor’s picture

StatusFileSize
new2.29 KB
new1.37 KB

And here's the d7 patches for comment.

tayzlor’s picture

Status: Needs work » Needs review
droplet’s picture

Status: Needs review » Needs work
+++ b/modules/comment/comment.moduleundefined
@@ -2592,9 +2592,12 @@ function comment_unpublish_action($comment, $context = array()) {
+   ¶

code style problem.

yesct’s picture

Status: Needs work » Needs review
Issue tags: -Performance, -Needs backport to D6, -Needs tests

#11: 874624-d7-comment.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Performance, +Needs backport to D6, +Needs tests

The last submitted patch, 874624-d7-comment.patch, failed testing.

yesct’s picture

Assigned: andypost » Unassigned
Issue tags: +Novice

adding novice tag for redoing patches for taking out the extra white space... and

+++ b/modules/comment/comment.testundefined
@@ -1969,6 +1970,13 @@ class CommentActionsTestCase extends CommentHelperCase {
     $this->assertEqual(comment_load($comment->cid)->status, COMMENT_PUBLISHED, t('Comment was published'));
     $this->assertWatchdogMessage('Published comment %subject.', array('%subject' => $subject), t('Found watchdog message'));
...
+    $this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $subject), t('Found watchdog message'));

t() in the assert might not be needed.

http://drupal.org/node/500866

babruix’s picture

Status: Needs work » Needs review
StatusFileSize
new2.68 KB

Patch fo d7 corrected.

andypost’s picture

Looks good except

+++ b/modules/comment/comment.moduleundefined
@@ -2615,9 +2615,12 @@ function comment_unpublish_action($comment, $context = array()) {
+  $text = drupal_render($build);
+   ¶

trailing whitespace

babruix’s picture

StatusFileSize
new15.26 KB
babruix’s picture

StatusFileSize
new2.68 KB
andypost’s picture

Status: Needs review » Reviewed & tested by the community

Now looks fine

yesct’s picture

Issue tags: -Needs tests

@babruix Interdiffs are awesome. For next time. :)
For instructions on creating an interdiff, see http://drupal.org/node/1488712 Or, see http://xjm.drupalgardens.com/blog/interdiffs-how-make-them-and-why-they-...

I think this has tests... so removing the needs tests tag.

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev
Component: trigger.module » comment.module
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

This is a patch for the Comment module, not the Trigger module. So it still needs to go into Drupal 8.

Looking at the code, it's possible this is partially fixed in Drupal 8 already, but I'm not sure if it's completely fixed... Also the test changes definitely don't look like they're in Drupal 8 yet.

David_Rothstein’s picture

Hm, also, there were changes to the node module too in earlier patches... what happened to those?

willieseabrook’s picture

Assigned: Unassigned » willieseabrook

Starting with this as part of the Prague mentoring sprint

willieseabrook’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new3.05 KB

There are two things to deal with here.

  1. Whether the fix in comment_unpublish_by_keyword_action in the D7 patch in #20 has come into D8
  2. What happened to the node_unpublish_by_keyword_action code in the original patch in #1

1. Whether the fix to the code in comment_unpublish_by_keyword_action in the D7 patch in #20 has come into D8

Appropriate code in D8 is in UnpublishByKeywordComment.php:

  public function execute($comment = NULL) {
    $build = comment_view($comment);
    $text = drupal_render($build);
    foreach ($this->configuration['keywords'] as $keyword) {
      if (strpos($text, $keyword) !== FALSE) {
        $comment->status->value = COMMENT_NOT_PUBLISHED;
        $comment->save();
        break;
      }
    }
  }

As you can see the key line "$text = drupal_render($build);" has indeed been moved outside of the foreach. Also the action is tested in CommentActionsTest:testCommentUnpublishByKeyword. Also, the D7 patch passes all tests and has been reviewed so I think we can conclude that the D7 fix is already in D8 and no action is needed on the comment_unpublish_by_keyword_action function.

2. What happened to the node_unpublish_by_keyword_action code in the original patch in #1

The code for node_unpublish_by_keyword_action has indeed disappeared from the original D7 patch in #1 and the improvement has not been made in D8. In D8 the node is still being rendered inside the foreach loop

I have attached a patch with the following:

  1. Changed node_unpublish_by_keyword_action to use the same higher performing approach in comment_unpublish_by_keyword_action
  2. Added a new test case in a new file in modules/node/Tests/NodeActionsTest.php to match the location of modules/comment/Tests/CommentActionsTest.php. I searched for an existing Node actions test and could not find it.
willieseabrook’s picture

Status: Reviewed & tested by the community » Needs review
willieseabrook’s picture

StatusFileSize
new1.06 KB
new3.06 KB

Minor styling improvements

willieseabrook’s picture

StatusFileSize
new1.06 KB
new3.06 KB

Styling changes

willieseabrook’s picture

I noticed there was no test coverage over Node actions. See #1412964: Add additional test coverage for actions

willieseabrook’s picture

Assigned: willieseabrook » Unassigned

anavarre queued 29: node-874624-28.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 29: node-874624-28.patch, failed testing.

tayzlor’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.79 KB

Re-rolling patch against latest HEAD

andypost’s picture

+++ b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php
@@ -26,9 +26,10 @@ class UnpublishByKeywordNode extends ConfigurableActionBase {
   public function execute($node = NULL) {
+    $build = node_view($node);
+    $text = drupal_render($build);

Use entity_view() here, and check for node is null needed here

yesct’s picture

Issue tags: -Novice

novice tag was added a while back for #16 and that was done. so removing novice tag. https://www.drupal.org/core-mentoring/novice-tasks

andypost’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php
    @@ -26,9 +26,10 @@ class UnpublishByKeywordNode extends ConfigurableActionBase {
    +    $build = node_view($node);
    +    $text = drupal_render($build);
    

    should use properly injected services

  2. +++ b/core/modules/node/src/Tests/NodeActionsTest.php
    @@ -0,0 +1,62 @@
    +class NodeActionsTest extends NodeTestBase {
    ...
    +  public static $modules = array('dblog', 'action');
    

    Should use EntityUnitTestBase
    no reason in dblog and action modules

martin107’s picture

Assigned: Unassigned » martin107

taking a look at this now...

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new4.55 KB
new4.51 KB

I have made a mistake in the new test. so this is not passing at the moment. The problem is to do with which user to use while filtering!

I am posting ... before going to bed ... maybe someone could nudge me in the right direction ... otherwise I will look again with fresh eyes in the morning

#38.1 use preferred dependency injection ... done.

#38.2 refactor for EntityUnitTestBase...

some notes

1) @group in needed now...
2) entity_create is deprecated.. I have replaced with Action::create() and Node:create()
3) drupalCreateUser became createUser in the new test environment.
4) Yep somehow I have muddled the simulation of logging in in the $admin_user.

Status: Needs review » Needs work

The last submitted patch, 40: 874624-actions-unpublish-40.patch, failed testing.

martin107’s picture

Assigned: martin107 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.46 KB
new1.01 KB

Ok next iteration,

1) I have removed the format definition it was not needed... (this was filtering issue from #40)
2) Creating a node without 'type' or 'title' triggers integrity violations. so I have inserted dummy values.
3) We can remove all the login fluff ... it was not needed.

Now for the question

when the action operates on the node in the test

  $action->execute(array($node));

some rendering is required ...

Is there a standard pattern for faking this in a low level test?

otherwise we are going to have to rethink the plan to use EntityUnitTestBase.

can we fake a render context?

currently the error is

LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead. in Drupal\Core\Render\Renderer->doRender() (line 246 of /Users/martin/sites/drupal/core/lib/Drupal/Core/Render/Renderer.php).

Status: Needs review » Needs work

The last submitted patch, 42: 874624-actions-unpublish-42.patch, failed testing.

andypost’s picture

@martin107 use \Drupal\Core\Render\RendererInterface::renderPlain() to render in separate context

  1. +++ b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php
    @@ -21,15 +24,54 @@
    +    $build = node_view($node);
    

    suppose this shoudl use viewBuilder for nodes

  2. +++ b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php
    @@ -21,15 +24,54 @@
    +    $text = $this->renderer->render($build);
    

    should be \Drupal\Core\Render\RendererInterface::renderPlain()

martin107’s picture

StatusFileSize
new4.96 KB

#44.1 Converted node_view to $this->entityTypeManager->getViewBuilder('node')->view($node);

#44.2 Converted to renderPlain() thanks that seems to be the correct thing to do. Not sure about the new error message yet .. just posting early.
Its seems something in the node upsets the rendering.

martin107’s picture

Status: Needs work » Needs review

triggering testbot

Status: Needs review » Needs work

The last submitted patch, 45: 874624-actions-unpublish-45.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for creating this issue to improve Drupal.

We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!

smustgrave’s picture

wanted to bump this 1 more time.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.