Skip to content
Snippets Groups Projects
Unverified Commit b06144b6 authored by Sandor Semsey's avatar Sandor Semsey
Browse files

CRM_Civirules_BAO_CiviRulesCondition::getConditionObjectById: cache condition class names

parent 9c892bac
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,11 @@
*/
class CRM_Civirules_BAO_CiviRulesCondition extends CRM_Civirules_DAO_Condition {
/**
* @var array
*/
protected static $conditionClassNames = [];
/**
* Function to get values
*
......@@ -139,21 +144,26 @@ class CRM_Civirules_BAO_CiviRulesCondition extends CRM_Civirules_DAO_Condition {
* @throws Exception if abort is set to true and class does not exist or is not valid
*/
public static function getConditionObjectById(int $conditionID, bool $abort=TRUE) {
$condition = new CRM_Civirules_BAO_Condition();
$condition->id = $conditionID;
if (!$condition->find(TRUE)) {
if ($abort) {
throw new Exception('CiviRule could not find condition');
if (isset(self::$conditionClassNames[$conditionID])) {
$className = self::$conditionClassNames[$conditionID];
} else {
$condition = new CRM_Civirules_BAO_Condition();
$condition->id = $conditionID;
if (!$condition->find(TRUE)) {
if ($abort) {
throw new Exception('CiviRule could not find condition');
}
return FALSE;
}
return FALSE;
}
$className = $condition->class_name;
if (!class_exists($className)) {
if ($abort) {
throw new Exception('CiviRule condition class "' . $className . '" does not exist');
$className = $condition->class_name;
if (!class_exists($className)) {
if ($abort) {
throw new Exception('CiviRule condition class "' . $className . '" does not exist');
}
return FALSE;
}
return FALSE;
self::$conditionClassNames[$conditionID] = $className;
}
$object = new $className();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment