When using complex data selectors like node:author:personal-profile:name in the data_is_empty condition, Rules will throw warnings if it is executed on a node where the author does not have a personal profile. This is inconvenient as one would have to check the whole data selector chain for emptiness (i.e. each data structure from node:author to node:author:personal-profile:name) in order to avoid the warnings.
This patch uses the entity metadata wrappers in the condition to check if data is actually available. Exceptions are caught and the condition treats them as indicator for an empty data structure and therefore returns TRUE. Simpletest included :-)
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1431102-rules-is-empty-improvement.patch | 3.02 KB | klausi |
| #1 | rules_data_is_empty.patch | 3.06 KB | fago |
| rules-is-empty-improvement.patch | 2.56 KB | klausi |
Comments
Comment #1
fagoThanks, the approach looks good. However, we can trust Rules to pass us the right data. We need just make sure that caches are cleared when people update their installation - thus I've added an update routine for that and changed the code to rely on getting a wrapper passed.
Updated patch attached.
Comment #2
klausiwe cannot do type hinting here as there can be primitive variables (Recoverable fatal error: Argument 1 passed to rules_condition_data_is_empty() must be an instance of EntityMetadataWrapper, string given)
This comment should be more specific why we clear the cache.
Comment #3
klausiUpdated patch attached.
Comment #4
fagoouch, indeed. I've added a comment for the primitive variables and committed it.
Comment #6
mitchell commentedUpdated component.