getParentEntity in SmartDateRule Preventing New Instance Creation

Created on 30 April 2024, 7 months ago
Updated 27 May 2024, 6 months ago

Problem/Motivation

I have a site that has several SmartDate Recur rules that are supposed to create new instances when needed on cron runs. I noticed recently that while the list of instances was correct in a rule's instances field and in the UI, the new instances were not being created as rows in my content type's node__field_xxx. (In my case this is node__field_date.) Because of this, a view that looks for a current date instance was not working.

After some digging, I tracked this down to an issue with a few of the rules that had field_name set to a field that no longer existed. When the getParentEntity() method ran during cron, and $field_name was used in the entity query with a deleted field, cron stopped the process and never got to the process of making new instances. The code was checking the entity_type was defined but was not checking bundle or field name.

Steps to reproduce

Create a SmartDate Recur rule on a field. Delete the field and run cron

Proposed resolution

I added a method "validateRule" to SmartDateRule. This returns TRUE if entity type, bundle and field name are all defined and field name is defined in the type/bundle and FALSE if any of the checks fail.

I then added a call to this new method before getParentEntity is called.

In addition, I created a drush command, "smart_date_recur:prune-invalid-rules" that checks the rules and removes invalid ones from the database.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

4.1

Component

Smart Date Recur

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024