-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Problem/Motivation
In certain circumstances, AZ Event nodes can reference Smart Date recurrence rules which have been deleted from the database. Visiting the node page results in a PHP error such as this:
Error: Call to a member function get() on null in az_event_get_recurrence_text() (line 323 of /usr/local/quickstart-install-profile/modules/custom/az_event/az_event.module).
Describe the bug
PHP errors can be caused by a lack of null checking of the Smart Date rule for an event in the az_event.module file.
One instance is on line 322:
az_quickstart/modules/custom/az_event/az_event.module
Lines 320 to 322 in 08531d1
| /** @var \Drupal\smart_date_recur\Entity\SmartDateRule $smart_date_rule */ | |
| $smart_date_rule = \Drupal::entityTypeManager()->getStorage('smart_date_rule')->load($rule_index); | |
| $start_date = (new \DateTime)->setTimestamp($smart_date_rule->get('start')[0]->getString()); |
A second instance is on line 216:
az_quickstart/modules/custom/az_event/az_event.module
Lines 214 to 216 in 08531d1
| /** @var \Drupal\smart_date_recur\Entity\SmartDateRule $smart_date_rule */ | |
| $smart_date_rule = \Drupal::entityTypeManager()->getStorage('smart_date_rule')->load($event_rrules[0]); | |
| $are_occurrences_modified = empty($smart_date_rule->getRuleOverrides()) ? FALSE : TRUE; |
In both cases, the $smart_date_rule variable can be null, causing a white screen PHP error to be displayed.
To Reproduce
The field_az_event_date_rrule field of an AZ Event node can reference a non-existent Smart Date recurrence rule when an event node is cloned and then the recurrence is removed from the original node or the cloned node.
For example, if the cloned event node is edited to remove the recurrence, then upon saving that node, the reference to the recurrence rule is removed AND the recurrence rule itself is deleted from the smart_date_rule table in the database. The field_az_event_date_rrule field of the original node still references that deleted recurrence rule, resulting in errors. Editing the original node and saving it again resolves the issue, since it clears that field.
Note: This behavior can also result in changes to the dates of the original event if the cloned node recurrence is modified rather than deleted.
Steps to reproduce the behavior:
- Create an event with a recurrence.
- Clone the event and save it.
- Edit the cloned event and remove the recurrence (set Repeats to "never" and save the event).
- Clear cache.
- Visit the page for the original event and observe the white screen error.
Proposed resolution
- Add null checking when loading Smart Date rules to prevent the PHP errors.
- Follow up with a separate issue and/or updates to documentation to warn about potential issues when cloning Quickstart events that use recurrences.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Status
Status