Ejemplo n.º 1
0
 /**
  * Create Script-Task for a Project
  *
  * @param string $projectUid Unique id of Project
  * @param array  $arrayData  Data
  *
  * return array Return data of the new Script-Task 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["SCRTAS_UID"]);
         unset($arrayData["PRJ_UID"]);
         //Verify data
         $process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
         $this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
         //Create
         $cnn = \Propel::getConnection("workflow");
         try {
             $scriptTask = new \ScriptTask();
             $scriptTask->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             $scriptTaskUid = \ProcessMaker\Util\Common::generateUID();
             $scriptTask->setScrtasUid($scriptTaskUid);
             $scriptTask->setPrjUid($projectUid);
             if ($scriptTask->validate()) {
                 $cnn->begin();
                 $result = $scriptTask->save();
                 $cnn->commit();
                 //Return
                 return $this->getScriptTask($scriptTaskUid);
             } else {
                 $msg = "";
                 foreach ($scriptTask->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;
     }
 }