function new_process_version($p_id, $minor = true) { $oldpid = $p_id; $proc_info = $this->get_process($p_id); $name = $proc_info['procname']; if (!$proc_info) { return false; } // Now update the version $version = $this->_new_version($proc_info['version'], $minor); while ($this->mDb->getOne("select count(*) from `" . GALAXIA_TABLE_PREFIX . "processes` where `procname`='{$name}' and `version`='{$version}'")) { $version = $this->_new_version($version, $minor); } // Make new versions unactive $proc_info['version'] = $version; $proc_info['is_active'] = 'n'; // create a new process, but don't create start/end activities $pid = $this->replace_process(0, $proc_info, false); // And here copy all the activities & so $am = new ActivityManager(); $query = "select * from `" . GALAXIA_TABLE_PREFIX . "activities` where `p_id`={$oldpid}"; $result = $this->mDb->query($query); $newaid = array(); while ($res = $result->fetchRow()) { $oldaid = $res['activity_id']; $newaid[$oldaid] = $am->replace_activity($pid, 0, $res); } // create transitions $query = "select * from `" . GALAXIA_TABLE_PREFIX . "transitions` where `p_id`={$oldpid}"; $result = $this->mDb->query($query); while ($res = $result->fetchRow()) { if (empty($newaid[$res['act_from_id']]) || empty($newaid[$res['act_to_id']])) { continue; } $am->add_transition($pid, $newaid[$res['act_from_id']], $newaid[$res['act_to_id']]); } // create roles $rm = new RoleManager(); $query = "select * from `" . GALAXIA_TABLE_PREFIX . "roles` where `p_id`={$oldpid}"; $result = $this->mDb->query($query); $newrid = array(); while ($res = $result->fetchRow()) { if (!$rm->role_name_exists($pid, $res['name'])) { $rid = $rm->replace_role($pid, 0, $res); } else { $rid = $rm->get_role_id($pid, $res['name']); } $newrid[$res['role_id']] = $rid; } // map users to roles if (count($newrid) > 0) { $query = "select * from `" . GALAXIA_TABLE_PREFIX . "group_roles` where `p_id`={$oldpid}"; $result = $this->mDb->query($query); while ($res = $result->fetchRow()) { if (empty($newrid[$res['role_id']])) { continue; } $rm->map_group_to_role($pid, $res['group_id'], $newrid[$res['role_id']]); } } // add roles to activities if (count($newaid) > 0 && count($newrid) > 0) { $query = "select * from " . GALAXIA_TABLE_PREFIX . "activity_roles where activity_id in (" . join(', ', array_keys($newaid)) . ")"; $result = $this->mDb->query($query); while ($res = $result->fetchRow()) { if (empty($newaid[$res['activity_id']]) || empty($newrid[$res['role_id']])) { continue; } $am->add_activity_role($newaid[$res['activity_id']], $newrid[$res['role_id']]); } } //Now since we are copying a process we should copy //the old directory structure to the new directory $oldname = $proc_info['normalized_name']; $newname = $this->_get_normalized_name($pid); $this->_rec_copy(GALAXIA_PROCESSES . "/{$oldname}", GALAXIA_PROCESSES . "/{$newname}"); // create a graph for the new process $am->build_process_graph($pid); return $pid; }