예제 #1
0
 /**
  * Update Message-Type-Variable
  *
  * @param string $messageTypeVariable Uid Unique id of Message-Type-Variable
  * @param array  $arrayData           Data
  *
  * return array Return data of the Message-Type-Variable updated
  */
 public function update($messageTypeVariableUid, array $arrayData)
 {
     try {
         //Verify data
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         unset($arrayData["MSGTV_UID"]);
         unset($arrayData["MSGT_UID"]);
         //Set variables
         $arrayMessageTypeVariableData = $this->getMessageTypeVariable($messageTypeVariableUid, true);
         //Verify data
         $this->throwExceptionIfNotExistsMessageTypeVariable($messageTypeVariableUid, $this->arrayFieldNameForException["messageTypeVariableUid"]);
         $this->throwExceptionIfDataIsInvalid($messageTypeVariableUid, $arrayMessageTypeVariableData["MSGT_UID"], $arrayData);
         //Update
         $cnn = \Propel::getConnection("workflow");
         try {
             $messageTypeVariable = \MessageTypeVariablePeer::retrieveByPK($messageTypeVariableUid);
             $messageTypeVariable->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             if ($messageTypeVariable->validate()) {
                 $cnn->begin();
                 $result = $messageTypeVariable->save();
                 $cnn->commit();
                 //Return
                 if (!$this->formatFieldNameInUppercase) {
                     $arrayData = array_change_key_case($arrayData, CASE_LOWER);
                 }
                 return $arrayData;
             } else {
                 $msg = "";
                 foreach ($messageTypeVariable->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #2
0
    /**
     * Update Email-Event
     *
     * @param string $emailEventUid Unique id of Email-Event
     * @param array  $arrayData Data
     *
     * return array Return data of the Email-Event updated
     */
    public function update($emailEventUid, array $arrayData)
    {
        try {
            //Verify data
            $validator = new \ProcessMaker\BusinessModel\Validator();

            $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
            $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");

            //Set data
            $arrayData = array_change_key_case($arrayData, CASE_UPPER);
            $arrayDataBackup = $arrayData;

            //Set variables
            $arrayEmailEventData = $this->getEmailEvent($emailEventUid);

            //Verify data
            $this->verifyIfEmailEventExists($emailEventUid); 

            //Update
            $db = \Propel::getConnection("workflow");

            try {
                $emailEvent = \EmailEventPeer::retrieveByPK($emailEventUid);
                $emailEvent->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
         
                $db->begin();
                $result = $emailEvent->save();
                $db->commit();

                $arrayData = $arrayDataBackup;
                $arrayData = array_change_key_case($arrayData, CASE_LOWER);
                return $arrayData;
                
            } catch (\Exception $e) {
                $cnn->rollback();

                throw $e;
            }
        } catch (\Exception $e) {
            throw $e;
        }
    } 
예제 #3
0
 /**
  * Update Role
  *
  * @param string $roleUid   Unique id of Role
  * @param array  $arrayData Data
  *
  * return array Return data of the Role updated
  */
 public function update($roleUid, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         $arrayDataBackup = $arrayData;
         $arrayRoleData = $this->getRole($roleUid);
         //Verify data
         $this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
         if ($roleUid == "00000000000000000000000000000002") {
             throw new \Exception(\G::LoadTranslation("ID_ROLES_MSG"));
         }
         $this->throwExceptionIfDataIsInvalid($roleUid, $arrayData);
         //Update
         $role = new \Roles();
         $arrayData["ROL_UID"] = $roleUid;
         $arrayData["ROL_UPDATE_DATE"] = date("Y-M-d H:i:s");
         if (!isset($arrayData["ROL_NAME"])) {
             $arrayData["ROL_NAME"] = $arrayRoleData[$this->getFieldNameByFormatFieldName("ROL_NAME")];
         }
         if (isset($arrayData["ROL_STATUS"])) {
             $arrayData["ROL_STATUS"] = $arrayData["ROL_STATUS"] == "ACTIVE" ? 1 : 0;
         }
         $result = $role->updateRole($arrayData);
         $arrayData = $arrayDataBackup;
         //Return
         if (!$this->formatFieldNameInUppercase) {
             $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         }
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #4
0
    /**

     * Update User

     *

     * @param string $userUid       Unique id of User

     * @param array  $arrayData     Data

     * @param string $userUidLogged Unique id of User logged

     *

     * return array Return data of the User updated

     */

    public function update($userUid, array $arrayData, $userUidLogged)

    {

        try {

            \G::LoadSystem("rbac");



            //Verify data

            $process = new \ProcessMaker\BusinessModel\Process();

            $validator = new \ProcessMaker\BusinessModel\Validator();



            $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");

            $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");



            //Set data

            $arrayData = array_change_key_case($arrayData, CASE_UPPER);

            $arrayDataBackup = $arrayData;



            //Verify data

            $this->throwExceptionIfNotExistsUser($userUid, $this->arrayFieldNameForException["usrUid"]);



            $this->throwExceptionIfDataIsInvalid($userUid, $arrayData);



            //Permission Admin

            $countPermission = 0;



            $permission = $this->loadUserRolePermission("PROCESSMAKER", $userUidLogged);



            foreach ($permission as $key => $value) {

                if ($value["PER_CODE"] == "PM_USERS") {

                    $countPermission = $countPermission + 1;

                }

            }



            if ($countPermission != 1) {

                throw new \Exception(\G::LoadTranslation("ID_USER_CAN_NOT_UPDATE", array($userUidLogged)));

            }



            //Update

            $cnn = \Propel::getConnection("workflow");



            try {

                $rbac = new \RBAC();

                $user = new \Users();



                $rbac->initRBAC();



                if (isset($arrayData["USR_NEW_PASS"])) {

                    $arrayData["USR_PASSWORD"] = \Bootstrap::hashPassword($arrayData["USR_NEW_PASS"]);

                }



                $arrayData["USR_UID"]              = $userUid;

                $arrayData["USR_LOGGED_NEXT_TIME"] = (isset($arrayData["USR_LOGGED_NEXT_TIME"]))? $arrayData["USR_LOGGED_NEXT_TIME"] : 0;

                $arrayData["USR_UPDATE_DATE"]      = date("Y-m-d H:i:s");



                $flagUserLoggedNextTime = false;



                if (isset($arrayData["USR_PASSWORD"])) {

                    if ($arrayData["USR_PASSWORD"] != "") {

                        //require_once 'classes/model/UsersProperties.php';



                        $userProperty = new \UsersProperties();

                        $aUserProperty = $userProperty->loadOrCreateIfNotExists($userUid, array("USR_PASSWORD_HISTORY" => serialize(array(\Bootstrap::hashPassword($arrayData["USR_PASSWORD"])))));



                        $memKey = "rbacSession" . session_id();

                        $memcache = & \PMmemcached::getSingleton(defined("SYS_SYS")? SYS_SYS : "");



                        if (($rbac->aUserInfo = $memcache->get($memKey)) == false) {

                            $rbac->loadUserRolePermission("PROCESSMAKER", $userUidLogged);

                            $memcache->set($memKey, $rbac->aUserInfo, \PMmemcached::EIGHT_HOURS);

                        }



                        if ($rbac->aUserInfo["PROCESSMAKER"]["ROLE"]["ROL_CODE"] == "PROCESSMAKER_ADMIN") {

                            $aUserProperty["USR_LAST_UPDATE_DATE"] = date("Y-m-d H:i:s");

                            $aUserProperty["USR_LOGGED_NEXT_TIME"] = $arrayData["USR_LOGGED_NEXT_TIME"];

                            $userProperty->update($aUserProperty);

                        }



                        $aHistory = unserialize($aUserProperty["USR_PASSWORD_HISTORY"]);



                        if (!is_array($aHistory)) {

                            $aHistory = array();

                        }



                        if (!defined("PPP_PASSWORD_HISTORY")) {

                            define("PPP_PASSWORD_HISTORY", 0);

                        }



                        if (PPP_PASSWORD_HISTORY > 0) {

                            //it's looking a password igual into aHistory array that was send for post in md5 way

                            $c = 0;

                            $sw = 1;



                            while (count($aHistory) >= 1 && count($aHistory) > $c && $sw) {

                                if (strcmp(trim($aHistory[$c]), trim($arrayData['USR_PASSWORD'])) == 0) {

                                    $sw = 0;

                                }



                                $c++;

                            }



                            if ($sw == 0) {

                                $sDescription = G::LoadTranslation("ID_POLICY_ALERT") . ":\n\n";

                                $sDescription = $sDescription . " - " . G::LoadTranslation("PASSWORD_HISTORY") . ": " . PPP_PASSWORD_HISTORY . "\n";

                                $sDescription = $sDescription . "\n" . G::LoadTranslation("ID_PLEASE_CHANGE_PASSWORD_POLICY") . "";



                                throw new \Exception($this->arrayFieldNameForException["usrNewPass"] . ": " . $sDescription);

                            }



                            if (count($aHistory) >= PPP_PASSWORD_HISTORY) {

                                $sLastPassw = array_shift($aHistory);

                            }



                            $aHistory[] = $arrayData["USR_PASSWORD"];

                        }



                        $aUserProperty["USR_LAST_UPDATE_DATE"] = date("Y-m-d H:i:s");

                        $aUserProperty["USR_LOGGED_NEXT_TIME"] = $arrayData["USR_LOGGED_NEXT_TIME"];

                        $aUserProperty["USR_PASSWORD_HISTORY"] = serialize($aHistory);

                        $userProperty->update($aUserProperty);

                    } else {

                        $flagUserLoggedNextTime = true;

                    }

                } else {

                    $flagUserLoggedNextTime = true;

                }



                if ($flagUserLoggedNextTime) {

                    //require_once "classes/model/Users.php";

                    $oUser = new \Users();

                    $aUser = $oUser->load($userUid);

                    //require_once "classes/model/UsersProperties.php";

                    $oUserProperty = new \UsersProperties();

                    $aUserProperty = $oUserProperty->loadOrCreateIfNotExists($userUid, array("USR_PASSWORD_HISTORY" => serialize(array($aUser["USR_PASSWORD"]))));

                    $aUserProperty["USR_LOGGED_NEXT_TIME"] = $arrayData["USR_LOGGED_NEXT_TIME"];

                    $oUserProperty->update($aUserProperty);

                }



                //Update in rbac

                if (isset($arrayData["USR_ROLE"])) {

                    $rbac->updateUser($arrayData, $arrayData["USR_ROLE"]);

                } else {

                    $rbac->updateUser($arrayData);

                }



                //Update in workflow

                $result = $user->update($arrayData);



                //Save Calendar assigment

                if (isset($arrayData["USR_CALENDAR"])) {

                    //Save Calendar ID for this user

                    \G::LoadClass("calendar");



                    $calendar = new \Calendar();

                    $calendar->assignCalendarTo($userUid, $arrayData["USR_CALENDAR"], "USER");

                }



                //Return

                $arrayData = $arrayDataBackup;



                if (!$this->formatFieldNameInUppercase) {

                    $arrayData = array_change_key_case($arrayData, CASE_LOWER);

                }



                return $arrayData;

            } catch (\Exception $e) {

                $cnn->rollback();



                throw $e;

            }

        } catch (\Exception $e) {

            throw $e;

        }

    }
예제 #5
0
    /**
     * Imports a Project sent through the POST method ($_FILES)
     *
     * @param array  $arrayData      Data
     * @param string $option         Option for Project ("CREATE", "OVERWRITE", "DISABLE", "KEEP")
     * @param string $optionGroup    Option for Group ("CREATE", "RENAME", "MERGE")
     * @param array  $arrayFieldName The field's names
     *
     * return array Returns the data sent and the unique id of Project
     */
    public function importPostFile(array $arrayData, $option = "CREATE", $optionGroup = "CREATE", array $arrayFieldName = array())
    {
        try {
            //Set data
            $arrayFieldName["projectFile"] = (isset($arrayFieldName["projectFile"]))? $arrayFieldName["projectFile"] : "PROJECT_FILE";
            $arrayFieldName["option"] = (isset($arrayFieldName["option"]))? $arrayFieldName["option"] : "OPTION";
            $arrayFieldName["optionGroup"] = (isset($arrayFieldName["optionGroup"]))? $arrayFieldName["optionGroup"] : "OPTION_GROUP";

            $arrayFieldDefinition = array(
                $arrayFieldName["projectFile"] => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectFile")
            );

            $arrayFieldNameForException = $arrayFieldName;

            if (isset($_FILES[$arrayFieldName["projectFile"]])) {
                $_FILES["filePmx"] = $_FILES[$arrayFieldName["projectFile"]];
            }

            if (isset($arrayData[$arrayFieldName["projectFile"]]) &&
                isset($arrayData[$arrayFieldName["projectFile"]]["name"]) &&
                is_array($arrayData[$arrayFieldName["projectFile"]])
            ) {
                $arrayData[$arrayFieldName["projectFile"]] = $arrayData[$arrayFieldName["projectFile"]]["name"];
            }

            $optionCaseUpper = (strtoupper($option) == $option)? true : false;
            $option = strtoupper($option);

            $optionGroupCaseUpper = (strtoupper($optionGroup) == $optionGroup)? true : false;
            $optionGroup = strtoupper($optionGroup);

            //Verify data
            $process = new \ProcessMaker\BusinessModel\Process();
            $validator = new \ProcessMaker\BusinessModel\Validator();

            $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");

            $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayFieldDefinition, $arrayFieldNameForException, true);

            $arrayOptionDefaultValues = array("CREATE", "OVERWRITE", "DISABLE", "KEEP");
            $arrayOptionGroupDefaultValues = array("CREATE", "RENAME", "MERGE");

            $arrayAux = array(
                array($option,      $arrayOptionDefaultValues,      $arrayFieldNameForException["option"],      $optionCaseUpper),
                array($optionGroup, $arrayOptionGroupDefaultValues, $arrayFieldNameForException["optionGroup"], $optionGroupCaseUpper)
            );

            foreach ($arrayAux as $value) {
                $opt = $value[0];
                $arrayDefaultValues = $value[1];
                $fieldNameForException = $value[2];
                $caseUpper = $value[3];

                if ($opt != "") {
                    if (!in_array($opt, $arrayDefaultValues, true)) {
                        $strdv = implode("|", $arrayDefaultValues);

                        throw new \Exception(
                            \G::LoadTranslation(
                                "ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES",
                                array($fieldNameForException, ($caseUpper)? $strdv : strtolower($strdv))
                            )
                        );
                    }
                }
            }

            if ((isset($_FILES["filePmx"]) && pathinfo($_FILES["filePmx"]["name"], PATHINFO_EXTENSION) != "pmx") ||
                (isset($arrayData[$arrayFieldName["projectFile"]]) && pathinfo($arrayData[$arrayFieldName["projectFile"]], PATHINFO_EXTENSION) != "pmx")
            ) {
                throw new \Exception(\G::LoadTranslation("ID_IMPORTER_FILE_EXTENSION_IS_NOT_PMX"));
            }

            //Set variables
            $arrayAux = array(
                (($option != "")? "CREATE" : "") => self::IMPORT_OPTION_CREATE_NEW,
                "OVERWRITE" => self::IMPORT_OPTION_OVERWRITE,
                "DISABLE"   => self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW,
                "KEEP"      => self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW
            );

            $option = $arrayAux[$option];

            $arrayAux = array(
                (($optionGroup != "")? "CREATE" : "") => self::GROUP_IMPORT_OPTION_CREATE_NEW,
                "RENAME" => self::GROUP_IMPORT_OPTION_RENAME,
                "MERGE"  => self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT
            );

            $optionGroup = $arrayAux[$optionGroup];

            if (isset($_FILES["filePmx"])) {
                $this->setSourceFromGlobals("filePmx");
            } else {
                $filePmx = rtrim($this->getSaveDir(), PATH_SEP) . PATH_SEP . $arrayData[$arrayFieldName["projectFile"]];

                if (isset($arrayData[$arrayFieldName["projectFile"]]) && file_exists($filePmx)) {
                    $this->setSourceFile($filePmx);
                } else {
                    throw new \Exception(\G::LoadTranslation("ID_IMPORTER_FILE_DOES_NOT_EXIST", array($arrayFieldNameForException["projectFile"], $arrayData[$arrayFieldName["projectFile"]])));
                }
            }

            //Import
            try {
                $projectUid = $this->import($option, $optionGroup);

                $arrayData = array_merge(array("PRJ_UID" => $projectUid), $arrayData);
            } catch (\Exception $e) {
                $strOpt  = implode("|", $arrayOptionDefaultValues);
                $strOptg = implode("|", $arrayOptionGroupDefaultValues);

                $strOpt = ($optionCaseUpper)? $strOpt : strtolower($strOpt);
                $strOptg = ($optionGroupCaseUpper)? $strOptg : strtolower($strOptg);

                $msg = str_replace(
                    array(
                        self::IMPORT_OPTION_CREATE_NEW,
                        self::IMPORT_OPTION_OVERWRITE,
                        self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW,
                        self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW,

                        self::GROUP_IMPORT_OPTION_CREATE_NEW,
                        self::GROUP_IMPORT_OPTION_RENAME,
                        self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT
                    ),
                    array_merge(explode("|", $strOpt), explode("|", $strOptg)),
                    $e->getMessage()
                );

                throw new \Exception($msg);
            }

            //Return
            if ($arrayFieldName["projectFile"] != strtoupper($arrayFieldName["projectFile"])) {
                $arrayData = array_change_key_case($arrayData, CASE_LOWER);
            }

            return $arrayData;
        } catch (\Exception $e) {
            throw $e;
        }
    }
예제 #6
0
 /**
  * Update Web Entry
  *
  * @param string $webEntryUid    Unique id of Web Entry
  * @param string $userUidUpdater Unique id of updater User
  * @param array  $arrayData      Data
  *
  * return array Return data of the Web Entry updated
  */
 public function update($webEntryUid, $userUidUpdater, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         //Set variables
         $arrayWebEntryData = $this->getWebEntry($webEntryUid, true);
         //Verify data
         $this->throwExceptionIfNotExistsWebEntry($webEntryUid, $this->arrayFieldNameForException["webEntryUid"]);
         $this->throwExceptionIfDataIsInvalid($webEntryUid, $arrayWebEntryData["PRO_UID"], $arrayData);
         //Update
         $cnn = \Propel::getConnection("workflow");
         try {
             $webEntry = \WebEntryPeer::retrieveByPK($webEntryUid);
             $webEntry->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             $webEntry->setWeUpdateUsrUid($userUidUpdater);
             $webEntry->setWeUpdateDate("now");
             if ($webEntry->validate()) {
                 $cnn->begin();
                 $result = $webEntry->save();
                 $cnn->commit();
                 //Set WE_TITLE
                 if (isset($arrayData["WE_TITLE"])) {
                     $result = \Content::addContent("WE_TITLE", "", $webEntryUid, SYS_LANG, $arrayData["WE_TITLE"]);
                 }
                 if (isset($arrayData["WE_DESCRIPTION"])) {
                     $result = \Content::addContent("WE_DESCRIPTION", "", $webEntryUid, SYS_LANG, $arrayData["WE_DESCRIPTION"]);
                 }
                 //Set WE_DATA
                 $this->setWeData($webEntryUid);
                 //Return
                 if (!$this->formatFieldNameInUppercase) {
                     $arrayData = array_change_key_case($arrayData, CASE_LOWER);
                 }
                 return $arrayData;
             } else {
                 $msg = "";
                 foreach ($webEntry->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #7
0
 /**
  * Update Category
  *
  * @param string $categoryUid Unique id of Category
  * @param array  $arrayData   Data
  *
  * return array Return data of the Category updated
  */
 public function update($categoryUid, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         $arrayDataBackup = $arrayData;
         //Verify data
         $this->throwExceptionIfNotExistsCategory($categoryUid, $this->arrayFieldNameForException["categoryUid"]);
         $this->throwExceptionIfDataIsInvalid($categoryUid, $arrayData);
         //Update
         $category = new \ProcessCategory();
         $category->setNew(false);
         $category->setCategoryUid($categoryUid);
         if (isset($arrayData["CAT_NAME"])) {
             $category->setCategoryName($arrayData["CAT_NAME"]);
         }
         $result = $category->save();
         $arrayData = $arrayDataBackup;
         //Return
         if (!$this->formatFieldNameInUppercase) {
             $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         }
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #8
0
 /**
  * Update Timer-Event
  *
  * @param string $timerEventUid Unique id of Timer-Event
  * @param array  $arrayData     Data
  *
  * return int Return the number of rows affected by this update
  */
 public function update($timerEventUid, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         //Set variables
         $arrayTimerEventData = $this->getTimerEvent($timerEventUid, true);
         $arrayFinalData = array_merge($arrayTimerEventData, $arrayData);
         //Verify data
         $this->throwExceptionIfNotExistsTimerEvent($timerEventUid, $this->arrayFieldNameForException["timerEventUid"]);
         $this->throwExceptionIfDataIsInvalid($timerEventUid, $arrayTimerEventData["PRJ_UID"], $arrayData);
         //Update
         $cnn = \Propel::getConnection("workflow");
         $arrayData = $this->unsetFields($arrayData);
         try {
             $timerEvent = \TimerEventPeer::retrieveByPK($timerEventUid);
             $bpmnEvent = \BpmnEventPeer::retrieveByPK($arrayFinalData["EVN_UID"]);
             if (isset($arrayData["TMREVN_START_DATE"])) {
                 $arrayData["TMREVN_START_DATE"] = $arrayData["TMREVN_START_DATE"] . "" != "" ? $arrayData["TMREVN_START_DATE"] : null;
             }
             if (isset($arrayData["TMREVN_END_DATE"])) {
                 $arrayData["TMREVN_END_DATE"] = $arrayData["TMREVN_END_DATE"] . "" != "" ? $arrayData["TMREVN_END_DATE"] : null;
             }
             if (isset($arrayData["TMREVN_NEXT_RUN_DATE"])) {
                 $arrayData["TMREVN_NEXT_RUN_DATE"] = $arrayData["TMREVN_NEXT_RUN_DATE"] . "" != "" ? $arrayData["TMREVN_NEXT_RUN_DATE"] : null;
             }
             if (isset($arrayData["TMREVN_CONFIGURATION_DATA"])) {
                 $arrayData["TMREVN_CONFIGURATION_DATA"] = serialize($arrayData["TMREVN_CONFIGURATION_DATA"]);
             }
             $timerEvent->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             if ($bpmnEvent->getEvnType() == "START") {
                 switch ($arrayFinalData["TMREVN_OPTION"]) {
                     case "HOURLY":
                     case "DAILY":
                     case "MONTHLY":
                     case "EVERY":
                         $flagUpdateNextRunDate = false;
                         $arrayFieldsToCheck = array();
                         switch ($arrayFinalData["TMREVN_OPTION"]) {
                             case "HOURLY":
                                 $arrayFieldsToCheck = array("TMREVN_START_DATE", "TMREVN_END_DATE", "TMREVN_MINUTE");
                                 break;
                             case "DAILY":
                                 $arrayFieldsToCheck = array("TMREVN_START_DATE", "TMREVN_END_DATE", "TMREVN_HOUR", "TMREVN_MINUTE", "TMREVN_CONFIGURATION_DATA");
                                 break;
                             case "MONTHLY":
                                 $arrayFieldsToCheck = array("TMREVN_START_DATE", "TMREVN_END_DATE", "TMREVN_DAY", "TMREVN_HOUR", "TMREVN_MINUTE", "TMREVN_CONFIGURATION_DATA");
                                 break;
                             case "EVERY":
                                 $arrayFieldsToCheck = array("TMREVN_HOUR", "TMREVN_MINUTE");
                                 break;
                         }
                         foreach ($arrayFieldsToCheck as $value) {
                             if (isset($arrayData[$value])) {
                                 if ($value == "TMREVN_CONFIGURATION_DATA") {
                                     $arrayAux = unserialize($arrayData[$value]);
                                     $array1 = array_diff($arrayAux, $arrayTimerEventData[$value]);
                                     $array2 = array_diff($arrayTimerEventData[$value], $arrayAux);
                                     $flagUpdateNextRunDate = !empty($array1) || !empty($array2);
                                 } else {
                                     $flagUpdateNextRunDate = $arrayData[$value] != $arrayTimerEventData[$value];
                                 }
                                 if ($flagUpdateNextRunDate) {
                                     break;
                                 }
                             }
                         }
                         if ($flagUpdateNextRunDate) {
                             $timerEvent->setTmrevnNextRunDate($this->getNextRunDateByDataAndDatetime($arrayFinalData, date("Y-m-d H:i:s")));
                         }
                         break;
                 }
             }
             if ($timerEvent->validate()) {
                 $cnn->begin();
                 $result = $timerEvent->save();
                 $cnn->commit();
                 //Return
                 return $result;
             } else {
                 $msg = "";
                 foreach ($timerEvent->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #9
0
 /**
  * Update Email Server
  *
  * @param string $emailServerUid Unique id of Group
  * @param array  $arrayData      Data
  *
  * return array Return data of the Email Server updated
  */
 public function update($emailServerUid, $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         //Verify data
         $this->throwExceptionIfNotExistsEmailServer($emailServerUid, $this->arrayFieldNameForException["emailServerUid"]);
         $this->throwExceptionIfDataIsInvalid($emailServerUid, $arrayData);
         //Update
         $cnn = \Propel::getConnection("workflow");
         try {
             $emailServer = \EmailServerPeer::retrieveByPK($emailServerUid);
             $passwd = $arrayData["MESS_PASSWORD"];
             $passwdDec = \G::decrypt($passwd, "EMAILENCRYPT");
             $auxPass = explode("hash:", $passwdDec);
             if (count($auxPass) > 1) {
                 if (count($auxPass) == 2) {
                     $passwd = $auxPass[1];
                 } else {
                     array_shift($auxPass);
                     $passwd = implode("", $auxPass);
                 }
             }
             $arrayData["MESS_PASSWORD"] = $passwd;
             if ($arrayData["MESS_PASSWORD"] != "") {
                 $arrayData["MESS_PASSWORD"] = "******" . $arrayData["MESS_PASSWORD"];
                 $arrayData["MESS_PASSWORD"] = \G::encrypt($arrayData["MESS_PASSWORD"], "EMAILENCRYPT");
             }
             $emailServer->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             if ($emailServer->validate()) {
                 $cnn->begin();
                 $result = $emailServer->save();
                 $cnn->commit();
                 if (isset($arrayData["MESS_DEFAULT"]) && (int) $arrayData["MESS_DEFAULT"] == 1) {
                     $this->setEmailServerDefaultByUid($emailServerUid);
                 }
                 //Return
                 if (!$this->formatFieldNameInUppercase) {
                     $arrayData = array_change_key_case($arrayData, CASE_LOWER);
                 }
                 return $arrayData;
             } else {
                 $msg = "";
                 foreach ($emailServer->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #10
0
 /**
  * Create Element-Task-Relation for a Project
  *
  * @param string $projectUid Unique id of Project
  * @param array  $arrayData  Data
  *
  * return array Return data of the new Element-Task-Relation created
  */
 public function create($projectUid, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         unset($arrayData["ETR_UID"]);
         unset($arrayData["PRJ_UID"]);
         //Verify data
         $process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
         $this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
         //Create
         $cnn = \Propel::getConnection("workflow");
         try {
             $elementTaskRelation = new \ElementTaskRelation();
             $elementTaskRelationUid = \ProcessMaker\Util\Common::generateUID();
             $elementTaskRelation->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             $elementTaskRelation->setEtrUid($elementTaskRelationUid);
             $elementTaskRelation->setPrjUid($projectUid);
             if ($elementTaskRelation->validate()) {
                 $cnn->begin();
                 $result = $elementTaskRelation->save();
                 $cnn->commit();
                 //Return
                 return $this->getElementTaskRelation($elementTaskRelationUid);
             } else {
                 $msg = "";
                 foreach ($elementTaskRelation->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #11
0
 /**
  * Update WebEntry-Event
  *
  * @param string $webEntryEventUid Unique id of WebEntry-Event
  * @param string $userUidUpdater   Unique id of updater User
  * @param array  $arrayData        Data
  *
  * return array Return data of the WebEntry-Event updated
  */
 public function update($webEntryEventUid, $userUidUpdater, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         $arrayDataBackup = $arrayData;
         unset($arrayData["WEE_UID"]);
         unset($arrayData["PRJ_UID"]);
         unset($arrayData["WEE_WE_UID"]);
         unset($arrayData["WEE_WE_TAS_UID"]);
         //Set variables
         $arrayWebEntryEventData = $this->getWebEntryEvent($webEntryEventUid, true);
         $arrayFinalData = array_merge($arrayWebEntryEventData, $arrayData);
         //Verify data
         $this->throwExceptionIfNotExistsWebEntryEvent($webEntryEventUid, $this->arrayFieldNameForException["webEntryEventUid"]);
         $this->throwExceptionIfDataIsInvalid($webEntryEventUid, $arrayWebEntryEventData["PRJ_UID"], $arrayData);
         //Update
         $cnn = \Propel::getConnection("workflow");
         $this->webEntryEventWebEntryUid = "";
         $this->webEntryEventWebEntryTaskUid = "";
         try {
             //WebEntry
             $option = "UPDATE";
             if (isset($arrayData["WEE_STATUS"])) {
                 if ($arrayData["WEE_STATUS"] == "ENABLED") {
                     if ($arrayWebEntryEventData["WEE_STATUS"] == "DISABLED") {
                         $option = "INSERT";
                     }
                 } else {
                     if ($arrayWebEntryEventData["WEE_STATUS"] == "ENABLED") {
                         $option = "DELETE";
                     }
                 }
             }
             switch ($option) {
                 case "INSERT":
                     $this->createWebEntry($arrayFinalData["PRJ_UID"], $arrayFinalData["EVN_UID"], $arrayFinalData["ACT_UID"], $arrayFinalData["DYN_UID"], $arrayFinalData["USR_UID"], $arrayFinalData["WEE_TITLE"], $arrayFinalData["WEE_DESCRIPTION"], $userUidUpdater);
                     $arrayData["WEE_WE_UID"] = $this->webEntryEventWebEntryUid;
                     $arrayData["WEE_WE_TAS_UID"] = $this->webEntryEventWebEntryTaskUid;
                     break;
                 case "UPDATE":
                     if ($arrayWebEntryEventData["WEE_WE_UID"] != "") {
                         $task = new \Tasks();
                         //Task - Step
                         if (isset($arrayData["DYN_UID"]) && $arrayData["DYN_UID"] != $arrayWebEntryEventData["DYN_UID"]) {
                             //Delete
                             $step = new \Step();
                             $criteria = new \Criteria("workflow");
                             $criteria->add(\StepPeer::TAS_UID, $arrayWebEntryEventData["WEE_WE_TAS_UID"]);
                             $rsCriteria = \StepPeer::doSelectRS($criteria);
                             $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                             while ($rsCriteria->next()) {
                                 $row = $rsCriteria->getRow();
                                 $result = $step->remove($row["STEP_UID"]);
                             }
                             //Add
                             $step = new \Step();
                             $stepUid = $step->create(array("PRO_UID" => $arrayWebEntryEventData["PRJ_UID"], "TAS_UID" => $arrayWebEntryEventData["WEE_WE_TAS_UID"]));
                             $result = $step->update(array("STEP_UID" => $stepUid, "STEP_TYPE_OBJ" => "DYNAFORM", "STEP_UID_OBJ" => $arrayData["DYN_UID"], "STEP_POSITION" => 1, "STEP_MODE" => "EDIT"));
                         }
                         //Task - User
                         if (isset($arrayData["USR_UID"]) && $arrayData["USR_UID"] != $arrayWebEntryEventData["USR_UID"]) {
                             //Unassign
                             $taskUser = new \TaskUser();
                             $criteria = new \Criteria("workflow");
                             $criteria->add(\TaskUserPeer::TAS_UID, $arrayWebEntryEventData["WEE_WE_TAS_UID"]);
                             $rsCriteria = \TaskUserPeer::doSelectRS($criteria);
                             $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                             while ($rsCriteria->next()) {
                                 $row = $rsCriteria->getRow();
                                 $result = $taskUser->remove($row["TAS_UID"], $row["USR_UID"], $row["TU_TYPE"], $row["TU_RELATION"]);
                             }
                             //Assign
                             $result = $task->assignUser($arrayWebEntryEventData["WEE_WE_TAS_UID"], $arrayData["USR_UID"], 1);
                         }
                         //Route
                         if (isset($arrayData["ACT_UID"]) && $arrayData["ACT_UID"] != $arrayWebEntryEventData["ACT_UID"]) {
                             //Delete
                             $result = $task->deleteAllRoutesOfTask($arrayWebEntryEventData["PRJ_UID"], $arrayWebEntryEventData["WEE_WE_TAS_UID"], true);
                             //Add
                             $workflow = \ProcessMaker\Project\Workflow::load($arrayWebEntryEventData["PRJ_UID"]);
                             $result = $workflow->addRoute($arrayWebEntryEventData["WEE_WE_TAS_UID"], $arrayData["ACT_UID"], "SEQUENTIAL");
                         }
                         //WebEntry
                         $arrayDataAux = array();
                         if (isset($arrayData["DYN_UID"])) {
                             $arrayDataAux["DYN_UID"] = $arrayData["DYN_UID"];
                         }
                         if (isset($arrayData["USR_UID"])) {
                             $arrayDataAux["USR_UID"] = $arrayData["USR_UID"];
                         }
                         if (isset($arrayData["WEE_TITLE"])) {
                             $arrayDataAux["WE_TITLE"] = $arrayData["WEE_TITLE"];
                         }
                         if (isset($arrayData["WEE_DESCRIPTION"])) {
                             $arrayDataAux["WE_DESCRIPTION"] = $arrayData["WEE_DESCRIPTION"];
                         }
                         if (count($arrayDataAux) > 0) {
                             $arrayDataAux = $this->webEntry->update($arrayWebEntryEventData["WEE_WE_UID"], $userUidUpdater, $arrayDataAux);
                         }
                     }
                     break;
                 case "DELETE":
                     $this->deleteWebEntry($arrayWebEntryEventData["WEE_WE_UID"], $arrayWebEntryEventData["WEE_WE_TAS_UID"]);
                     $arrayData["WEE_WE_UID"] = "";
                     $arrayData["WEE_WE_TAS_UID"] = "";
                     break;
             }
             //WebEntry-Event
             $webEntryEvent = \WebEntryEventPeer::retrieveByPK($webEntryEventUid);
             $webEntryEvent->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             if ($webEntryEvent->validate()) {
                 $cnn->begin();
                 $result = $webEntryEvent->save();
                 $cnn->commit();
                 //Set WEE_TITLE
                 if (isset($arrayData["WEE_TITLE"])) {
                     $result = \Content::addContent("WEE_TITLE", "", $webEntryEventUid, SYS_LANG, $arrayData["WEE_TITLE"]);
                 }
                 //Set WEE_DESCRIPTION
                 if (isset($arrayData["WEE_DESCRIPTION"])) {
                     $result = \Content::addContent("WEE_DESCRIPTION", "", $webEntryEventUid, SYS_LANG, $arrayData["WEE_DESCRIPTION"]);
                 }
                 //Return
                 $arrayData = $arrayDataBackup;
                 if (!$this->formatFieldNameInUppercase) {
                     $arrayData = array_change_key_case($arrayData, CASE_LOWER);
                 }
                 return $arrayData;
             } else {
                 $msg = "";
                 foreach ($webEntryEvent->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             $this->deleteWebEntry($this->webEntryEventWebEntryUid, $this->webEntryEventWebEntryTaskUid);
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #12
0
 /**
  * Update Calendar
  *
  * @param string $calendarUid Unique id of Calendar
  * @param array  $arrayData   Data
  *
  * return array Return data of the Calendar updated
  */
 public function update($calendarUid, $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER);
         //Verify data
         $this->throwExceptionIfNotExistsCalendar($calendarUid, $this->arrayFieldNameForException["calendarUid"]);
         $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
         if (isset($arrayData["CAL_NAME"])) {
             $this->throwExceptionIfExistsName($arrayData["CAL_NAME"], $this->arrayFieldNameForException["calendarName"], $calendarUid);
         }
         if (isset($arrayData["CAL_WORK_DAYS"]) && count($arrayData["CAL_WORK_DAYS"]) < 3) {
             throw new \Exception(\G::LoadTranslation("ID_MOST_AT_LEAST_3_DAY"));
         }
         if (isset($arrayData["CAL_WORK_HOUR"])) {
             foreach ($arrayData["CAL_WORK_HOUR"] as $value) {
                 $process->throwExceptionIfDataNotMetFieldDefinition($value, $this->arrayWorkHourFieldDefinition, $this->arrayWorkHourFieldNameForException, true);
             }
         }
         if (isset($arrayData["CAL_HOLIDAY"])) {
             foreach ($arrayData["CAL_HOLIDAY"] as $value) {
                 $process->throwExceptionIfDataNotMetFieldDefinition($value, $this->arrayHolidayFieldDefinition, $this->arrayHolidayFieldNameForException, true);
             }
         }
         //Set variables
         $arrayCalendarData = \G::array_change_key_case2($this->getCalendar($calendarUid), CASE_UPPER);
         $calendarWorkDays = isset($arrayData["CAL_WORK_DAYS"]) ? $arrayData["CAL_WORK_DAYS"] : array_keys($arrayCalendarData["CAL_WORK_DAYS"]);
         $arrayCalendarWorkHour = array();
         $arrayAux = isset($arrayData["CAL_WORK_HOUR"]) ? $arrayData["CAL_WORK_HOUR"] : $arrayCalendarData["CAL_WORK_HOUR"];
         foreach ($arrayAux as $value) {
             if (isset($arrayData["CAL_WORK_HOUR"]) && $value["DAY"] != 0 && !in_array($value["DAY"], $calendarWorkDays, true)) {
                 throw new \Exception(\G::LoadTranslation("ID_VALUE_SPECIFIED_DOES_NOT_EXIST", array($this->arrayWorkHourFieldNameForException["day"], $this->arrayFieldNameForException["calendarWorkDays"])));
             }
             $arrayCalendarWorkHour[] = array("CALENDAR_BUSINESS_DAY" => $this->workDaysTransformData($value["DAY"]), "CALENDAR_BUSINESS_START" => $value["HOUR_START"], "CALENDAR_BUSINESS_END" => $value["HOUR_END"]);
         }
         $arrayCalendarHoliday = array();
         $arrayAux = isset($arrayData["CAL_HOLIDAY"]) ? $arrayData["CAL_HOLIDAY"] : $arrayCalendarData["CAL_HOLIDAY"];
         foreach ($arrayAux as $value) {
             $arrayCalendarHoliday[] = array("CALENDAR_HOLIDAY_NAME" => $value["NAME"], "CALENDAR_HOLIDAY_START" => $value["DATE_START"], "CALENDAR_HOLIDAY_END" => $value["DATE_END"]);
         }
         $arrayDataAux = array();
         $arrayDataAux["CALENDAR_UID"] = $calendarUid;
         $arrayDataAux["CALENDAR_NAME"] = isset($arrayData["CAL_NAME"]) ? $arrayData["CAL_NAME"] : $arrayCalendarData["CAL_NAME"];
         $arrayDataAux["CALENDAR_DESCRIPTION"] = isset($arrayData["CAL_DESCRIPTION"]) ? $arrayData["CAL_DESCRIPTION"] : $arrayCalendarData["CAL_DESCRIPTION"];
         $arrayDataAux["CALENDAR_WORK_DAYS"] = $this->workDaysTransformData($calendarWorkDays);
         $arrayDataAux["CALENDAR_STATUS"] = isset($arrayData["CAL_STATUS"]) ? $arrayData["CAL_STATUS"] : $arrayCalendarData["CAL_STATUS"];
         $arrayDataAux["BUSINESS_DAY"] = $arrayCalendarWorkHour;
         $arrayDataAux["HOLIDAY"] = $arrayCalendarHoliday;
         //Update
         $calendarDefinition = new \CalendarDefinition();
         $calendarDefinition->saveCalendarInfo($arrayDataAux);
         //Return
         if (!$this->formatFieldNameInUppercase) {
             $arrayData = \G::array_change_key_case2($arrayData, CASE_LOWER);
         }
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #13
0
 /**
  * Assign Permission to Role
  *
  * @param string $roleUid   Unique id of Role
  * @param array  $arrayData Data
  *
  * return array Return data of the Permission assigned to Role
  */
 public function create($roleUid, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         unset($arrayData["ROL_UID"]);
         //Verify data
         $role = new \ProcessMaker\BusinessModel\Role();
         $role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
         $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
         $process->throwExceptionIfNotExistsPermission($arrayData["PER_UID"], $this->arrayFieldNameForException["permissionUid"]);
         $this->throwExceptionIfItsAssignedPermissionToRole($roleUid, $arrayData["PER_UID"], $this->arrayFieldNameForException["permissionUid"]);
         if ($roleUid == "00000000000000000000000000000002") {
             throw new \Exception(\G::LoadTranslation("ID_ROLE_PERMISSION_ROLE_PERMISSIONS_CAN_NOT_BE_CHANGED", array("PROCESSMAKER_ADMIN")));
         }
         //Create
         $role = new \Roles();
         $arrayData = array_merge(array("ROL_UID" => $roleUid), $arrayData);
         $role->assignPermissionRole($arrayData);
         //Return
         if (!$this->formatFieldNameInUppercase) {
             $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         }
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #14
0
 /**
  * Assign User to Department
  *
  * @param string $departmentUid Unique id of Department
  * @param array  $arrayData     Data
  *
  * return array Return data of the User assigned to Department
  */
 public function assignUser($departmentUid, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         unset($arrayData["DEP_UID"]);
         //Set variables
         $arrayUserFieldDefinition = array("DEP_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "departmentUid"), "USR_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid"));
         $arrayUserFieldNameForException = array("departmentUid" => strtolower("DEP_UID"), "userUid" => strtolower("USR_UID"));
         //Verify data
         $departmentUid = \ProcessMaker\BusinessModel\Validator::depUid($departmentUid);
         $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayUserFieldDefinition, $arrayUserFieldNameForException, true);
         $process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $arrayUserFieldNameForException["userUid"]);
         //Assign User
         $department = new \Department();
         $department->load($departmentUid);
         $department->addUserToDepartment($departmentUid, $arrayData["USR_UID"], $department->getDepManager() == "" ? true : false, false);
         $department->updateDepartmentManager($departmentUid);
         //Return
         $arrayData = array_merge(array("DEP_UID" => $departmentUid), $arrayData);
         $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #15
0
 /**
  * Update Message-Type
  *
  * @param string $messageTypeUid Unique id of Message-Type
  * @param array  $arrayData      Data
  *
  * return array Return data of the Message-Type updated
  */
 public function update($messageTypeUid, $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         $arrayDataBackup = $arrayData;
         unset($arrayData["MSGT_UID"]);
         unset($arrayData["PRJ_UID"]);
         if (isset($arrayData["MSGT_VARIABLES"]) && is_array($arrayData["MSGT_VARIABLES"])) {
             foreach ($arrayData["MSGT_VARIABLES"] as $key => $value) {
                 $arrayData["MSGT_VARIABLES"][$key] = array_change_key_case($value, CASE_UPPER);
             }
         }
         //Set variables
         $arrayMessageTypeData = $this->getMessageType($messageTypeUid, true);
         //Verify data
         $this->throwExceptionIfNotExistsMessageType($messageTypeUid, $this->arrayFieldNameForException["messageTypeUid"]);
         $this->throwExceptionIfDataIsInvalid($messageTypeUid, $arrayMessageTypeData["PRJ_UID"], $arrayData);
         //Update
         $cnn = \Propel::getConnection("workflow");
         try {
             $messageType = \MessageTypePeer::retrieveByPK($messageTypeUid);
             $messageType->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             if ($messageType->validate()) {
                 $cnn->begin();
                 $result = $messageType->save();
                 $cnn->commit();
                 //----- *****
                 $variable = new \ProcessMaker\BusinessModel\MessageType\Variable();
                 $variable->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
                 $criteria = new \Criteria("workflow");
                 $criteria->add(\MessageTypeVariablePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
                 \MessageTypeVariablePeer::doDelete($criteria);
                 if (isset($arrayData["MSGT_VARIABLES"]) && count($arrayData["MSGT_VARIABLES"]) > 0) {
                     $variable = new \ProcessMaker\BusinessModel\MessageType\Variable();
                     $variable->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
                     foreach ($arrayData["MSGT_VARIABLES"] as $key => $value) {
                         $arrayVariable = $value;
                         $arrayResult = $variable->create($messageTypeUid, $arrayVariable);
                     }
                 }
                 //----- *****
                 //Return
                 $arrayData = $arrayDataBackup;
                 if (!$this->formatFieldNameInUppercase) {
                     $arrayData = array_change_key_case($arrayData, CASE_LOWER);
                 }
                 return $arrayData;
             } else {
                 $msg = "";
                 foreach ($messageType->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }