require_once 'pre.php'; require_once 'common/tracker/ArtifactType.class.php'; require_once 'common/tracker/Artifact.class.php'; require_once 'common/tracker/ArtifactFieldFactory.class.php'; $id = $request->get('id'); $artifact_id = $request->get('artifact_id'); // We have the artifact id, but not the tracker id $sql = "SELECT group_artifact_id, group_id FROM artifact INNER JOIN artifact_group_list USING (group_artifact_id) WHERE artifact_id= " . db_ei($artifact_id); $result = db_query($sql); if (db_numrows($result) > 0) { $row = db_fetch_array($result); $atid = $row['group_artifact_id']; $pm = ProjectManager::instance(); $group = $pm->getProject($row['group_id']); $at = new ArtifactType($group, $atid); if ($at->userCanView()) { $art_field_fact = new ArtifactFieldFactory($at); // Grrr! don't use global >_< $a = new Artifact($at, $artifact_id); if ($a->userCanView()) { $sql = "SELECT description,bin_data,filename,filesize,filetype FROM artifact_file WHERE id='" . db_ei($id) . "' AND artifact_id ='" . db_ei($artifact_id) . "'"; //echo $sql; $result = db_query($sql); if ($result && db_numrows($result) > 0) { if (db_result($result, 0, 'filesize') == 0) { exit_error($Language->getText('global', 'error'), $Language->getText('tracker_download', 'file_is_null')); } else { // Download the patch with the correct filetype require_once 'common/include/Codendi_HTTPPurifier.class.php'; $http = Codendi_HTTPPurifier::instance(); header('Content-Type: ' . $http->purify(db_result($result, 0, 'filetype')));
/** * Returns the ArtifactType named $tracker_name in the project of ID $gropup_id, or false if such a tracker does not exist or if the user can not view this tracker * * @param int $group_id th ID of the group * @param string $tracker_name the name of the tracker we are lokking for * @return the ArtifactType named $tracker_name in the project of ID $gropup_id, or false if such a tracker does not exist or if the user can not view this tracker */ function getArtifactTypeFromName($group_id, $tracker_name) { global $Language; $sql = "SELECT group_artifact_id \n FROM artifact_group_list \n WHERE group_id='" . db_ei($group_id) . "' AND \n item_name='" . db_es($tracker_name) . "' AND \n status!='D'"; $result = db_query($sql); $rows = db_numrows($result); if (!$result || $rows != 1) { $this->setError($Language->getText('tracker_common_type', 'none_found') . ' ' . db_error()); return false; } else { $pm = ProjectManager::instance(); while ($arr = db_fetch_array($result)) { $new_at = new ArtifactType($pm->getProject($group_id), $arr['group_artifact_id']); if ($new_at->userCanView()) { return $new_at; } else { $this->setError($Language->getText('tracker_common_type', 'no_view_permission') . ' ' . db_error()); return false; } } } }
/** * Create a tracker v5 from a tracker v3 * * @param PFUser $user the user who requested the creation * @param int $atid the id of the tracker v3 * @param Project $project the Id of the project to create the tracker * @param string $name the name of the tracker (label) * @param string $description the description of the tracker * @param string $itemname the short name of the tracker * * @throws Tracker_Exception_Migration_GetTv3Exception * * @return Tracker */ public function createFromTV3(PFUser $user, $atid, Project $project, $name, $description, $itemname) { require_once 'common/tracker/ArtifactType.class.php'; $tv3 = new ArtifactType($project, $atid); if ($tv3->isError()) { throw new Tracker_Exception_Migration_GetTv3Exception($tv3->getErrorMessage()); } // Check if this tracker is valid (not deleted) if (!$tv3->isValid()) { throw new Tracker_Exception_Migration_GetTv3Exception($GLOBALS['Language']->getText('tracker_add', 'invalid')); } //Check if the user can view the artifact if (!$tv3->userCanView($user->getId())) { throw new Tracker_Exception_Migration_GetTv3Exception($GLOBALS['Language']->getText('include_exit', 'no_perm')); } $tracker = null; if ($this->validMandatoryInfoOnCreate($name, $description, $itemname, $project->getId())) { $migration_v3 = new Tracker_Migration_V3($this); $tracker = $migration_v3->createTV5FromTV3($project, $name, $description, $itemname, $tv3); $this->postCreateActions($tracker); } return $tracker; }
/** * existArtifactSummary - check if the tracker $group_artifact_id already contains an artifact with the summary $summary * * @param string $sessionKey the session hash associated with the session opened by the person who calls the service * @param int $group_artifact_id the ID of the tracker we want to check * @param string $summary the summary we want to check * @return int the ID of the artifact containing the same summary in the tracker, or * -1 if the summary does not exist in this tracker. */ function existArtifactSummary($sessionKey, $group_artifact_id, $summary) { if (session_continue($sessionKey)) { $res = db_query("SELECT group_id FROM artifact_group_list WHERE group_artifact_id = " . db_ei($group_artifact_id)); if ($res && db_numrows($res) > 0) { $group_id = db_result($res, 0, 'group_id'); } else { return new SoapFault(get_artifact_type_fault, 'Tracker not found.', 'existArtifactSummary'); } try { $pm = ProjectManager::instance(); $grp = $pm->getGroupByIdForSoap($group_id, 'existArtifactSummary'); } catch (SoapFault $e) { return $e; } $at = new ArtifactType($grp, $group_artifact_id); if ($at->userCanView()) { $res = db_query('SELECT artifact_id FROM artifact WHERE group_artifact_id = ' . db_ei($group_artifact_id) . ' AND summary="' . db_es(htmlspecialchars($summary)) . '"'); if ($res && db_numrows($res) > 0) { return db_result($res, 0, 0); } else { return -1; } } else { return new SoapFault(get_artifact_type_fault, 'Permission denied.', 'existArtifactSummary'); } } else { return new SoapFault(invalid_session_fault, 'Invalid Session', 'existArtifactSummary'); } }