[evolvis-commits] r17217: merge bm:taramir51/patches/use-same-sequence-for-pm-and-tracker

mirabilos at evolvis.org mirabilos at evolvis.org
Thu May 12 18:18:04 CEST 2011


Author: mirabilos
Date: 2011-05-12 18:18:04 +0200 (Thu, 12 May 2011)
New Revision: 17217

Modified:
   trunk/gforge_base/evolvisforge-5.1/src/common/pm/ProjectTaskSqlQueries.php
   trunk/gforge_base/evolvisforge-5.1/src/www/include/features_boxes.php
Log:
merge bm:taramir51/patches/use-same-sequence-for-pm-and-tracker

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/pm/ProjectTaskSqlQueries.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/pm/ProjectTaskSqlQueries.php	2011-05-12 16:17:58 UTC (rev 17216)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/pm/ProjectTaskSqlQueries.php	2011-05-12 16:18:04 UTC (rev 17217)
@@ -1,9 +1,103 @@
 <?php
-/**
- * @author: Patrick Apel, tarent GmbH
+/*-
+ * FusionForge function bundle for PM and Artefact related queries
+ *
+ * Copyright © 2010, 2011
+ *	Thorsten “mirabilos” Glaser <t.glaser at tarent.de>
+ *	Patrick Apel <p.apel at tarent.de>
+ * All rights reserved.
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *-
+ * Retrieve extra information about task items.
  */
 
 
