Exemplo n.º 1
0
 function sendTo($from, $activityId, $split = false)
 {
     //1: if we are in a join check if this instance is also in other activity
     //if so do nothing
     $type = $this->getOne("SELECT `type` FROM `" . GALAXIA_TABLE_PREFIX . "activities` WHERE `activityId`=?", array((int) $activityId));
     // Verify the existance of a transition
     if (!$this->getOne("SELECT count(*) FROM `" . GALAXIA_TABLE_PREFIX . "transitions` WHERE `actFromId`=? AND `actToId`=?", array($from, (int) $activityId))) {
         trigger_error(tra('Fatal error: trying to send an instance to an activity but no transition found'), E_USER_WARNING);
     }
     //Use the nextUser
     if ($this->nextUser) {
         $putuser = $this->nextUser;
     } else {
         //Try to determine the user or *
         $candidates = array();
         $query = "SELECT `roleId` FROM `" . GALAXIA_TABLE_PREFIX . "activity_roles` WHERE `activityId`=?";
         $result = $this->query($query, array((int) $activityId));
         while ($res = $result->fetchRow()) {
             $roleId = $res['roleId'];
             $query2 = "SELECT `user` FROM `" . GALAXIA_TABLE_PREFIX . "user_roles` WHERE `roleId`=?";
             $result2 = $this->query($query2, array((int) $roleId));
             while ($res2 = $result2->fetchRow()) {
                 $candidates[] = $res2['user'];
             }
         }
         $putuser = count($candidates) == 1 ? $candidates[0] : '*';
     }
     $now = date("U");
     $iid = $this->instanceId;
     // Test if the join activity has preceding activities that are not completed yet
     if ($type == 'join') {
         // Calculate 1)how many incoming transitions the activity has, and 2)how many of those are completed
         $querycant = "SELECT COUNT(*) FROM `" . GALAXIA_TABLE_PREFIX . "transitions` WHERE actToId = ?";
         $querycomp = "SELECT COUNT(*) FROM `" . GALAXIA_TABLE_PREFIX . "transitions` tr " . "INNER JOIN " . GALAXIA_TABLE_PREFIX . "instance_activities gia ON tr.actFromId=gia.activityId\r\n                     WHERE tr.pid=? AND tr.actToId=? AND gia.instanceId=? AND gia.status = ?";
         $transcant = $this->getone($querycant, array($activityId));
         $transcomp = $this->getone($querycomp, array($this->pId, $activityId, $iid, 'completed'));
         // if there are still preceding activities not completed, STOP
         if ($nb = $transcant - $transcomp) {
             //echo 'Pending preceding activities = ' . $nb;
             return;
         }
     }
     $query = "DELETE FROM `" . GALAXIA_TABLE_PREFIX . "instance_activities` WHERE `instanceId`=? AND `activityId`=?";
     $this->query($query, array((int) $iid, (int) $activityId));
     $query = "INSERT INTO `" . GALAXIA_TABLE_PREFIX . "instance_activities` (`instanceId`, `activityId`, `user`, `status`, `started`) VALUES (?,?,?,?,?)";
     $this->query($query, array((int) $iid, (int) $activityId, $putuser, 'running', (int) $now));
     // Check whether the activity we're sending the instance to is interactive
     $isInteractive = $this->getOne("SELECT `isInteractive` FROM `" . GALAXIA_TABLE_PREFIX . "activities` WHERE `activityId`=?", array((int) $activityId));
     //if the activity is not interactive then execute its code and complete it
     if ($isInteractive == 'n') {
         // These are necessary to determine if the activity needs to be recompiled
         $proc = new Process($this->db);
         $proc->getProcess($this->pId);
         $baseact = new BaseActivity($this->db);
         $act = $baseact->getActivity($activityId);
         // Get paths for original and compiled activity code
         $origcode = 'lib/Galaxia/processes/' . $proc->getNormalizedName() . '/code/activities/' . $act->getNormalizedName() . '.php';
         $compcode = 'lib/Galaxia/processes/' . $proc->getNormalizedName() . '/compiled/' . $act->getNormalizedName() . '.php';
         // Check whether the activity code is newer than its compiled counterpart,
         // i.e. check if the source code was changed; if so, we need to recompile
         if (filemtime($origcode) > filemtime($compcode)) {
             // Recompile
             include_once 'lib/Galaxia/src/ProcessManager/ActivityManager.php';
             include_once 'lib/Galaxia/src/ProcessManager/ProcessManager.php';
             $am = new ActivityManager($this->db);
             $am->compile_activity($this->pId, $activityId);
         }
         // Now execute the code for the activity (function galaxia_execute_activity
         // is defined in lib/Galaxia/config.php)
         galaxia_execute_activity($activityId, $iid, 1);
         // Reload in case the activity did some change
         $this->getInstance($this->instanceId);
         $this->complete($activityId);
     }
 }
