Cron in smart_date_recur not working due to property_exists

Created on 22 August 2023, over 1 year ago
Updated 7 May 2024, 7 months ago

Problem/Motivation

In smart_date_recur_cron there is the following code block:

  $ids = \Drupal::entityTypeManager()->getStorage('smart_date_rule')->getRuleIdsToCheck();
  foreach (SmartDateRule::loadMultiple($ids) as $rule) {
    if (!is_object($rule) || !property_exists($rule, 'entity_type')) {
      continue;
    }

As $rule is a content entity of type SmartDateRule, the property_exists will always return FALSE, and as a result, the array $to_process will always remain empty.

Proposed resolution

if (!is_object($rule) || !property_exists($rule, 'entity_type')) { should be replaced by this:

if (!($rule instanceof SmartDateRule) || !$rule->hasField('entity_type')) {

Happy to provide an MR, if the approach is correct and I haven't missed anything?

🐛 Bug report
Status

Fixed

Version

4.1

Component

Smart Date Recur

Created by

🇩🇪Germany jurgenhaas Gottmadingen

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

Comments & Activities

  • Issue created by @jurgenhaas
  • Status changed to Needs review about 1 year ago
  • 🇨🇦Canada mandclu

    Here's a patch that should fix the logic.

  • Status changed to RTBC about 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This does the job. I'm just uncertain why that if-statement is even required in the first place. SmartDateRule::loadMultiple($ids) never returns anything other than a list of SmartDateRule entities. So why checking?

    However, if there's a reason that I don't see, as for the purpose of this issue, this patch fixes it and is RTBC.

    • mandclu committed a5136ff5 on 4.1.x
      Issue #3382603 by mandclu: Cron in smart_date_recur not working due to...
  • Status changed to Fixed about 1 year ago
  • 🇨🇦Canada mandclu

    The check was added in #3281805: smart_date_recur_cron() - runs into an error to resolve an error that creating problems during cron runs. I never actually uncovered the source of the error, but validating that the necessary data is available seems reasonable enough.

    Thanks for the quick feedback, merged in these changes.

  • Status changed to RTBC about 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks for fixing this. The data check was probably necessary if the format of the entity changed some time back. Never mind, should be OK now.

  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 7 months ago
  • Since the previous queue wasn't working properly, you might be in a situation where the next queue is scheduled to run in 7 days time, which means that a manual reset might be required in order to process them as soon as possible:

    drush php-eval '\Drupal::state()->set("smart_date_recur_check", 0);'
    
Production build 0.71.5 2024