+/* -+- generic functions -+- */
+
+
+/* get minimum safe task/tracker ID for which to assume uniqueness */
+function tasktracker_getminid() {
+	global $tasktracker_minid;
+
+	if (isset($tasktracker_minid))
+		return $tasktracker_minid;
+
+	$res = db_query('SELECT min_value FROM tasktracker_seq');
+	if (!$res || db_numrows($res) != 1 || !($arr = db_fetch_array($res)))
+		exit_error(_('Internal Error'),
+		    _('Cannot read out tasktracker_seq SEQUENCE'));
+
+	$tasktracker_minid = $arr[0];
+	return $tasktracker_minid;
+}
+
+
+/* find out if id is an aid or a tid (quick, one SELECT) */
+function tasktracker_gettype($id) {
+	if ($id < tasktracker_getminid())
+		/* neither */
+		return false;
+
+	$res = db_query_params('SELECT summary, is_a, subproject_is_public, group_is_public
+	    FROM tasktracker_ids
+	    WHERE id=$1', array($id));
+
+	if (!$res || db_numrows($res) != 1 || !($arr = db_fetch_array($res)))
+		return false;
+
+	$arrResult = array(
+	    'id' => (int)$id,
+	    'is_a' => $arr[1]
+	);
+	$arrResult['summary'] = ($arr[2] == 1 && $arr[3] == 1) ?
+	    $arr[0] : _('<Information not public>');
+
+	return $arrResult;
+}
+
+
+/* find out if id is an aid or a tid (verbose, two SELECTs) */
+/* set defaultto to 1 (tracker) or 2 (task) if you KNOW it… */
+function tasktracker_getinfo($id,$getsummary=false,$defaultto=0) {
+	if ($id < tasktracker_getminid()) {
+		/* neither */
+		if ($defaultto == 1)
+			return (getArtefactTrackerIdGroupId($id, $getsummary));
+		else if ($defaultto == 2)
+			return (getGroupProjectIdGroupId($id, $getsummary));
+		return false;
+	}
+
+	if (($res = getGroupProjectIdGroupId($id,$getsummary)) !== false)
+		/* tid */
+		return $res;
+
+	if (($res = getArtefactTrackerIdGroupId($id,$getsummary)) !== false)
+		/* aid */
+		return $res;
+
+	/* unknown */
+	return false;
+}
+
+
+/* -+- Tasks -+- PM -+- */
+
+
 /**
  * Retrieve group_project_id and group_id for a specific project_task_id,
  * for URI construction and similar things.
@@ -14,23 +108,27 @@
  *	- int group_project_id
  *	- int group_id
  */
-function getGroupProjectIdGroupId($project_task_id) {
-	$res = db_query_params('SELECT project_task.group_project_id, project_group_list.group_id FROM project_task ' .
+function getGroupProjectIdGroupId($project_task_id,$getsummary=false) {
+	$res = db_query_params('SELECT project_task.group_project_id, project_group_list.group_id, project_task.summary FROM project_task ' .
 	    'INNER JOIN project_group_list ON project_task.group_project_id = project_group_list.group_project_id ' .
 	    'WHERE project_task.project_task_id = $1',
 	    array($project_task_id));
 
-	if (!$res || db_numrows($res) != 1) {
+	if (!$res || db_numrows($res) != 1 || !($arr = db_fetch_array($res))) {
 		return false;
 	}
 
-	while ($arr = db_fetch_array($res)) {
-		$arrResult = array(
-		    'project_task_id' => (int)$project_task_id,
-		    'group_project_id' => (int)$arr[0],
-		    'group_id' => (int)$arr[1]
-		);
-	}
+	$arrResult = array(
+	    'project_task_id' => (int)$project_task_id,
+	    'group_project_id' => (int)$arr[0],
+	    'group_id' => (int)$arr[1],
+	    'is_a' => 'tid'
+	);
+	if ($getsummary)
+		$arrResult['summary'] =
+		    (isProjectTaskInfoPublic($project_task_id) ||
+		    session_checkperm(array('group'=>'1','admin_flags'=>'A'))) ?
+		    $arr[2] : _('<Information not public>');
 
 	return $arrResult;
 }
@@ -45,11 +143,11 @@
 function isProjectTaskInfoPublic($project_task_id) {
 	$res = db_query_params('SELECT group_project_id FROM project_task WHERE project_task_id=$1',
 			       array ($project_task_id)) ;
-	
+
 	if (!$res || db_numrows($res) < 1) {
 		return false;
 	}
-	
+
 	return RoleAnonymous::getInstance()->hasPermission('pm', 
 							   db_result ($res, 0, 'group_project_id'),
 							   'read') ;
@@ -67,15 +165,15 @@
 function isUserAndTaskinSameGroup($project_task_id, $user_name) {
 	$res = db_query_params('SELECT group_project_id FROM project_task WHERE project_task_id=$1',
 			       array ($project_task_id)) ;
-	
-	if (!$res || db_numrows($res) < 1) {
+
+	if (!$res || db_numrows($res) < 1 || !($arr = db_fetch_array($res))) {
 		return false;
 	}
-	$arr = db_fetch_array($res) ;
-	
+
 	return forge_check_perm_for_user(user_get_object_by_name ($user_name), 'pm', $arr['group_project_id'], 'read') ;
 }
 
+
 /*-
  * Query for controlling the result. It gives back all user_names and
  * project_task_ids that matches the groups above:
@@ -95,7 +193,6 @@
  * WHERE project_task_id isNull;
  */
 
-
 /**
  * Retrieve extended information about a project task.
  *
@@ -114,6 +211,7 @@
  *	- int category_id
  *	- str category_name (of the per-group category the task is in)
  *	- str project_name (of the per-group subproject the task is in)
+ *	- str is_a := 'tid' (task id, as opposed to 'aid', artefact id)
  */
 function getAllFromProjectTask($project_task_id) {
 	$res = db_query_params('SELECT ' .
@@ -139,28 +237,89 @@
 	    'WHERE project_task.project_task_id = $1',
 	    array($project_task_id));
 
-	if (!$res || db_numrows($res) != 1) {
+	if (!$res || db_numrows($res) != 1 || !($arr = db_fetch_array($res)))
 		return false;
-	}
 
-	while ($arr = db_fetch_array($res)) {
-		$arrResult = array(
-		    'project_task_id' => (int)$arr[0],
-		    'group_project_id' => (int)$arr[1],
-		    'group_id' => (int)$arr[11],
-		    'summary' => $arr[2],
-		    'priority' => (int)$arr[3],
-		    'created_by' => (int)$arr[4],
-		    'status_id' => (int)$arr[5],
-		    'category_id' => (int)$arr[6],
-		    'created_by_name' => $arr[7],
-		    'category_name' => $arr[8],
-		    'project_name' => $arr[9],
-		    'group_name' => $arr[10],
-		    'status_name' => $arr[12]
-		);
+	$arrResult = array(
+	    'project_task_id' => (int)$arr[0],
+	    'group_project_id' => (int)$arr[1],
+	    'group_id' => (int)$arr[11],
+	    'summary' => $arr[2],
+	    'priority' => (int)$arr[3],
+	    'created_by' => (int)$arr[4],
+	    'status_id' => (int)$arr[5],
+	    'category_id' => (int)$arr[6],
+	    'created_by_name' => $arr[7],
+	    'category_name' => $arr[8],
+	    'project_name' => $arr[9],
+	    'group_name' => $arr[10],
+	    'status_name' => $arr[12],
+	    'is_a' => 'tid'
+	);
+
+	return $arrResult;
+}
+
+
+/* -+- Tracker -+- Artefact -+- */
+
+
+/**
+ * Check if the bug behind aid is considered public.
+ *
+ * in:	int aid
+ * out:	true, if it is; false otherwise
+ */
+function isArtefactInfoPublic($aid) {
+	$res = db_query_params('SELECT * FROM artifact ' .
+	    'INNER JOIN artifact_group_list ON ' .
+	    'artifact.group_artifact_id = artifact_group_list.group_artifact_id ' .
+	    'INNER JOIN groups ON ' .
+	    'artifact_group_list.group_id = groups.group_id ' .
+	    'WHERE artifact.artifact_id = $1 ' .
+	    'AND artifact_group_list.is_public = $2 AND groups.is_public = $3',
+	    array($aid, 1, 1));
+
+	if (!$res || db_numrows($res) < 1) {
+		return false;
 	}
 
+	return true;
+}
+
+
+/**
+ * Retrieve atid and group_id for a specific aid (Artefact ID),
+ * for URI construction and similar things.
+ *
+ * in:	int aid
+ * out:	false, or an associative array with
+ *	- int aid (copy)
+ *	- int atid
+ *	- int group_id
+ */
+function getArtefactTrackerIdGroupId($aid,$getsummary=false) {
+	$res = db_query_params('
+		SELECT artifact_group_list.group_artifact_id, artifact_group_list.group_id, artifact.summary
+		FROM artifact_group_list, artifact
+		WHERE artifact_group_list.group_artifact_id=artifact.group_artifact_id
+		    AND artifact.artifact_id=$1',
+	    array($aid));
+
+	if (!$res || db_numrows($res) != 1 || !($arr = db_fetch_array($res)))
+		return false;
+
+	$arrResult = array(
+	    'aid' => (int)$aid,
+	    'atid' => (int)$arr[0],
+	    'group_id' => (int)$arr[1],
+	    'is_a' => 'aid'
+	);
+	if ($getsummary)
+		$arrResult['summary'] = (isArtefactInfoPublic($aid) ||
+		    session_checkperm(array('group'=>'1','admin_flags'=>'A'))) ?
+		    $arr[2] : _('<Information not public>');
+
 	return $arrResult;
 }
 

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/include/features_boxes.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/include/features_boxes.php	2011-05-12 16:17:58 UTC (rev 17216)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/include/features_boxes.php	2011-05-12 16:18:04 UTC (rev 17217)
@@ -27,7 +27,7 @@
 require_once $gfcommon.'include/FusionForge.class.php';
 require_once $gfcommon.'include/tag_cloud.php';
 require_once $gfcommon.'include/Stats.class.php';
-require_once $gfcommon.'/pm/ProjectTaskSqlQueries.php';
+require_once $gfcommon.'pm/ProjectTaskSqlQueries.php';
 
 function show_features_boxes() {
 	GLOBAL $HTML;
@@ -61,8 +61,9 @@
 			   forge_get_config ('forge_name'),
 			   $ff->software_name,
 			   $ff->software_version);
-	$return .= sprintf(_('Minimum Unique Task/Tracker Item ID: %d') . "\n",
-	    tasktracker_getminid());
+	$return .= "\n<br />\n" .
+	    sprintf(_('Minimum Unique Task/Tracker Item ID: <b>%d</b>'),
+	    tasktracker_getminid()) . "\n";
 	$return .= $HTML->boxBottom();
 	plugin_hook ("features_boxes_bottom", array());
 	return $return;



More information about the evolvis-commits mailing list