Beispiel #1
0
 function new_process_version($pId, $minor = true)
 {
     $oldpid = $pId;
     $proc_info = $this->get_process($pId);
     $name = $proc_info['name'];
     if (!$proc_info) {
         return false;
     }
     // Now update the version
     $version = $this->_new_version($proc_info['version'], $minor);
     while ($this->getOne("select count(*) from `" . GALAXIA_TABLE_PREFIX . "processes` where `name`=? and `version`=?", array($name, $version))) {
         $version = $this->_new_version($version, $minor);
     }
     // Make new versions unactive
     $proc_info['version'] = $version;
     $proc_info['isActive'] = '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($this->db);
     $query = "select * from `" . GALAXIA_TABLE_PREFIX . "activities` where `pId`=?";
     $result = $this->query($query, array($oldpid));
     $newaid = array();
     while ($res = $result->fetchRow()) {
         $oldaid = $res['activityId'];
         $newaid[$oldaid] = $am->replace_activity($pid, 0, $res);
     }
     // create transitions
     $query = "select * from `" . GALAXIA_TABLE_PREFIX . "transitions` where `pId`=?";
     $result = $this->query($query, array($oldpid));
     while ($res = $result->fetchRow()) {
         if (empty($newaid[$res['actFromId']]) || empty($newaid[$res['actToId']])) {
             continue;
         }
         $am->add_transition($pid, $newaid[$res['actFromId']], $newaid[$res['actToId']]);
     }
     // create roles
     $rm = new RoleManager($this->db);
     $query = "select * from `" . GALAXIA_TABLE_PREFIX . "roles` where `pId`=?";
     $result = $this->query($query, array($oldpid));
     $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['roleId']] = $rid;
     }
     // map users to roles
     if (count($newrid) > 0) {
         $query = "select * from `" . GALAXIA_TABLE_PREFIX . "user_roles` where `pId`=?";
         $result = $this->query($query, array($oldpid));
         while ($res = $result->fetchRow()) {
             if (empty($newrid[$res['roleId']])) {
                 continue;
             }
             $rm->map_user_to_role($pid, $res['user'], $newrid[$res['roleId']]);
         }
     }
     // add roles to activities
     if (count($newaid) > 0 && count($newrid) > 0) {
         foreach ($newaid as $ne) {
             $q[] = '?';
         }
         $query = "select * from `" . GALAXIA_TABLE_PREFIX . "activity_roles` where `activityId` in (" . join(',', $q) . ")";
         $result = $this->query($query, array_keys($newaid));
         while ($res = $result->fetchRow()) {
             if (empty($newaid[$res['activityId']]) || empty($newrid[$res['roleId']])) {
                 continue;
             }
             $am->add_activity_role($newaid[$res['activityId']], $newrid[$res['roleId']]);
         }
     }
     //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;
 }