/** * @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()); } }
public function ParseFile() { Notifications::addLog('------------------------- EXCEL IMPORT STARTED -------------------------', 'ExcelImport'); $this->ProcessFileContent(); Notifications::addLog('------------------------- END OF EXCEL IMPORT -------------------------', 'ExcelImport'); // Close transaction => ROLLBACK or COMMIT. $this->db->closeTransaction('File uploaded', false, true, false); return Notifications::getAll(); }
/** * @url GET logout */ public function logout() { try { $session = Session::singleton(); $db = Database::singleton(); $db->deleteAtom(session_id(), 'SESSION'); $db->closeTransaction('Logout successfull', false, true, false); return array('notifications' => Notifications::getAll()); } catch (Exception $e) { throw new RestException($e->getCode(), $e->getMessage()); } }
/** * @url GET notifications/all * @param array $roleIds */ public function getAllNotifications($roleIds = null) { try { $session = Session::singleton(); $session->activateRoles($roleIds); RuleEngine::getProcessViolationsFromDB($session); return Notifications::getAll(); } catch (Exception $e) { throw new RestException($e->getCode(), $e->getMessage()); } }
public function post(&$interface, $request_data, $requestType) { switch ($requestType) { case 'feedback': $databaseCommit = false; break; case 'promise': $databaseCommit = true; break; default: throw new Exception("Unkown request type '{$requestType}'. Supported are: 'feedback', 'promise'", 500); } // Get current state of atom $before = $this->getContent($interface, true, $this->id); $before = current($before); // current(), returns first item of array. This is valid, because put() concerns exactly 1 atom. // Determine differences between current state ($before) and requested state ($request_data) $patches = JsonPatch::diff($before, $request_data); // Skip remove operations, because it is a POST operation and there are no values in de DB yet $patches = array_filter($patches, function ($patch) { return $patch['op'] != 'remove'; }); // Patch foreach ((array) $patches as $key => $patch) { switch ($patch['op']) { case "replace": $this->doPatchReplace($patch, $interface, $before); break; case "add": $this->doPatchAdd($patch, $interface, $before); break; case "remove": $this->doPatchRemove($patch, $interface, $before); break; default: throw new Exception("Unknown patch operation '" . $patch['op'] . "'. Supported are: 'replace', 'add' and 'remove'", 501); } } // $databaseCommit defines if transaction should be committed or not when all invariant rules hold. Returns if invariant rules hold. $invariantRulesHold = $this->database->closeTransaction($this->concept . ' created', false, $databaseCommit); return array('patches' => $patches, 'content' => current((array) $this->newContent), 'notifications' => Notifications::getAll(), 'invariantRulesHold' => $invariantRulesHold, 'requestType' => $requestType); }
/** * @url GET notifications/all * @param int $roleId */ public function getAllNotifications($roleId = 0) { try { $session = Session::singleton(); $session->setRole($roleId); $session->role->getViolations(); return Notifications::getAll(); } catch (Exception $e) { throw new RestException($e->getCode(), $e->getMessage()); } }