[Fusionforge-commits] FusionForge branch master updated. 9c054754a6e6c3fc523ed27cae7c06958863004d

Thorsten Glaser mirabilos at fusionforge.org
Wed Nov 21 15:43:29 CET 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  9c054754a6e6c3fc523ed27cae7c06958863004d (commit)
      from  69c701c2afc1ae16b05156a008ac87ac2d016017 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9c054754a6e6c3fc523ed27cae7c06958863004d
Author: Thorsten Glaser <tg at mirbsd.org>
Date:   Wed Nov 21 15:43:02 2012 +0100

    export all tracker items and a *lot* more data
    
    (still more to follow)

diff --git a/src/utils/one-off-scripts/tracker-export.php b/src/utils/one-off-scripts/tracker-export.php
index b88a4ae..796b662 100644
--- a/src/utils/one-off-scripts/tracker-export.php
+++ b/src/utils/one-off-scripts/tracker-export.php
@@ -21,8 +21,7 @@
  * with FusionForge; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *-
- * Edit below; comments inline.  Exports all open items in a tracker,
- * although only part of the data, as JSON.
+ * Edit below; comments inline.  Exports all items in a tracker as JSON.
  */
 
 require '/usr/share/gforge/common/include/env.inc.php';
@@ -37,6 +36,28 @@ require_once $gfwww.'tracker/include/ArtifactHtml.class.php';
 require_once $gfcommon.'tracker/ArtifactCanned.class.php';
 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
 
