*/
use Civi\ActionSchedule\Event\MappingRegisterEvent;
+use Civi\Core\HookInterface;
/**
* This class contains functions for managing Scheduled Reminders
*/
-class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule {
+class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements HookInterface {
/**
* @param array $filters
return self::writeRecord($params);
}
+ /**
+ * @param \Civi\Core\Event\PreEvent $event
+ * @implements hook_civicrm_pre
+ */
+ public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
+ if (in_array($event->action, ['create', 'edit'])) {
+ if (isset($event->params['limit_to']) && in_array($event->params['limit_to'], [0, '0', FALSE], TRUE)) {
+ CRM_Core_Error::deprecatedWarning('Deprecated value "0" is no longer a valid option for ActionSchedule.limit_to; changed to "2".');
+ $event->params['limit_to'] = 2;
+ }
+ }
+ }
+
/**
* Retrieve DB object and copy to defaults array.
*
// https://lab.civicrm.org/dev/rc/-/issues/14
$fieldValue = 1;
}
+ if ($fieldName === 'limit_to' && in_array($fieldValue, [0, '0'], TRUE)) {
+ // https://github.com/civicrm/civicrm-core/pull/26881
+ // FALSE will bypass the below validation and then the BAO will change it to 2 with a deprecation notice
+ $fieldValue = FALSE;
+ }
if (strpos(($op ?? ''), 'NULL') !== FALSE || strpos(($op ?? ''), 'EMPTY') !== FALSE) {
return;
}
* @group headless
*/
class api_v3_ActionScheduleTest extends CiviUnitTestCase {
- protected $_params;
- protected $_params2;
+
protected $_entity = 'action_schedule';
/**
$this->assertEquals($actionSchedule['values'][$actionSchedule['id']]['start_action_offset'], $params['start_action_offset']);
$newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule');
$this->assertEquals($oldCount + 1, $newCount);
+ }
+ public function testDeprecatedLimitToValue(): void {
+ $params = [
+ 'title' => 'Hello',
+ 'limit_to' => 0,
+ 'entity_value' => 'Meeting',
+ 'entity_status' => 'Scheduled',
+ 'mapping_id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID,
+ 'start_action_date' => 'activity_date_time',
+ 'body_html' => 'Test description',
+ 'subject' => 'Test subject',
+ ];
+ $actionSchedule = $this->callAPIFailure('action_schedule', 'create', $params);
+ $this->assertStringContainsString('ActionSchedule.limit_to', $actionSchedule['error_message']);
}
}