Exemplo n.º 2
0
 function import_process($data)
 {
     //Now the show begins
     $am = new ActivityManager($this->db);
     $rm = new RoleManager($this->db);
     // First create the process
     $vars = array('name' => $data['name'], 'version' => $data['version'], 'description' => $data['description'], 'lastModif' => $data['lastModif'], 'isActive' => $data['isActive'], 'isValid' => $data['isValid']);
     $pid = $this->replace_process(0, $vars, false);
     //Put the shared code
     $proc_info = $this->get_process($pid);
     $procname = $proc_info['normalized_name'];
     $fp = fopen(GALAXIA_PROCESSES . "/{$procname}/code/shared.php", "w");
     fwrite($fp, $data['sharedCode']);
     fclose($fp);
     $actids = array();
     // Foreach activity create activities
     foreach ($data['activities'] as $activity) {
         $vars = array('name' => $activity['name'], 'description' => $activity['description'], 'type' => $activity['type'], 'lastModif' => $activity['lastModif'], 'isInteractive' => $activity['isInteractive'], 'isAutoRouted' => $activity['isAutoRouted'], 'expirationTime' => $activity['expirationTime']);
         $actname = $am->_normalize_name($activity['name']);
         $actid = $am->replace_activity($pid, 0, $vars);
         $fp = fopen(GALAXIA_PROCESSES . "/{$procname}/code/activities/{$actname}" . '.php', "w");
         fwrite($fp, $activity['code']);
         fclose($fp);
         if ($activity['isInteractive'] == 'y') {
             $fp = fopen(GALAXIA_PROCESSES . "/{$procname}/code/templates/{$actname}" . '.tpl', "w");
             fwrite($fp, $activity['template']);
             fclose($fp);
         }
         $actids[$activity['name']] = $am->_get_activity_id_by_name($pid, $activity['name']);
         $actname = $am->_normalize_name($activity['name']);
         $now = date("U");
         foreach ($activity['roles'] as $role) {
             $vars = array('name' => $role, 'description' => $role, 'lastModif' => $now);
             if (!$rm->role_name_exists($pid, $role)) {
                 $rid = $rm->replace_role($pid, 0, $vars);
             } else {
                 $rid = $rm->get_role_id($pid, $role);
             }
             if ($actid && $rid) {
                 $am->add_activity_role($actid, $rid);
             }
         }
     }
     foreach ($data['transitions'] as $tran) {
         $am->add_transition($pid, $actids[$tran['from']], $actids[$tran['to']]);
     }
     // FIXME: recompile activities seems to be needed here
     foreach ($actids as $name => $actid) {
         $am->compile_activity($pid, $actid);
     }
     // Check whether the uploaded process is valid.
     $valid = $am->validate_process_activities($pid);
     //As roles have yet to be mapped, it isn't. So let's deactivate the uploaded process.
     if (!$valid) {
         $this->deactivate_process($pid);
     }
     // create a graph for the new process
     $am->build_process_graph($pid);
     unset($am);
     unset($rm);
     $msg = sprintf(tra('Process %s %s imported'), $proc_info['name'], $proc_info['version']);
     $this->notify_all(2, $msg);
 }