diff --git a/CRM/Civirules/BAO/Event.php b/CRM/Civirules/BAO/Event.php index 33dd1966fc262a95a24d3f4533b18c97b2745874..668a671b7ee9f3338d40426bb83689cdd987a47d 100755 --- a/CRM/Civirules/BAO/Event.php +++ b/CRM/Civirules/BAO/Event.php @@ -134,4 +134,30 @@ class CRM_Civirules_BAO_Event extends CRM_Civirules_DAO_Event { $event->find(true); return $event->label; } + + /** + * Function to check if an event exists with class_name or object_name/op + * + * @param array $params + * @return bool + * @access public + * @static + */ + public static function eventExists($params) { + if (isset($params['class_name']) && !empty($params['class_name'])) { + $checkParams['class_name'] = $params['class_name']; + } else { + if (isset($params['object_name']) && isset($params['op']) && !empty($params['object_name']) && !empty($params['op'])) { + $checkParams['object_name'] = $params['object_name']; + $checkParams['op'] = $params['op']; + } + } + if (!empty($checkParams)) { + $foundEvents = self::getValues($checkParams); + if (!empty($foundEvents)) { + return TRUE; + } + } + return FALSE; + } } \ No newline at end of file diff --git a/api/v3/CiviRuleEvent/Create.php b/api/v3/CiviRuleEvent/Create.php index dc8dacdb93db46016e5b7fc721c315e07b6c8927..a79735006402305f11c1e23b554cf9dfc37deb8f 100755 --- a/api/v3/CiviRuleEvent/Create.php +++ b/api/v3/CiviRuleEvent/Create.php @@ -55,6 +55,13 @@ function _validateParams($params) { if (_checkClassNameObjectNameOperation($params) == FALSE) { return ts('Either class_name or a combination of object_name and op is mandatory'); } + if (isset($params['cron']) && $params['cron'] == 1) { + $params['object_name'] = null; + $params['op'] = null; + if (!isset($params['class_name']) || empty($params['class_name'])) { + return ts('For a cron type event the class_name is mandatory'); + } + } if (isset($params['object_name']) && !empty($params['object_name'])) { $extensionConfig = CRM_Civirules_Config::singleton(); if (!in_array($params['object_name'], $extensionConfig->getValidEventObjectNames())) { @@ -69,6 +76,10 @@ function _validateParams($params) { .')is not a valid operation for a CiviRule Event'); } } + if (CRM_Civirules_BAO_Event::eventExists($params) == TRUE) { + return ts('There is already an event for this class_name or combination of object_name and op'); + } + return $errorMessage; }