Using one variable for different things can be very dangerous. See the code:
$entities = entity_load('entity_rule_setting', FALSE, $conditions);
if ($load_rules) {
foreach (array_keys($entities) as $entity_id) {
$entities[$entity_id]->rules_config = rules_config_load($entities[$entity_id]->rules_config);
// If rule didn't load unset this entity
if (empty($entities[$entity_id]->rules_config)) {
unset($entities[$entity_id]);
}
}
}
It uses the same rules_config property to store either the string or the object. The problem arises when this entity is cached in entity_load(), so the first entity_load() call returns a string in this property, and the second entity_load() call returns the object loaded by rules_config_load(). This is the common case if you define both 'update rule' and 'validation rule' for the same entity bundle.
The proposed patch adds checking of value type of rules_config property.
Comments
Comment #1
tedbow@maximpodorov , maybe we should store it in different property on the object altogether?
Comment #2
maximpodorov commentedYes, it's better if it doesn't break the existing code. But storing entity rules configuration in entities was added recently, so it seems safe to modify this internal structures.
Comment #3
tedbowOk here is patch that adds a "loaded_rules_config" property
Comment #4
maximpodorov commentedLooks reasonable. And no more warnings with the last patch.
Comment #5
tedbowOk committed this to 7.x-1.dev
Comment #6
tedbow