/** * Triggers the workflows scheduled for running. */ public function runWorkflows() { $arrWorkflows = class_module_workflows_workflow::getWorkflowsByType(class_module_workflows_workflow::$INT_STATE_SCHEDULED); class_logger::getInstance(self::STR_LOGFILE)->addLogRow("running workflows, count: " . count($arrWorkflows), class_logger::$levelInfo); foreach ($arrWorkflows as $objOneWorkflow) { //lock the workflow $objLockmanager = new class_lockmanager($objOneWorkflow->getSystemid()); if ($objLockmanager->isLocked()) { class_logger::getInstance(self::STR_LOGFILE)->addLogRow("workflow " . $objOneWorkflow->getSystemid() . " is locked, can't be scheduled", class_logger::$levelWarning); continue; } $objLockmanager->lockRecord(); /** * @var interface_workflows_handler */ $objHandler = $objOneWorkflow->getObjWorkflowHandler(); //trigger the workflow class_logger::getInstance(self::STR_LOGFILE)->addLogRow("executing workflow " . $objOneWorkflow->getSystemid(), class_logger::$levelInfo); if ($objHandler->execute()) { //handler executed successfully. shift to state 'executed' $objOneWorkflow->setIntState(class_module_workflows_workflow::$INT_STATE_EXECUTED); class_logger::getInstance(self::STR_LOGFILE)->addLogRow(" execution finished, new state: executed", class_logger::$levelInfo); } else { //handler failed to execute. reschedule. $objHandler->schedule(); $objOneWorkflow->setIntState(class_module_workflows_workflow::$INT_STATE_SCHEDULED); class_logger::getInstance(self::STR_LOGFILE)->addLogRow(" execution finished, new state: scheduled", class_logger::$levelInfo); } $objOneWorkflow->setIntRuns($objOneWorkflow->getIntRuns() + 1); $objOneWorkflow->updateObjectToDb(); $objLockmanager->unlockRecord(true); } class_logger::getInstance(self::STR_LOGFILE)->addLogRow("running workflows finished", class_logger::$levelInfo); }
/** * @xml * @permissions edit * @return string */ protected function actionUpdateObjectProperty() { $strReturn = ""; //get the object to update /** @var $objObject class_module_pages_element */ $objObject = class_objectfactory::getInstance()->getObject($this->getSystemid()); if ($objObject->rightEdit()) { //differ between two modes - page-elements or regular objects if ($objObject instanceof class_module_pages_pageelement) { $strPageSystemid = $objObject->getPrevId(); $objLockmanager = new class_lockmanager($objObject->getSystemid()); if (!$objLockmanager->isLocked()) { $objLockmanager->lockRecord(); } if ($objLockmanager->isLockedByCurrentUser()) { //and finally create the object /** @var class_module_pages_pageelement $objElement */ $strElementClass = str_replace(".php", "", $objObject->getStrClassAdmin()); //and finally create the object /** @var $objElement class_element_admin */ $objElement = new $strElementClass(); $objElement->setSystemid($this->getSystemid()); $arrElementData = $objElement->loadElementData(); //see if we could set the param to the element if ($this->getParam("property") != "") { $strProperty = null; //try to fetch the matching setter $objReflection = new class_reflection($objElement); //try to fetch the property based on the orm annotations $strTargetTable = $objReflection->getAnnotationValuesFromClass(class_orm_base::STR_ANNOTATION_TARGETTABLE); if (count($strTargetTable) > 0) { $strTargetTable = $strTargetTable[0]; } $arrTable = explode(".", $strTargetTable); if (count($arrTable) == 2) { $strTargetTable = $arrTable[0]; } $arrOrmProperty = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrOrmProperty as $strCurProperty => $strValue) { if ($strValue == $strTargetTable . "." . $this->getParam("property")) { $strProperty = $strCurProperty; } } if ($strProperty == null) { $strProperty = $this->getParam("property"); } $strSetter = $objReflection->getSetter($strProperty); if ($strSetter != null) { call_user_func(array($objElement, $strSetter), $this->getParam("value")); } else { $arrElementData[$this->getParam("property")] = $this->getParam("value"); $objElement->setArrParamData($arrElementData); } } //pass the data to the element, maybe the element wants to update some data $objElement->doBeforeSaveToDb(); //check, if we could save the data, so the element needn't to //woah, we are soooo great $objElement->updateForeignElement(); //Edit Date of page & unlock $objPage = class_objectfactory::getInstance()->getObject($strPageSystemid); $objPage->updateObjectToDb(); $objLockmanager->unlockRecord(); //allow the element to run actions after saving $objElement->doAfterSaveToDb(); //Loading the data of the corresp site $this->flushCompletePagesCache(); $strReturn = "<message><success>element update succeeded</success></message>"; } } else { //any other object - try to find the matching property and write the value if ($this->getParam("property") == "") { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST); return "<message><error>missing property param</error></message>"; } $objReflection = new class_reflection($objObject); $strSetter = $objReflection->getSetter($this->getParam("property")); if ($strSetter == null) { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST); return "<message><error>setter not found</error></message>"; } call_user_func(array($objObject, $strSetter), $this->getParam("value")); $objObject->updateObjectToDb(); $this->flushCompletePagesCache(); $strReturn = "<message><success>object update succeeded</success></message>"; } } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED); $strReturn = "<message><error>" . $this->getLang("ds_gesperrt") . "." . $this->getLang("commons_error_permissions") . "</error></message>"; } return $strReturn; }