[evolvis-commits] r17506: by request of papel, somewhat merge the JSON Preferences code↵ from Evolvis 5.1 (revisions 17250 and 17264), although skip↵ the FusionForge compatibility code (this will never be fed↵ back into FF 4.8)

mirabilos at evolvis.org mirabilos at evolvis.org
Fri Sep 2 11:18:44 CEST 2011


Author: mirabilos
Date: 2011-09-02 11:18:44 +0200 (Fri, 02 Sep 2011)
New Revision: 17506

Added:
   branches/evolvis-pa/db/20110516-drop-evolvis-art_cust-prefs.sql
Modified:
   branches/evolvis-pa/common/tracker/ArtifactFactory.class.php
   branches/evolvis-pa/common/tracker/ArtifactFile.class.php
   branches/evolvis-pa/deb-specific/db-upgrade.pl
   branches/evolvis-pa/debian/changelog
Log:
by request of papel, somewhat merge the JSON Preferences code
from Evolvis 5.1 (revisions 17250 and 17264), although skip
the FusionForge compatibility code (this will never be fed
back into FF 4.8)


Modified: branches/evolvis-pa/common/tracker/ArtifactFactory.class.php
===================================================================
--- branches/evolvis-pa/common/tracker/ArtifactFactory.class.php	2011-09-02 09:09:29 UTC (rev 17505)
+++ branches/evolvis-pa/common/tracker/ArtifactFactory.class.php	2011-09-02 09:18:44 UTC (rev 17506)
@@ -22,6 +22,7 @@
  * USA
  */
 
+require_once $gfcommon.'include/minijson.php';
 require_once $gfcommon.'include/Error.class.php';
 require_once $gfcommon.'tracker/Artifact.class.php';
 require_once $gfcommon.'tracker/ArtifactType.class.php';
