Closed (fixed)
Project:
Workbench Moderation
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Mar 2011 at 20:09 UTC
Updated:
1 May 2012 at 09:35 UTC
Jump to comment: Most recent file
Comments
Comment #1
binford2k commentedThis is a very rough first stab. It adds a single trigger at transition state change and exposes two new tokens, [moderation:new-state] and [moderation:old-state]
Comment #2
dave reidAwesome! I have to put in my 2 cents as Token maintainer. :) I'm not exactly seeing the purpose of a new token type when this seems to be a node-related token. I'd advise adding the tokens into $info['tokens']['node'].
Comment #3
binford2k commentedI'd agree. The "purpose" was that this was the first time I'd ever touched the token API and I ran into some weird newb issues when I tried merging them into the node tokens.
Comment #4
binford2k commentedAdds a token for the editor username.
Comment #5
binford2k commentedAnd the patch sans typo...
Comment #6
stevectorThanks again binford2k for doing this. I'm curious about your implementation of hook_trigger_info. I would have expected the top level key to be 'node' instead of 'workbench_moderation.' Am I misunderstanding something? It seems that the 'transition' event fits in a list with 'node_update', 'node_delete' etc.
Dave do you have an opinion on that question?
Comment #7
cbLoving the trigger patch, I didn't apply the token patches but the trigger will not show up in Rules, it shows up in the Drupal triggers, just not in rules. Would love to know if there is anything I need to do to get it in Rules (I know this isn't Rules support, just curious if you know anything.)
Comment #8
agence web coheractio commentedsubscribing
Comment #9
nrambeck commentedsubscribe
Comment #10
stevectorHere's an update to the trigger patch.
I think this warrants some more discussion. As I was thinking about this more it seemed like we need triggers for each transition. So I've included that. However there are some wrinkles.
The triggers assignment table limits trigger names to 32 characters so keying off state names is worrisome. Also we may need to update these names any time a transition name changes. This is another reason for machine names on states.
So let's split the token stuff off to a separate issue since that can happen independently. Rules work might need to follow trigger work. I'm not entirely sure.
Comment #11
Shadlington commentedSubbing
Comment #12
stevectorI'm splitting token work into a separate issue and will post an updated patch there. #1159256: Token support for workbench moderation states
Comment #13
stevectorI've also created a separate issue about machine names which could help triggers work more reliably.
#1160478: Machine names for states
Comment #14
dystopianblue commentedSubscribe
Comment #15
stevector#764558: Remove Trigger module from core
Triggers might get taken out of core in D8. This indicates that our integration with Rules should be just as tight so that this doesn't cause any refactoring for us. I still think we should use triggers now for D7.
Comment #16
ericras commentedI've been testing the patch in #10 with 7.x-1.0-beta8 and with the default moderation states to send out an email when the state changes. Works well without any problems for me.
Comment #17
nrambeck commentedI re-rolled patch #10 with some changes to account for the 32 character limit for trigger hooks. If any trigger hook exceeds 32 characters, I created an MD5 hash to use as the trigger hook string. The hash is done when creating the trigger assigning and when getting the trigger assignment to ensure they will match.
Comment #18
Frederic wbase commentedI've tested the patch from #17 with custom workbench states and everything works fine. Just wondering, why there is no rules integraton?
Comment #19
rbishop commentedive tried the patch #17 on 7.x-1.0-beta8 but my email action returns the tokens just as [workbench_moderation:from-state] however it works for token [node:title]. is there anything i need to configure to allow these tokens to evaluate ?
but i am successfully able to evaluate wbm using these node tokens
[node:wbm-my-revision:editor:mail]
[node:wbm-current:editor:mail]
but with User Warning errors
User warning: Attempting to perform token replacement for token type workbench_moderation without required data in token_tokens() (line 791 of /sites/all/modules/token/token.tokens.inc).
Comment #20
nrambeck commentedrbishop, this patch doesn't add any new tokens or touch token support in any way. Token support was split out into a separate issue: #1159256: Token support for workbench moderation states
Comment #21
ericras commentedThe #10 and #17 patches cause saving an edit to fail when the Trigger module is disabled.
PHP Fatal error: Call to undefined function trigger_get_assigned_actions() in /Library/WebServer/Documents/workspace/drupal/sites/all/modules/workbench_moderation/workbench_moderation.module on line 1850, referer: http://localhost/workspace/drupal/?q=node/1/editWe need to check module_exists for trigger when calling workbench_moderation_trigger_transition()
Comment #22
knaffles commentedsubscribe
Comment #23
nrambeck commentedThanks Eric. Patch modified to include conditional around trigger from comment 21.
Comment #24
kukle commentedsub
Comment #25
Vandalf commentedsubscribing
Comment #26
sylus commentedsub
Comment #27
liliplanet commentedAbsolutely fabulous, thank you!
#23 patch works perfectly :)
Comment #28
thamas#23 works me too. Set to RTBC. Thanks!
Comment #29
theunraveler commentedI know this has been RTBC, but it seems like the better way to do this would be to implement a hook that fires when a transition occurs, then bind the trigger call to that hook. As it stands, you sort of force yourself to duplicate a lot of code when adding hooks, triggers, and rules integration. Instead, it would make sense to make trigger integration just another consumer of a consistent workbench moderation API, of which rules could be another.
How do people feel about this approach? Obviously, it should probably be part of a bigger discussion on a uniform Workbench Moderation hook API, but it seems pretty reasonable to me.
(Patch applies to current master branch).
Comment #31
theunraveler commentedRe-rolling against 7.x-1.x.
Comment #32
theunraveler commentedSigh. Trying again.
Comment #33
thekevinday commentedIt makes sense, as you said, to centralize the changes.
Heres what I did:
- Fixed spelling of trasnistion at line 1875.
- Moved the '*_action_info()' functions I created here http://drupal.org/node/1226688#comment-4989010 to this function.
- Moved the "if (module_exists('rules')){ ..." code to your workbench_moderation_workbench_moderation_transition() function in this patch.
- Used your "Add a trigger for each transition." loop code to associate an action with each of those triggers.
- I also associated 'node_presave' with the actions as well.
Comment #34
kingswoodute commentedGreat work, this is exactly the sort of functionality I need.
I'm newish to Drupal and have a general question about this process.
When this patch is completed will it become part of a re-released Workbench module or an automatic update?
Basically if I want to use this functionality do I watch this log and wait for the patch to be finalised and then install it?
Thanks for your work. I think this community approach to development is fantastic (as is Drupal).
Comment #35
itaine commented@kingswoodute - This is open source, I would and I am going to git clone the dev version and patch that sucker now! The odds are it will be included along with other patches in the next stable release. Then you just update to that.
Happy Drupalling!
Comment #36
stevectorThanks Kevin for this patch!
I'm having difficulty testing it. My first approach was to to create an action that moved a node to "Needs Review." I then assigned this action to the node_insert trigger so that new nodes would automatically move to "Needs Review." I then added a node and got the following notices.
The problem seems to be that this new node object doesn't have the workbench_moderation property. $node does have $node->workbench_moderation_state_current and $node->workbench_moderation_state_new. So the problem is likely an inconsistent use of these properties and the $node->workbench_moderation['my_revision'] approach.
So perhaps we need to take node_insert and node_presave out of patch until that problem is fixed.
On the node_update hook we seem to have a different problem. If I edit a draft node and leave the moderation drop down set to "draft" I get two moderation records, one from the form and one from the action. Kevin, do you have an opinion on how to handle that case?
Comment #37
thekevinday commentedThis seems to be problems in how workbench_moderation is designed.
There are a number of issues in how it is designed that prevents some of the functionality here from being used.
One is the usage of node_save().
I had this same problem with workbench_access when writing actions support.
The only solution was to provide presave only actions and not any node_update or node_insert actions.
What happens is node_save will trigger another set of actions.
When using an action that responds to a node save and then it itself will do a node_save, well you can guess what happens.
By using presave functionality, changes are made to the properties and no node_save is made.
For the other issue, it seems that some part of how workbench_access is designed is causing a duplicate revision to be saved under all circumstances on initial node creation.
I tested this by making a number of the workbench_moderation functions do a return; as the first line of code.
I suspect that this could be a problem that both workbench_access and workbench_moderation are doing manual node_save() operations, which means a node_save() gets called 3 times for any given node.
One for the original node_save, one for workbench_access, and one for workbench_moderation.
I suspect the solution to this would be to not perform any manual node_saves and do any work on fields like it is done with presave.
As an alternative, perhaps the workbench module could provide a node save wrapper function that can call all workbench-specific node save operations to at least reduce the number of node_save calls?
Comment #38
benjhe commentedHey ! Great works !
This patch works perfectly.
I have 2 questions thought :
- I'm currently using the custom module 'Action Email Role' (http://drupal.org/node/1213306) which let us create an action for sending an email to all users of a given role. This module works with 'Node', 'System', 'Taxonomy' and 'User' triggers section, but not with the 'Workbench Moderation'. Actions of that type don't appear in the list. Any idea of why ?
- When a moderator approve or refuse an article, I want the user who write the new version of an existing article to be notified. How can we specify in the action that the receiver is the User who write a new version of the article instead of the original author ? I can't find the correct token for that.
Thank for your help.
Comment #39
thekevinday commentedI wish that were true.
Yep.
Actions seem to require one to specify the "trigger" type to associate it with.
See: http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...
Which means that each an every module must know about another to add itself to associate it with anothers triggers.
I suggest using the rules module, it is better at doing these things than the core trigger system.
Of course, because it can do more it might be harder to learn how to use. I suggest applying the patch https://drupal.org/node/1226688 after applying this one.
Here is the new patch with the node_update and node_insert removed for the time being.
I added a presave action to work with presaves and it can be used to set states.
I am not sure how useful the presave can be for triggers+actions, but it at least shows how not performing a node_save() works better.
Comment #40
tevans commentedsub
Comment #41
benjhe commentedThank you thekevinday !
Using rules instead does what I want.
Any suggestions for my 2nd problem ? How to send an email to the User of the new version ?
Another way could be changing the content owner when he saves his draft.
Is it possible to do that ? With VBO ?
Comment #42
thamasI had no time to test the newer patches, but I want to tell you that the patch in #23 may cause a new bug (not sure): http://drupal.org/node/1230034#comment-5111200
Comment #43
Désiré commentedNo, the problem is not with the patches, it is a token module bug: #1317926: menu_tokens function should not change the node object
Comment #44
mxh commentedthekevinday, i wanna say 10000000 thanks.
I'd say this is a typical feature a workflow module must have.
Wish you a good day.
Comment #45
thekevinday commentedJust for the record, all these people created/modified the patch:
binford2k
stevector
nrambeck
theunraveler
I was simply the last person to make any changes.
Comment #46
dams_26 commentedThanks for this feature you did a great job. Can we hope a new release of the module soon?
Comment #47
dams_26 commented#39: trigger_support_for_wb_moderation-1079134-39.patch queued for re-testing. ===> sorry, is there anyone who can delete my post ?
Comment #49
mxh commentedDon't know if this is a bug, but presave action does not set the state to 'published' when moderating the state to 'publish', only node->state is set to 1. when using workbench_moderation_set_state_action the status is set to 'published' then. I can set every other status with the presave action, like 'draft' to 'needs review', but publish does not work. rules are set correctly.
Comment #50
mxh commentedme again. i don't know if your patch from #39 works as it should. I use the actions as VBO's, like selecting multiple nodes an set new state per one click. So for that use case, my post #49 already mentioned:
neither presave action nor the normal set moderation state action do what i want.
the normal method: status isn't updated after set it via vbo. I see in list of recent version the old state. Clicking on the node itself, theres the new state. This is not a caching problem as i found out.
Presave action: it saves some states, but when set the state to publish -> state is not being set & only node->status == 1.
So I have altered your last patch, removing presave action because i don't really know what it is for, but the normal set method has been changed. This patch is working for me, with version 7.x-1.1 and using node revision views.
here's the snipped of the changed function code:
posted patch in attachement.
please test it out, maybe it fits your needs in VBO.
If this patch is useless, please remove this post. thx.
Comment #51
plopescGreat!
Thanks for your work
Comment #52
emptyvoid commentedShouldn't this be set to "needs review" for the latest patch?
Or has this integrated into the dev branch yet?
Comment #54
David_Rothstein commentedJust a note, it looks like most of this patch was already committed in #1226688: Rules Integration Support, although it sounds from the discussion there like there may be some additional follow up work to do?
Comment #55
mxh commented#54: Do you know if patch from #1226688: Rules Integration Support also support actions to use for example in VBO? I don't know what the patch there does exactly now, just set a rule for the trigger like "After stat X was set", or if there are also actions like "set moderation state" supported. If so, this issue here is a duplicate.
Comment #56
David_Rothstein commentedI believe there are actions too - it looked like it was almost literally the same patch as the latest one here (with a couple small tweaks on top of it), plus an extra file for the Rules integration on top of that.
I didn't look too carefully into it, but it sounded like there was some discussion that followup was necessary and that this issue could be used for that followup, but otherwise I agree this issue is probably fixed.
Comment #57
mxh commentedJust looked into it. It does, so I close this one.
Issue from http://drupal.org/node/1226688 fixed this issue.
Thanks David_Rothstein for getting this clear.