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

change columns in CiviRule Event to object_name and op

parent d4bf77f4
Branches
Tags
No related merge requests found
......@@ -154,27 +154,27 @@ class CRM_Civirules_BAO_Rule extends CRM_Civirules_DAO_Rule {
/**
* Returns an array with rules which should be triggered
*
* @param $entity ObjectName in the Post hook
* @param $action op in the Post hook
* @param $objectName ObjectName in the Post hook
* @param $op op in the Post hook
* @return array
*/
public static function findRulesByObjectnameAndAction($entity, $action)
public static function findRulesByObjectNameAndOp($objectName, $op)
{
$rules = array();
$sql = "SELECT r.id AS rule_id, e.id AS event_id
FROM `civirule_rule` r
INNER JOIN `civirule_event` e ON r.event_id = e.id AND e.is_active = 1
WHERE r.`is_active` = 1 AND (e.class_name IS NULL OR e.class_name = '') AND e.entity = %1 AND e.action = %2";
$params[1] = array($entity, 'String');
$params[2] = array($action, 'String');
WHERE r.`is_active` = 1 AND (e.class_name IS NULL OR e.class_name = '') AND e.object_name = %1 AND e.op = %2";
$params[1] = array($objectName, 'String');
$params[2] = array($op, 'String');
$dao = CRM_Core_DAO::executeQuery($sql, $params);
while ($dao->fetch()) {
$rule_data = array(
$ruleData = array(
'event_id' => $dao->event_id,
'rule_id' => $dao->rule_id,
);
$rules[] = $rule_data;
$rules[] = $ruleData;
}
return $rules;
}
......
......@@ -14,8 +14,8 @@ class CRM_Civirules_Config
/*
* properties to hold the valid entities and actions for civirule event
*/
protected $validEventEntities = NULL;
protected $validEventActions = NULL;
protected $validEventObjectNames = NULL;
protected $validEventOperations = NULL;
/**
* Constructor
......@@ -46,9 +46,9 @@ class CRM_Civirules_Config
* @return int
* @access public
*/
public function getValidEventEntities()
public function getValidEventObjectNames()
{
return $this->validEventEntities;
return $this->validEventObjectNames;
}
/**
......@@ -57,19 +57,19 @@ class CRM_Civirules_Config
* @return int
* @access public
*/
public function getValidEventActions()
public function getValidEventOperations()
{
return $this->validEventActions;
return $this->validEventOperations;
}
protected function setEventProperties() {
$this->validEventActions = array(
$this->validEventOperations = array(
'create',
'edit',
'delete',
'restore',
'trash');
$this->validEventEntities = array(
$this->validEventObjectNames = array(
'Activity',
'Address',
'Case',
......
......@@ -44,13 +44,13 @@ class CRM_Civirules_DAO_Event extends CRM_Core_DAO {
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
),
'entity' => array(
'name' => 'entity',
'object_name' => array(
'name' => 'object_name',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 45,
),
'action' => array(
'name' => 'action',
'op' => array(
'name' => 'op',
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 45
),
......@@ -96,8 +96,8 @@ class CRM_Civirules_DAO_Event extends CRM_Core_DAO {
'id' => 'id',
'name' => 'name',
'label' => 'label',
'entity' => 'entity',
'action' => 'action',
'object_name' => 'object_name',
'op' => 'op',
'class_name' => 'class_name',
'is_active' => 'is_active',
'created_date' => 'created_date',
......
......@@ -9,6 +9,10 @@
*/
function _civicrm_api3_civi_rule_event_create_spec(&$spec) {
$spec['label']['api_required'] = 1;
$spec['name']['api_required'] = 0;
$spec['object_name']['api_required'] = 0;
$spec['op']['api_required'] = 0;
$spec['class_name']['api_required'] = 0;
}
/**
......@@ -24,9 +28,6 @@ function civicrm_api3_civi_rule_event_create($params) {
if (!empty($errorMessage)) {
return civicrm_api3_create_error($errorMessage);
}
/*
* set created or modified date and user_id
*/
$session = CRM_Core_Session::singleton();
$userId = $session->get('userID');
if (isset($params['id'])) {
......@@ -54,18 +55,18 @@ function _validateParams($params) {
if (_checkClassNameEntityAction($params) == FALSE) {
return ts('Either Class Name or a combination of Entity/Action is mandatory');
}
if (isset($params['entity']) && !empty($params['entity'])) {
if (isset($params['object_name']) && !empty($params['object_name'])) {
$extensionConfig = CRM_Civirules_Config::singleton();
if (!in_array($params['entity'], $extensionConfig->getValidEventEntities())) {
return ts('Entity passed in parameters ('.$params['entity']
.')is not a valid entity for a CiviRule Event');
if (!in_array($params['object_name'], $extensionConfig->getValidEventObjectNames())) {
return ts('ObjectName passed in parameters ('.$params['object_name']
.')is not a valid object for a CiviRule Event');
}
}
if (isset($params['action']) && !empty($params['action'])) {
if (isset($params['op']) && !empty($params['op'])) {
$extensionConfig = CRM_Civirules_Config::singleton();
if (!in_array($params['action'], $extensionConfig->getValidEventActions())) {
return ts('Action passed in parameters ('.$params['action']
.')is not a valid action for a CiviRule Event');
if (!in_array($params['op'], $extensionConfig->getValidEventOperations())) {
return ts('Operation passed in parameters ('.$params['op']
.')is not a valid operation for a CiviRule Event');
}
}
return $errorMessage;
......@@ -79,15 +80,15 @@ function _validateParams($params) {
*/
function _checkClassNameEntityAction($params) {
if (isset($params['class_name']) && !empty($params['class_name'])) {
if (!isset($params['entity']) && !isset($params['action'])) {
if (!isset($params['object_name']) && !isset($params['op'])) {
return TRUE;
} else {
if (empty($params['entity']) && empty($params['action'])) {
if (empty($params['object_name']) && empty($params['op'])) {
return TRUE;
}
}
}
if (isset($params['entity']) && isset($params['action']) && !empty($params['entity']) && !empty($params['action'])) {
if (isset($params['object_name']) && isset($params['op']) && !empty($params['object_name']) && !empty($params['op'])) {
if (!isset($params['class_name']) || empty($params['class_name'])) {
return TRUE;
}
......
......@@ -2,8 +2,8 @@ CREATE TABLE IF NOT EXISTS civirule_event (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(80) NULL,
label VARCHAR(128) NULL,
entity VARCHAR(45) NULL,
action VARCHAR(45) NULL,
object_name VARCHAR(45) NULL,
op VARCHAR(45) NULL,
class_name VARCHAR(128) NULL,
is_active TINYINT NULL DEFAULT 1,
created_date DATE NULL,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment