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 :-)

Comments

fago’s picture

StatusFileSize
new3.06 KB

Thanks, 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.

klausi’s picture

Status: Needs review » Needs work
+++ b/modules/data.eval.inc
@@ -282,8 +282,19 @@ function rules_condition_data_list_contains($list, $item, $settings, $state) {
+function rules_condition_data_is_empty(EntityMetadataWrapper $data) {

we 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)

+++ b/rules.install
@@ -406,3 +406,10 @@ function rules_update_7206() {
+/**
+ * Flush all caches.
+ */

This comment should be more specific why we clear the cache.

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new3.02 KB

Updated patch attached.

fago’s picture

Status: Needs review » Fixed

ouch, indeed. I've added a comment for the primitive variables and committed it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mitchell’s picture

Component: Provided Rules integration » Provided Module Integrations

Updated component.