+function dbe2jsn($v) {
+	/* fix mistake of how stuff is stored in the DB */
+	$v = util_unconvert_htmlspecialchars($v);
+	/* fix issue with how stuff may be stored in the DB */
+	$v = util_sanitise_multiline_submission($v);
+	/* but export using logical newlines */
+	$v = str_replace("\r\n", "\n", $v);
+	/* now we’ve got something we can use */
+	return $v;
+}
+
+function u2jsn($id) {
+	if ($id == 100) {
+		return 'nobody';
+	}
+	if (($u = user_get_object($id)) && is_object($u) &&
+	    !$u->isError()) {
+		return $u->getUnixName();
+	}
+	return sprintf('u%u', $id);
+}
+
 function usage($rc=1) {
 	echo "Usage: .../tracker-export.php 123\n" .
 	    "\twhere 123 is the group_artifact_id of the tracker to export\n";
@@ -58,9 +79,9 @@ if (!($trk = util_nat0($argv1))) {
 
 session_set_admin();
 
-/* pull a list of all open tracker items */
+/* pull a list of all tracker items */
 $res = db_query_params('SELECT artifact_id FROM artifact
-	WHERE status_id=1 AND group_artifact_id=$1',
+	WHERE group_artifact_id=$1',
     array($trk));
 if (!$res || db_numrows($res) < 1 ||
     !($srclist = util_result_column_to_array($res))) {
@@ -68,6 +89,39 @@ if (!$res || db_numrows($res) < 1 ||
 	die;
 }
 
+$at = false;
+function initialise_at($atx) {
+	global $at, $efarr, $efmap, $efval, $usespm, $out;
+
+	if (!($at = $atx) || !is_object($at) || $at->isError()) {
+		echo "error no AT\n";
+		db_rollback();
+		die;
+	}
+	$efarr = $at->getExtraFields();
+	$efval = array();
+	$usespm = $at->getGroup()->usesPM();
+
+	$efmap = array();
+	foreach ($efarr as $f) {
+		$efmap[($efid = (int)$f['extra_field_id'])] = array(
+			'name' => util_unconvert_htmlspecialchars($f['field_name']),
+			'alias' => preg_replace('/^@/', '',
+			    preg_replace('/[0-9.]+$/', '', $f['alias'])),
+			'type' => (int)$f['field_type'],
+		    );
+		if (!strcasecmp($efmap[$efid]['name'], $efmap[$efid]['alias'])) {
+			/* skip when alias is the same as name */
+			$efmap[$efid]['alias'] = "";
+		}
+		$efval[$efid] = array();
+		foreach (ArtifactExtraField_getAvailableValues($efid) as $k => $v) {
+			$efval[$efid][(int)$v['element_id']] =
+			    util_unconvert_htmlspecialchars($v['element_name']);
+		}
+	}
+}
+
 $out = array();
 foreach ($srclist as $aidx) {
 	/* retrieve the current item */
@@ -79,6 +133,10 @@ foreach ($srclist as $aidx) {
 		die;
 	}
 
+	if ($at === false) {
+		initialise_at($ah->getArtifactType());
+	}
+
 	/* prepare an export record */
 	$rec = array();
 	foreach ($ah->data_array as $k => $v) {
@@ -91,19 +149,24 @@ foreach ($srclist as $aidx) {
 		switch ($k) {
 		case 'summary':
 		case 'details':
-			/* fix mistake of how stuff is stored in the DB */
-			$v = util_unconvert_htmlspecialchars($v);
-			/* fix issue with how stuff may be stored in the DB */
-			$v = util_sanitise_multiline_submission($v);
-			/* but export using logical newlines */
-			$v = str_replace("\r\n", "\n", $v);
-			/* now we’ve got something we can use */
-			$rec[$k] = $v;
+			$rec[$k] = dbe2jsn($v);
+			break;
+
+		case 'group_id':
+		case 'group_artifact_id':
+		case 'artifact_id':
+			/* skip */
 			break;
 
-		/* uncomment this to not emit the tracker id */
-		//case 'group_artifact_id':
-		//	break;
+		case 'assigned_to':
+		case 'close_date':
+		case 'last_modified_date':
+		case 'open_date':
+		case 'priority':
+		case 'status_id':
+		case 'submitted_by':
+			$rec[$k] = (int)$v;
+			break;
 
 		default:
 			$rec[$k] = $v;
@@ -114,9 +177,112 @@ foreach ($srclist as $aidx) {
 	/* add a _permalink pseudo-field */
 	$rec['_permalink'] = util_make_url('/tracker/t_follow.php/' . $aid);
 
+	/* copy votes */
+	$rec['_votes'] = array_combine(array(
+		'votes',
+		'voters',
+		'votage_percent',
+	    ), $ah->getVotes());
+
+	/* copy related tasks and add task permalink format pseudo-field */
+	if ($usespm) {
+		$rec['~related_tasks'] = array();
+		$taskcount = db_numrows($ah->getRelatedTasks());
+		if ($taskcount >= 1) for ($i = 0; $i < $taskcount; ++$i) {
+			$taskinfo = db_fetch_array($ah->relatedtasks, $i);
+			$rec['~related_tasks'][] =
+			    (int)$taskinfo['project_task_id'];
+		}
+		sort($rec['~related_tasks'], SORT_NUMERIC);
+		$rec['_fmt_taskpermalink'] = util_make_url('/pm/t_follow.php/%d');
+	}
+
+	/* copy comments */
+	$res = $ah->getMessages();
+	$c = array();
+	if ($res) while (($row = db_fetch_array($res))) {
+		$c[] = array(
+			'adddate' => (int)$row['adddate'],
+			'from_email' => $row['from_email'],
+			'body' => dbe2jsn($row['body']),
+			'from_user' => u2jsn($row['user_id']),
+		    );
+	}
+	$rec['~comments'] = $c;
+
+	/* copy extra fields */
+	foreach ($ah->getExtraFieldData() as $k => $v) {
+		$k = (int)$k;
+		switch ((int)$efarr[$k]['field_type']) {
+		case 2:		/* ARTIFACT_EXTRAFIELDTYPE_CHECKBOX */
+		case 5:		/* ARTIFACT_EXTRAFIELDTYPE_MULTISELECT */
+			/* stored as arrays, values as-is */
+			if (!is_array($v)) {
+				/* error? */
+				$v = array(100);
+			}
+			break;
+
+		/* all others are stored crippled */
+		default:
+			$v = dbe2jsn($v);
+			break;
+		}
+		switch ((int)$efarr[$k]['field_type']) {
+		/* integers */
+		case 10:	/* ARTIFACT_EXTRAFIELDTYPE_INTEGER */
+			$res = (int)$v;
+			break;
+
+		/* list values */
+		case 1:		/* ARTIFACT_EXTRAFIELDTYPE_SELECT */
+		case 3:		/* ARTIFACT_EXTRAFIELDTYPE_RADIO */
+		case 7:		/* ARTIFACT_EXTRAFIELDTYPE_STATUS */
+			$res = $efval[$k][(int)$v];
+			break;
+
+		/* arrays of list values */
+		case 2:		/* ARTIFACT_EXTRAFIELDTYPE_CHECKBOX */
+		case 5:		/* ARTIFACT_EXTRAFIELDTYPE_MULTISELECT */
+			$res = array();
+			foreach ($v as $fv) {
+				$res[] = $efval[$k][(int)$fv];
+			}
+			break;
+
+		/* special handling */
+		case 9:		/* ARTIFACT_EXTRAFIELDTYPE_RELATION */
+			$res = array();
+			foreach (preg_split("/\D+/", $v) as $fv) {
+				if (!util_nat0($fv)) {
+					continue;
+				}
+				$res[] = (int)$fv;
+			}
+			break;
+
+		/* strings */
+		case 4:		/* ARTIFACT_EXTRAFIELDTYPE_TEXT */
+		case 6:		/* ARTIFACT_EXTRAFIELDTYPE_TEXTAREA */
+		/* unknown */
+		case 8:		/* ARTIFACT_EXTRAFIELDTYPE_ASSIGNEE */
+		default:
+			$res = $v;
+			break;
+		}
+		$v = array(
+			'type' => $efmap[$k]['type'],
+			'value' => $res,
+		    );
+		if ($efmap[$k]['alias']) {
+			$v['alias'] = $efmap[$k]['alias'];
+		}
+		$rec['~extrafields'][$efmap[$k]['name']] = $v;
+	}
+
 	/*
 	 * here would be the place to add more pseudo-elements, like
-	 * a _comments Array, an _extrafields Value, a _files Value…
+	 * a _files Value…
 	 */
 
 	/* append to list of records to emit */

-----------------------------------------------------------------------

Summary of changes:
 src/utils/one-off-scripts/tracker-export.php |  198 +++++++++++++++++++++++---
 1 file changed, 182 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list