Skip to content
Snippets Groups Projects
Commit c7f46de7 authored by Erik Hommel's avatar Erik Hommel
Browse files

updated validation of api Event Create

parent 8b90f68b
Branches
Tags
No related merge requests found
......@@ -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
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment