/**
  * @url GET run
  */
 public function run()
 {
     try {
         $session = Session::singleton();
         $db = Database::singleton();
         $allowedRoles = (array) Config::get('allowedRolesForRunFunction', 'execEngine');
         if (Config::get('loginEnabled') && !is_null($allowedRoles)) {
             $ok = false;
             $sessionRoles = Role::getAllSessionRoles();
             foreach ($sessionRoles as $role) {
                 if (in_array($role->label, $allowedRoles)) {
                     $ok = true;
                 }
             }
             if (!$ok) {
                 throw new Exception("You do not have access to run the exec engine", 401);
             }
         }
         $session->setRole();
         ExecEngine::runAllRules();
         $db->closeTransaction('Run completed', false, true, false);
         $result = array('notifications' => Notifications::getAll());
         return $result;
     } catch (Exception $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     }
 }
 /**
  * @url GET run
  * @param array $roleIds
  */
 public function run($roleIds = null)
 {
     try {
         $session = Session::singleton();
         $session->activateRoles($roleIds);
         // Check sessionRoles if allowedRolesForRunFunction is specified
         $allowedRoles = Config::get('allowedRolesForRunFunction', 'execEngine');
         if (!is_null($allowedRoles)) {
             $ok = false;
             foreach ($session->getSessionRoles() as $role) {
                 if (in_array($role->label, $allowedRoles)) {
                     $ok = true;
                 }
             }
             if (!$ok) {
                 throw new Exception("You do not have access to run the exec engine", 401);
             }
         }
         ExecEngine::run(true);
         $db = Database::singleton();
         $db->closeTransaction('Run completed', false, true, false);
         $result = array('notifications' => Notifications::getAll());
         return $result;
     } catch (Exception $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     }
 }
function RerunExecEngine($logText = 'run ExecEngine again after completion')
{
    Notifications::addLog('Rerun: ' . $logText, 'ExecEngine');
    ExecEngine::$doRun = true;
    return true;
}
 public static function fixViolations($rule, $violations)
 {
     if (count($violations)) {
         Notifications::addLog('ExecEngine fixing violations for rule: ' . $rule['name'], 'ExecEngine');
         foreach ($violations as $violation) {
             $theMessage = ExecEngine::getPairView($violation['src'], $rule['srcConcept'], $violation['tgt'], $rule['tgtConcept'], $rule['pairView']);
             // This function tries to return a string with all NULL bytes, HTML and PHP tags stripped from a given str. Strip_tags() is binary safe.
             // $theCleanMessage = strip_tags($theMessage);
             // Determine actions/functions to be taken
             $functionsToBeCalled = explode('{EX}', $theMessage);
             // Execute actions/functions
             foreach ($functionsToBeCalled as $functionToBeCalled) {
                 if (empty($functionToBeCalled)) {
                     continue;
                 }
                 // skips to the next iteration if $functionToBeCalled is empty. This is the case when violation text starts with delimiter {EX}
                 // Determine delimiter
                 if (substr($functionToBeCalled, 0, 2) == '_;') {
                     $delimiter = '_;';
                     $functionToBeCalled = substr($functionToBeCalled, 2);
                 } else {
                     $delimiter = ';';
                 }
                 $params = explode($delimiter, $functionToBeCalled);
                 // Split off variables
                 $params = array_map('trim', $params);
                 // Trim all params
                 $params = array_map('phpArgumentInterpreter', $params);
                 // Evaluate phpArguments, using phpArgumentInterpreter function
                 $function = array_shift($params);
                 // First parameter is function name
                 $classMethod = (array) explode('::', $function);
                 if (function_exists($function) || method_exists($classMethod[0], $classMethod[1])) {
                     $successMessage = call_user_func_array($function, $params);
                     Notifications::addLog($successMessage, 'ExecEngine');
                 } else {
                     $errorMessage = "Function '" . $function . "' does not exists. Create function with " . count($params) . " parameters";
                     throw new Exception($errorMessage, 500);
                 }
             }
         }
         Notifications::addInfo(self::$roleName . ' fixed violations for rule: ' . $rule['name'], 'ExecEngineSuccessMessage', self::$roleName . ' fixed violations');
     }
 }