@@ -131,64 +132,20 @@
 					$this->closedaterange = $aq->getCloseDateRange();
 				} else {
 					$custom_pref=$u->getPreference('art_cust'.$this->ArtifactType->getID());
-					if ($custom_pref) {
-/**
- * $custom_pref is in one of the following formats:
- * v2|_assigned_to|_status|_order_col|_sort_ord|_changed|serialize(_extra_fields)| ← broken!
- * v2|_assigned_to|_status|_order_col|_sort_ord|_changed|_submitted_by|serialize(_extra_fields)
- * _assigned_to|_status|_order_col|_sort_ord|_changed|_submitted_by|serialize(_extra_fields)
- * _assigned_to|_status|_order_col|_sort_ord|_changed|serialize(_extra_fields)|_submitted_by
- * (This is due to some earlier programming bugs.) Since we cannot
- * distinguish between the latter two, we only use fields 0-4 there,
- * fields 1-7 for v2 format prefs.
- */
-						$pref_arr = explode('|', $custom_pref);
-						if ($pref_arr[0] === 'v2') {
-							$_assigned_to = $pref_arr[1];
-							$_status = $pref_arr[2];
-							$order_col = $pref_arr[3];
-							$sort = $pref_arr[4];
-							$_changed = $pref_arr[5];
-							/* deal with database corruption */
-							$tmp = util_nat0($pref_arr[6]);
-							if ($tmp === false) {
-								$_submitted_by = 0;
-								$_extra_fields = array();
-							} else {
-								$_submitted_by = $tmp;
-								$_extra_fields = unserialize($pref_arr[7]);
-								if (!is_array($_extra_fields)) {
-									$_extra_fields = array();
-								}
-							}
-						} else {
-							/*
-							 * cope with bugs in
-							 * earlier Evolvis -
-							 * sucks, but what can
-							 * we do… [#944]
-							 */
-							$_assigned_to = $pref_arr[0];
-							$_status = $pref_arr[1];
-							$order_col = $pref_arr[2];
-							$sort = $pref_arr[3];
-							$_changed = $pref_arr[4];
-							/* if it’s numeric, chances are good */
-							$tmp = util_nat0($pref_arr[5]);
-							if ($tmp === false) {
-								/*
-								 * in theory, we could use
-								 * $pref_arr[6] here and
-								 * make $pref_arr[5] the
-								 * $_extra_fields but it
-								 * may just as well break
-								 */
-								$_submitted_by = 0;
-							} else {
-								$_submitted_by = $tmp;
-							}
+					if ($custom_pref && $custom_pref[0] == '{' /*}*/) {
+						/* try JSON encoded preferences */
+						$pref_arr = array();
+						if (minijson_decode($custom_pref,
+						    &$pref_arr)) {
+							$_assigned_to = util_ifsetor($pref_arr['assigned_to']);
+							$_status = util_ifsetor($pref_arr['status']);
+							$order_col = util_ifsetor($pref_arr['order_col']);
+							$sort = util_ifsetor($pref_arr['sort']);
+							$_changed = util_ifsetor($pref_arr['changed']);
+							$_extra_fields = util_ifsetor($pref_arr['extra_fields'], array());
+							$_submitted_by = util_ifsetor($pref_arr['submitted_by']);
+							$set = 'custom';
 						}
-						$set='custom';
 					} else {
 						//default to open
 						$_assigned_to=0;
@@ -242,14 +199,19 @@
 				}
 
 				$extra_pref = '';
+				$pref_s = array(
+					'assigned_to' => $_assigned_to,
+					'status' => $_status,
+					'order_col' => $_order_col,
+					'sort' => $_sort_ord,
+					'changed' => $_changed,
+					'submitted_by' => $_submitted_by,
+				    );
 				if (count($aux_extra_fields) > 0) {
-					$extra_pref = serialize($aux_extra_fields);
+					$pref_s['extra_fields'] = $aux_extra_fields;
 				}
-				
-				$pref_ = 'v2|' . $_assigned_to . '|' .
-				    $_status . '|' . $_order_col . '|' .
-				    $_sort_ord . '|' . $_changed . '|' .
-				    $_submitted_by . '|' . $extra_pref;
+
+				$pref_ = minijson_encode($pref_s, false);
 				if ($pref_ != $u->getPreference('art_cust'.$this->ArtifactType->getID())) {
 					$u->setPreference('art_cust'.$this->ArtifactType->getID(),$pref_);
 				}

Modified: branches/evolvis-pa/common/tracker/ArtifactFile.class.php
===================================================================
--- branches/evolvis-pa/common/tracker/ArtifactFile.class.php	2011-09-02 09:09:29 UTC (rev 17505)
+++ branches/evolvis-pa/common/tracker/ArtifactFile.class.php	2011-09-02 09:18:44 UTC (rev 17506)
@@ -126,7 +126,6 @@
 		//	data validation
 		//
 		if (!$filename || !$filetype || !$filesize || !$bin_data) {
-			//echo '<p>|'.$filename.'|'.$filetype.'|'.$filesize.'|'.$bin_data.'|';
 			$this->setError(_('ArtifactFile: File name, type, size, and data are required'));
 			return false;
 		}

Added: branches/evolvis-pa/db/20110516-drop-evolvis-art_cust-prefs.sql
===================================================================
--- branches/evolvis-pa/db/20110516-drop-evolvis-art_cust-prefs.sql	                        (rev 0)
+++ branches/evolvis-pa/db/20110516-drop-evolvis-art_cust-prefs.sql	2011-09-02 09:18:44 UTC (rev 17506)
@@ -0,0 +1 @@
+DELETE FROM user_preferences WHERE preference_name LIKE 'art_cust%';

Modified: branches/evolvis-pa/deb-specific/db-upgrade.pl
===================================================================
--- branches/evolvis-pa/deb-specific/db-upgrade.pl	2011-09-02 09:09:29 UTC (rev 17505)
+++ branches/evolvis-pa/deb-specific/db-upgrade.pl	2011-09-02 09:18:44 UTC (rev 17506)
@@ -3490,6 +3490,8 @@
 	$dbh->commit();
     }
 
+    &update_with_sql("20110516-drop-evolvis-art_cust-prefs.sql","4.8.3+evolvis36.0pa1");
+
     ########################### INSERT HERE #################################
 
     &debug ("It seems your database $action went well and smoothly. That's cool.") ;

Modified: branches/evolvis-pa/debian/changelog
===================================================================
--- branches/evolvis-pa/debian/changelog	2011-09-02 09:09:29 UTC (rev 17505)
+++ branches/evolvis-pa/debian/changelog	2011-09-02 09:18:44 UTC (rev 17506)
@@ -1,3 +1,9 @@
+gforge (4.8.3+evolvis36.0pa1) UNMERGED; urgency=low
+
+  * Change art_cust* prefs to use JSON serialisation
+
+ -- Thorsten Glaser <t.glaser at tarent.de>  Fri, 02 Sep 2011 11:11:10 +0200
+
 gforge (4.8.3+evolvis36) unstable; urgency=low
 
   * Evolvis theme: display Wiki link in Public Areas



More information about the evolvis-commits mailing list