I am tying to add an action set that fetch entities with specific properties (i.e status = published and Created = specific date). then add a loop and perform an action within the loop.
I have been able to add an action set component that fetch node entities with ONE specific property, for example, status = published, but I cannot seem to add another property condition within the same action set (i.e created = some date). Is there a way to do so? or perhaps add multiple conditions within the action set or within the loop itself.
I know this can be coded by implemntig hook_cron (because I want the actions to trigger on cron) but it would be very helpful if it is possible to do it in rules so it could be easily configured later and modified.
Comments
Comment #1
acrazyanimal commentedCreate a rule component
Create your initial rule that is triggered by your cron event or whatever
... and kablamo! you're done.
One super awesome rule that does what you want without having to code anything. Yay!
cheers.
Comment #2
awm commentedThank you acrazyanimal. Your explanation guided me in resolving my issue.
For curious minds, here is what I did.
1.Go to workflow -> Rules.
2. Clicked on compnontes
3. Added 2 compononents
A)Main component of type (rule set) that have one rule that fetches my entities with the specified property and loop over them and perform an action component.
B) Another Component of type rule that deletes the fetched entity called it (delete entity)
Component A fetch Entities is a ruleset (does not have to be I presume) that have one rule, as I mentioned. The rule has the following:
-Condition: None
-Actions:
1. Fetch entity by property (Parameter: Entity type: (Some Type), Property: Status, Value: Published, Limit result count: 100 Provides variables: Fetched Entity (entity_fetched)
2. Loop: (Parameter: List: [entity-fetched] List item: Entity Fetched item (list_item) )
Nested within the loop I have I add another action. The action is Component B.
Component B Delete Entity is a rule that have the following:
1. Condition: Data comparison to compare dates.
2. Actions: one action delete entity (Parameter: Entity ....)
I feel that there gotta be cleaner more intutive ways to do it, however, I am content with what I got. I can now use these Components in other rules, with different events.
Comment #3
acrazyanimal commentedGreat, glad to be of help.
Comment #4
Leoo commentedHello,
Still, for the above, when you have a big site with lots of rules this is a big burden to insert loops into components into loops etc. to fetch an entity by several properties.
Moreover, with that many loops, the processing time of the rules must be greatly increased isnt it?
Having thought a bit about it, here is a proposal:
What about a RULE TO FETCH AN ENTITY BY PROPERTY, INSIDE A SUBSET LIST OF ENTITIES instead of the whole entities of Drupal?
Right now we can define the type of the entity fetched (node, taxonomy term etc.), should be pretty close to say that the entoty must belong to a list?
That way no need to loop and use components, we just need to, for the example above, 2 actions:
1) Fetch entities with status = "published" =>list 1
2) Fetch entities created on a specific date INSIDE list 1 => list 2
So 2 actions, instead of
1) Fetch entities with status = "published" =>list 1
2) Loop through list 1 =>listitem
3) component If listitem created on a specific date then do something
This would save lots of hours/days creating the components/loops, and a faster site.
Thanks a lot, a shame Im not able yet to code this rule in PHP.
L
Comment #5
Leoo commentedFixed by http://drupal.org/project/views_rules in http://drupal.org/node/1777968.
Comment #6
giorgio79 commentedFetch entity by propety seems to be useless with only 1 property. I guess this uses EntityFieldQuery, but you rarely see an EntityFieldQuery with one property only...
So, multiple properties should be allowed, or make http://drupal.org/project/views_rules a Rules core module.
Comment #7
delacosta456 commentedhi
for anyone reading this, another option is to use this module EFQ Rules ..
As said in the module's page :
The only thing is that i haven't compare EFQ Rules and Views Rules to know the one that will faster when loading data from database.