function sendTo($from, $activity_id, $split = false) { //1: if we are in a join check //if this instance is also in //other activity if so do //nothing $type = $this->mDb->getOne("select `act_type` from `" . GALAXIA_TABLE_PREFIX . "activities` where `activity_id`=?", array((int) $activity_id)); // Verify the existance of a transition if (!$this->mDb->getOne("select count(*) from `" . GALAXIA_TABLE_PREFIX . "transitions` where `act_from_id`=? and `act_to_id`=?", array($from, (int) $activity_id))) { trigger_error(tra('Fatal error: trying to send an instance to an activity but no transition found'), E_USER_WARNING); } //try to determine the group or * //Use the next_group_id if ($this->next_group_id) { $putgroup = $this->next_group_id; } else { $candidates = array(); $query = "select `role_id` from `" . GALAXIA_TABLE_PREFIX . "activity_roles` where `activity_id`=?"; $result = $this->mDb->query($query, array((int) $activity_id)); while ($res = $result->fetchRow()) { $role_id = $res['role_id']; $query2 = "select ugm.`user_id` from `" . GALAXIA_TABLE_PREFIX . "group_roles` ggr\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_groups_map` ugm ON ugm.`group_id`=ggr.`group_id`\n\t\t\t\twhere `role_id`=?"; $result2 = $this->mDb->query($query2, array((int) $role_id)); while ($res2 = $result2->fetchRow()) { $candidates[] = $res2['user_id']; } } if (count($candidates) == 1) { $putgroup = $candidates[0]; } else { $putgroup = NULL; } } //update the instance_activities table //if not splitting delete first //please update started,status,user if (!$split) { // $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `instance_id`=? and `activity_id`=?"; // $this->mDb->query($query,array((int)$this->instance_id,$from)); } $now = date("U"); $iid = $this->instance_id; $query = "delete from `" . GALAXIA_TABLE_PREFIX . "instance_activities` where `instance_id`=? and `activity_id`=?"; $this->mDb->query($query, array((int) $iid, (int) $activity_id)); $query = "insert into `" . GALAXIA_TABLE_PREFIX . "instance_activities`(`instance_id`,`activity_id`,`user_id`,`status`,`started`,`ended`) values(?,?,?,?,?,?)"; $this->mDb->query($query, array((int) $iid, (int) $activity_id, $putgroup, 'running', (int) $now, 0)); //we are now in a new activity $this->activities = array(); $query = "select * from `" . GALAXIA_TABLE_PREFIX . "instance_activities` where `instance_id`=?"; $result = $this->mDb->query($query, array((int) $iid)); while ($res = $result->fetchRow()) { $this->activities[] = $res; } if ($type == 'join') { if (count($this->activities) > 1) { // This instance will have to wait! return; } } //if the activity is not interactive then //execute the code for the activity and //complete the activity $is_interactive = $this->mDb->getOne("select `is_interactive` from `" . GALAXIA_TABLE_PREFIX . "activities` where `activity_id`=?", array((int) $activity_id)); if ($is_interactive == 'n') { // Now execute the code for the activity (function defined in lib/Galaxia/config.php) galaxia_execute_activity($activity_id, $iid, 1); // Reload in case the activity did some change $this->getInstance($this->instance_id); $this->complete($activity_id); } }
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); } }