From 5617488da81d27aea81a0a3c6f5142ebc8c42ff5 Mon Sep 17 00:00:00 2001 From: colemanw Date: Tue, 5 Sep 2023 12:18:59 -0400 Subject: [PATCH] ActionSchedule - Don't crash when mapping type is missing --- CRM/Core/BAO/ActionSchedule.php | 37 ++++++++++++--------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 4e2b468a39..df6f784ded 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -16,6 +16,7 @@ */ use Civi\ActionSchedule\Event\MappingRegisterEvent; +use Civi\ActionSchedule\MappingBase; use Civi\Core\HookInterface; /** @@ -86,10 +87,8 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements */ public static function getEntityValueOptions(string $fieldName, array $params): array { $values = self::fillValues($params['values'], ['mapping_id']); - if (!$values['mapping_id']) { - return []; - } - return self::getMapping($values['mapping_id'])->getValueLabels(); + $mapping = self::getMapping($values['mapping_id']); + return $mapping ? $mapping->getValueLabels() : []; } /** @@ -98,10 +97,8 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements */ public static function getLimitToOptions(string $fieldName, array $params): ?array { $values = self::fillValues($params['values'], ['mapping_id']); - if (!$values['mapping_id']) { - return Civi\ActionSchedule\MappingBase::getLimitToOptions(); - } - return self::getMapping($values['mapping_id'])::getLimitToOptions(); + $mapping = self::getMapping($values['mapping_id']); + return $mapping ? $mapping::getLimitToOptions() : MappingBase::getLimitToOptions(); } /** @@ -110,10 +107,8 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements */ public static function getRecipientOptions(string $fieldName, array $params): ?array { $values = self::fillValues($params['values'], ['mapping_id']); - if (!$values['mapping_id']) { - return Civi\ActionSchedule\MappingBase::getRecipientTypes(); - } - return self::getMapping($values['mapping_id'])::getRecipientTypes(); + $mapping = self::getMapping($values['mapping_id']); + return $mapping ? $mapping::getRecipientTypes() : MappingBase::getRecipientTypes(); } /** @@ -122,10 +117,8 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements */ public static function getRecipientListingOptions(string $fieldName, array $params): ?array { $values = self::fillValues($params['values'], ['mapping_id', 'recipient']); - if (!$values['mapping_id']) { - return []; - } - return self::getMapping($values['mapping_id'])->getRecipientListing($values['recipient']); + $mapping = self::getMapping($values['mapping_id']); + return $mapping ? $mapping->getRecipientListing($values['recipient']) : []; } /** @@ -134,10 +127,8 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements */ public static function getEntityStatusOptions(string $fieldName, array $params): array { $values = self::fillValues($params['values'], ['mapping_id', 'entity_value']); - if (!$values['mapping_id']) { - return []; - } - return self::getMapping($values['mapping_id'])->getStatusLabels($values['entity_value']); + $mapping = self::getMapping($values['mapping_id']); + return $mapping ? $mapping->getStatusLabels($values['entity_value']) : []; } /** @@ -146,10 +137,8 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements */ public static function getActionDateOptions(string $fieldName, array $params): array { $values = self::fillValues($params['values'], ['mapping_id', 'entity_value']); - if (!$values['mapping_id']) { - return []; - } - return self::getMapping($values['mapping_id'])->getDateFields($values['entity_value']); + $mapping = self::getMapping($values['mapping_id']); + return $mapping ? $mapping->getDateFields($values['entity_value']) : []; } /** -- 2.25.1