[Fusionforge-commits] r15211 - in trunk: . src/common/include

Roland Mas lolando at fusionforge.org
Mon Mar 26 10:59:28 CEST 2012


Author: lolando
Date: 2012-03-26 10:59:28 +0200 (Mon, 26 Mar 2012)
New Revision: 15211

Modified:
   trunk/
   trunk/src/common/include/database-pgsql.php
   trunk/src/common/include/extras-debug.php
Log:
Merged from Evolvis: better DB query tracing


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk:8721-8727
/shelves/aljeux:15005,15012,15150,15154-15160,15177-15179,15203
/branches/Branch_4_7:6879,6881,6884,6897,6899,6902,6904,6906,6909,6911,6922,6932,6936,6939,6942,6944,6946-6948,6954,6956,6959,7000-7001,7012,7111,7130-7131,7133-7134,7138,7140-7142,7147-7148,7159-7160,7163,7168,7177,7179,7203,7205,7207,7210,7212,7251-7253,7255,7284,7287,7291,7293,7295-7296,7300,7355,7365-7366,7375-7376,7378,7395,7423-7426,7435,7458,7504,7567,7577,7623-7624,7638,7659-7660,7662,7665,7668,7674,7699,7746-7748,7771,7774,7786,7838
/shelves/alain_peyrat:14997-15003
/branches/Branch_4_8:7334-7335,7344-7345,7382,7387,7389-7390,7396,7398,7401-7402,7428-7429,7437,7440,7443,7449-7455,7459,7462,7466,7469-7470,7476-7478,7480,7485,7490-7492,7505,7540,7556-7560,7568,7570-7571,7573,7576,7580,7609-7611,7613,7615,7618,7621-7622,7625-7627,7639,7658,7661,7663-7664,7666-7667,7673,7675,7678,7680,7685,7688-7689,7693,7700,7706-7708,7713,7725,7728-7742,7760,7763-7764,7767,7769-7770,7773,7776,7784-7785,7791,7797,7799,7802-7808,7810-7811,7816,7818,7825-7828,7839,7846-7847,7850,7894,7902,7920-7922,7927-7928,7932,7936-7937,7939,7942,7944-7945,7947,7951,7956,7958,7960,8064,8079-8080,8108,8113,8119,8121,8127-8128,8145,8197,8201-8202,8216,8224,8226,8228,8247-8250,8252,8271-8272,8310-8311,8328,8337,8339-8357,8361,8371,8373-8375,8378-8379,8383-8396,8415,8427-8431,8438-8441,8449,8452-8453,8458,8461,8477-8478,8480,8482,8492,8514,8530,8604-8605,8608,8637,8662,8674,8751,8754,8756,8760-8761,8812,8850,8945,8995,8998,9004-9006,9124,9137,9141,9317,9443,9469,9670,9701,9726,9934,10013,10310,10314,10366,12790,13085
/branches/Branch_5_1:11607-11609,11621,11625,11627,11631,11638,11644,11647-11651,11677,11680-11681,11683-11684,11719-11720,11724,11754,11780,11783,11792,11794,11802,11808-11816,11818,11822-11824,11827-11829,11834-11835,11847,11849,11851-11852,11855,11858,11862,11867,11869-11872,11876,11880,11893,11902-11905,11915,11923-11927,11929-11930,11932,11934-11941,11943,11948-11949,11952-11954,11956-11960,11962,11965-11966,11972,11975,11980,11983-11984,11986-11987,11990,11992-11997,12003-12004,12010-12013,12015,12018-12024,12043-12044,12046-12061,12063,12065,12070,12073-12076,12081-12083,12093-12094,12102,12105,12118,12124,12127-12128,12139,12141,12143,12148-12149,12153,12157-12159,12168-12169,12175-12180,12190,12194-12198,12203,12208-12213,12217-12258,12262,12264-12266,12274-12277,12281-12282,12287-12290,12340,12345-12346,12352,12359,12472-12473,12594,12634,12636-12638,12658-12659,12684-12712,12714-12715,12733,12780-12783,12785-12786,12795,12797,12800-12802,12815-12816,12840-12856,12860,12882-12883,12888-12892,12897,12904,12914-12917,12922-12926,12929-12936,12939,12959-12965,12967-12971,13011,13022,13025,13031-13032,13034,13043-13046,13048-13050,13053,13056,13058,13061,13068-13070,13075,13088,13090-13091,13101,13103-13104,13106,13108-13109,13111-13114,13116-13117,13120,13125,13127-13128,13148,13153-13161,13163,13165-13166,13174-13175,13188,13190,13211-13212,13219,13221,13231-13234,13236-13238,13253,13257-13270,13272-13274,13287-13300,13302-13342,13355-13374,13377-13379,13386-13389,13391-13400,13404,13408,13410,13412,13415-13416,13420,13422-13426,13429-13432,13452,13456,13461-13464,13466,13468-13470,13472-13477,13492,13517-13519,13527-13532,13589-13590,13624-13628,13645,13661-13663,13666,13684,13689-13690,13697,13699,13704,13745,13761,13766-13767,13769-13770,13772-13801,13808,13817-13818,13820-13823,13830-13831,13838,13854,13861,13984,13986-13988,14009,14013-14015,14020-14021,14036,14039-14045,14047,14051-14053,14056-14059,14065,14072,14080-14084,14086-14090,14095-14099,14101-14121,14130-14136,14162-14167,14172-14173,14184,14215-14220,14238-14241,14266-14269,14273-14278,14285,14288-14289,14303,14305,14307,14309,14311,14313-14316,14318-14320,14322,14358,14391-14392,14444-14446,14461-14462,14472,14476-14480,14496,14498,14505-14506,14511,14515,14538-14554,14558-14574,14577-14578,14582-14597,14599-14602,14614-14616,14686-14687,14698,14702,14705,14736,14738,14740,14742-14743,14747,14784-14786,14802-14809,14812-14813,14898-14904,14908-14909,14929-14931,15014-15015,15024-15028,15032,15044-15049,15056-15058,15070,15081-15082,15087,15092-15095,15121-15125,15128-15135,15138-15139,15141,15144,15147-15148,15169-15173,15175,15182,15186-15188,15190
/branches/Branch_5_0:8892,8895,8897-8898,8900,8903-8904,8906-8907,8910,8915,8922,8924,8926,8929,8931-8933,8941,8946,8951,8955,8972-8977,8981,8997,8999,9002,9031-9032,9050,9080-9081,9084-9086,9093-9095,9102-9104,9108,9113-9115,9117-9118,9123,9125,9127-9131,9135-9136,9139,9146,9148-9150,9179-9191,9193-9195,9198,9200,9202,9204,9207,9209,9211,9213,9215,9220-9222,9231,9234-9235,9243,9251,9254,9259,9287,9315,9318,9347-9349,9358,9396,9427,9429,9431-9433,9441-9442,9444-9445,9462,9464,9468,9522-9523,9549,9551-9552,9576-9577,9579,9615,9633-9634,9672-9673,9675-9676,9684,9686-9687,9689,9699,9727,9729,9731,9930-9932,9935,9956,9980,10005-10006,10021,10024,10027,10064,10081-10082,10273,10285,10820-10824,10868,10872,10876-10878,10880,10918,11015,11017,11058-11060,11085-11086,11160-11165,11252-11253,11287,11294,11581,11619-11620,11679,11722-11723,11907,11974,12789,12940,12986,13023-13024,13086,13121-13122,13162,13465,13496,13501,13503,13660

   + /branches/Branch_4_7:6879,6881,6884,6897,6899,6902,6904,6906,6909,6911,6922,6932,6936,6939,6942,6944,6946-6948,6954,6956,6959,7000-7001,7012,7111,7130-7131,7133-7134,7138,7140-7142,7147-7148,7159-7160,7163,7168,7177,7179,7203,7205,7207,7210,7212,7251-7253,7255,7284,7287,7291,7293,7295-7296,7300,7355,7365-7366,7375-7376,7378,7395,7423-7426,7435,7458,7504,7567,7577,7623-7624,7638,7659-7660,7662,7665,7668,7674,7699,7746-7748,7771,7774,7786,7838
/shelves/aljeux:15005,15012,15150,15154-15160,15177-15179,15203
/trunk:8721-8727
/shelves/alain_peyrat:14997-15003
/branches/Branch_4_8:7334-7335,7344-7345,7382,7387,7389-7390,7396,7398,7401-7402,7428-7429,7437,7440,7443,7449-7455,7459,7462,7466,7469-7470,7476-7478,7480,7485,7490-7492,7505,7540,7556-7560,7568,7570-7571,7573,7576,7580,7609-7611,7613,7615,7618,7621-7622,7625-7627,7639,7658,7661,7663-7664,7666-7667,7673,7675,7678,7680,7685,7688-7689,7693,7700,7706-7708,7713,7725,7728-7742,7760,7763-7764,7767,7769-7770,7773,7776,7784-7785,7791,7797,7799,7802-7808,7810-7811,7816,7818,7825-7828,7839,7846-7847,7850,7894,7902,7920-7922,7927-7928,7932,7936-7937,7939,7942,7944-7945,7947,7951,7956,7958,7960,8064,8079-8080,8108,8113,8119,8121,8127-8128,8145,8197,8201-8202,8216,8224,8226,8228,8247-8250,8252,8271-8272,8310-8311,8328,8337,8339-8357,8361,8371,8373-8375,8378-8379,8383-8396,8415,8427-8431,8438-8441,8449,8452-8453,8458,8461,8477-8478,8480,8482,8492,8514,8530,8604-8605,8608,8637,8662,8674,8751,8754,8756,8760-8761,8812,8850,8945,8995,8998,9004-9006,9124,9137,9141,9317,9443,9469,9670,9701,9726,9934,10013,10310,10314,10366,12790,13085
/branches/Branch_5_1:11607-11609,11621,11625,11627,11631,11638,11644,11647-11651,11677,11680-11681,11683-11684,11719-11720,11724,11754,11780,11783,11792,11794,11802,11808-11816,11818,11822-11824,11827-11829,11834-11835,11847,11849,11851-11852,11855,11858,11862,11867,11869-11872,11876,11880,11893,11902-11905,11915,11923-11927,11929-11930,11932,11934-11941,11943,11948-11949,11952-11954,11956-11960,11962,11965-11966,11972,11975,11980,11983-11984,11986-11987,11990,11992-11997,12003-12004,12010-12013,12015,12018-12024,12043-12044,12046-12061,12063,12065,12070,12073-12076,12081-12083,12093-12094,12102,12105,12118,12124,12127-12128,12139,12141,12143,12148-12149,12153,12157-12159,12168-12169,12175-12180,12190,12194-12198,12203,12208-12213,12217-12258,12262,12264-12266,12274-12277,12281-12282,12287-12290,12340,12345-12346,12352,12359,12472-12473,12594,12634,12636-12638,12658-12659,12684-12712,12714-12715,12733,12780-12783,12785-12786,12795,12797,12800-12802,12815-12816,12840-12856,12860,12882-12883,12888-12892,12897,12904,12914-12917,12922-12926,12929-12936,12939,12959-12965,12967-12971,13011,13022,13025,13031-13032,13034,13043-13046,13048-13050,13053,13056,13058,13061,13068-13070,13075,13088,13090-13091,13101,13103-13104,13106,13108-13109,13111-13114,13116-13117,13120,13125,13127-13128,13148,13153-13161,13163,13165-13166,13174-13175,13188,13190,13211-13212,13219,13221,13231-13234,13236-13238,13253,13257-13270,13272-13274,13287-13300,13302-13342,13355-13374,13377-13379,13386-13389,13391-13400,13404,13408,13410,13412,13415-13416,13420,13422-13426,13429-13432,13452,13456,13461-13464,13466,13468-13470,13472-13477,13492,13517-13519,13527-13532,13589-13590,13624-13628,13645,13661-13663,13666,13684,13689-13690,13697,13699,13704,13745,13761,13766-13767,13769-13770,13772-13801,13808,13817-13818,13820-13823,13830-13831,13838,13854,13861,13984,13986-13988,14009,14013-14015,14020-14021,14036,14039-14045,14047,14051-14053,14056-14059,14065,14072,14080-14084,14086-14090,14095-14099,14101-14121,14130-14136,14162-14167,14172-14173,14184,14215-14220,14238-14241,14266-14269,14273-14278,14285,14288-14289,14303,14305,14307,14309,14311,14313-14316,14318-14320,14322,14358,14391-14392,14444-14446,14461-14462,14472,14476-14480,14496,14498,14505-14506,14511,14515,14538-14554,14558-14574,14577-14578,14582-14597,14599-14602,14614-14616,14686-14687,14698,14702,14705,14736,14738,14740,14742-14743,14747,14784-14786,14802-14809,14812-14813,14898-14904,14908-14909,14929-14931,15014-15015,15024-15028,15032,15044-15049,15056-15058,15070,15081-15082,15087,15092-15095,15121-15125,15128-15135,15138-15139,15141,15144,15147-15148,15169-15173,15175,15182,15186-15188,15190
/branches/Branch_5_0:8892,8895,8897-8898,8900,8903-8904,8906-8907,8910,8915,8922,8924,8926,8929,8931-8933,8941,8946,8951,8955,8972-8977,8981,8997,8999,9002,9031-9032,9050,9080-9081,9084-9086,9093-9095,9102-9104,9108,9113-9115,9117-9118,9123,9125,9127-9131,9135-9136,9139,9146,9148-9150,9179-9191,9193-9195,9198,9200,9202,9204,9207,9209,9211,9213,9215,9220-9222,9231,9234-9235,9243,9251,9254,9259,9287,9315,9318,9347-9349,9358,9396,9427,9429,9431-9433,9441-9442,9444-9445,9462,9464,9468,9522-9523,9549,9551-9552,9576-9577,9579,9615,9633-9634,9672-9673,9675-9676,9684,9686-9687,9689,9699,9727,9729,9731,9930-9932,9935,9956,9980,10005-10006,10021,10024,10027,10064,10081-10082,10273,10285,10820-10824,10868,10872,10876-10878,10880,10918,11015,11017,11058-11060,11085-11086,11160-11165,11252-11253,11287,11294,11581,11619-11620,11679,11722-11723,11907,11974,12789,12940,12986,13023-13024,13086,13121-13122,13162,13465,13496,13501,13503,13660


Modified: trunk/src/common/include/database-pgsql.php
===================================================================
--- trunk/src/common/include/database-pgsql.php	2012-03-26 08:52:30 UTC (rev 15210)
+++ trunk/src/common/include/database-pgsql.php	2012-03-26 08:59:28 UTC (rev 15211)
@@ -173,13 +173,13 @@
 	$qstring = file_get_contents($file);
 	if (!$qstring) {
 		if ($sysdebug_dbquery) {
-			ffDebug("warning",
+			ffDebug("database",
 			    "aborted call of db_query_from_file():",
 			    "Cannot read file: " . $file .
 			    "\n\n" . debug_string_backtrace());
 		} else if ($sysdebug_dberrors) {
-			ffDebug("warning", "db_query_from_file() aborted (" .
-			    "Cannot read file: " . $file . ")", false);
+			ffDebug("database", "db_query_from_file() aborted (" .
+			    "Cannot read file: " . $file . ")");
 		} else {
 			error_log("db_query_from_file(): Cannot read file: " . $file);
 		}
@@ -202,7 +202,7 @@
 			    $qstring, debug_string_backtrace());
 		}
 	} else if ($sysdebug_dbquery || $sysdebug_dberrors) {
-		ffDebug("warning", "db_query_from_file() failed (" .
+		ffDebug("database", "db_query_from_file() failed (" .
 		    db_error($dbserver) . "), SQL: " . $qstring,
 		    $sysdebug_dbquery ? debug_string_backtrace() : false);
 	} else {
@@ -249,10 +249,10 @@
 			    debug_string_backtrace());
 		}
 	} else if ($sysdebug_dbquery) {
-		ffDebug("warning", "failed call of db_query_params():",
+		ffDebug("database", "failed call of db_query_params():",
 		    db_error($dbserver) . "\n\n" . debug_string_backtrace());
 	} else if ($sysdebug_dberrors) {
-		ffDebug("warning", "db_query_params() failed (" .
+		ffDebug("database", "db_query_params() failed (" .
 		    db_error($dbserver) . "), SQL: " . $qstring,
 		    print_r(array("params" => $params), 1));
 	} else {

Modified: trunk/src/common/include/extras-debug.php
===================================================================
--- trunk/src/common/include/extras-debug.php	2012-03-26 08:52:30 UTC (rev 15210)
+++ trunk/src/common/include/extras-debug.php	2012-03-26 08:59:28 UTC (rev 15211)
@@ -1,14 +1,15 @@
 <?php
 
+// initialise globals used by the debugging code
 $sysdebug_dberrors = forge_get_config('sysdebug_dberrors');
 $sysdebug_dbquery = forge_get_config('sysdebug_dbquery');
 $sysdebug_ignored = forge_get_config('sysdebug_ignored');
-if (!isset($ffErrors))
+if (!isset($ffErrors)) {
 	$ffErrors = array();
+}
 
 // error handler function
-function ffErrorHandler($errno, $errstr, $errfile, $errline)
-{
+function ffErrorHandler($errno, $errstr, $errfile, $errline) {
 	global $ffErrors, $sysdebug_ignored, $sysdebug__aborted;
 
 	if ($sysdebug__aborted) {
@@ -16,56 +17,62 @@
 		return true;
 	}
 
-	if (!$sysdebug_ignored && error_reporting() == 0)
+	if (!$sysdebug_ignored && error_reporting() == 0) {
 		/* prepended @ to statement => ignore */
 		return false;
+	}
 
 	$msg = "[$errno] $errstr ($errfile at $errline)";
 
-	// Display messages only once.
+	// display messages only once
 	foreach ($ffErrors as $m) {
-		if ($m['message'] == $msg)
+		if ($m['message'] == $msg) {
 			return true;
+		}
 	}
 
 	switch ($errno) {
-		case E_USER_ERROR:
-		case E_ERROR:
-			$type = 'error';
-			break;
+	case E_USER_ERROR:
+	case E_ERROR:
+		$type = 'error';
+		break;
 
-		case E_USER_WARNING:
-		case E_WARNING:
-			$type = 'warning';
-			break;
+	case E_USER_WARNING:
+	case E_WARNING:
+		$type = 'warning';
+		break;
 
-		case E_USER_NOTICE:
-		case E_NOTICE:
-			$type = 'notice';
-			break;
+	case E_USER_NOTICE:
+	case E_NOTICE:
+		$type = 'notice';
+		break;
 
-		case E_STRICT:
-		case E_USER_DEPRECATED:
-		case E_DEPRECATED:
-			$type = "strict";
-			break;
+	case E_STRICT:
+	case E_USER_DEPRECATED:
+	case E_DEPRECATED:
+		$type = "strict";
+		break;
 
-		default:
-			$type = 'unknown';
-			break;
+	default:
+		$type = 'unknown';
+		break;
 	}
 
-	if (forge_get_config('sysdebug_backtraces'))
+	if (forge_get_config('sysdebug_backtraces')) {
 		$msg .= "\n" .
 		    '<pre style="font-weight:normal; font-size:90%; color:#000066; line-height:100%;">' .
 		    htmlentities(debug_string_backtrace()) . "</pre>";
+	}
 
-	$ffErrors[] = array('type' => $type, 'message' => $msg);
+	$ffErrors[] = array(
+		'type' => $type,
+		'message' => $msg,
+	    );
 	/* Don't execute PHP internal error handler */
 	return true;
 }
 
-
+// output buffer finaliser function
 function ffOutputHandler($buffer) {
 	global $ffErrors, $sysdebug_enable, $sysdebug__aborted,
 	    $sysdebug_lazymode_on, $sysdebug_doframe, $gfcommon,
@@ -82,19 +89,22 @@
 	}
 
 	/* in case we’re aborted */
-	if (!$sysdebug_enable)
+	if (!$sysdebug_enable) {
 		return $buffer;
+	}
 
 	/* if content-type != text/html* assume abortion */
 	if ($sysdebug_lazymode_on) {
 		$thdr = 'content-type:';
 		$tstr = 'content-type: text/html';
 		foreach (headers_list() as $h) {
-			if (strncasecmp($h, $thdr, strlen($thdr)))
+			if (strncasecmp($h, $thdr, strlen($thdr))) {
 				continue;
-			if (strncasecmp($h, $tstr, strlen($tstr)))
+			}
+			if (strncasecmp($h, $tstr, strlen($tstr))) {
 				/* application/something, maybe */
 				return $buffer;
+			}
 		}
 	}
 
@@ -120,8 +130,7 @@
 	    '<a href="javascript:toggle_ffErrors();">Click to toggle</a>' .
 	    "\n<div id=\"ffErrorsBlock\">";
 
-	$doctype = util_ifsetor($HTML->doctype);
-	if (!$doctype) {
+	if (!($doctype = util_ifsetor($HTML->doctype))) {
 		$doctype = 'transitional';
 	}
 
@@ -139,25 +148,33 @@
 	$bufend = array(false, substr($buffer, -100));
 	if (substr($buffer, -strlen("</html>")) != "</html>") {
 		$bufend[0] = true;
-		$ffErrors[] = array('type' => "error",
-		    'message' => htmlentities("does not end with </html> tag"));
+		$ffErrors[] = array(
+			'type' => "error",
+			'message' => htmlentities("does not end with </html> tag"),
+		    );
 		$buffer = str_ireplace("</html>", "", $buffer);
-	} else
+	} else {
 		$buffer = substr($buffer, 0, -strlen("</html>"));
+	}
 	$buffer = rtrim($buffer);	/* spaces, newlines, etc. */
 	if (substr($buffer, -strlen("</body>")) != "</body>") {
 		$bufend[0] = true;
-		$ffErrors[] = array('type' => "error",
-		    'message' => htmlentities("does not end with </body> tag"));
+		$ffErrors[] = array(
+			'type' => "error",
+			'message' => htmlentities("does not end with </body> tag"),
+		    );
 		$buffer = str_ireplace("</body>", "", $buffer);
-	} else
+	} else {
 		$buffer = substr($buffer, 0, -strlen("</body>"));
+	}
 	$buffer = rtrim($buffer);	/* spaces, newlines, etc. */
 
 	if ($bufend[0]) {
-		$ffErrors[] = array('type' => "info",
-		    'message' => "The output has ended thus: " .
-		    htmlentities($bufend[1]));
+		$ffErrors[] = array(
+			'type' => "info",
+			'message' => "The output has ended thus: " .
+			    htmlentities($bufend[1]),
+		   );
 	}
 
 	/* append errors, if any */
@@ -174,8 +191,9 @@
 	/* generate buffer for checking */
 	$cbuf = str_ireplace('http://www.w3.org/TR/xhtml1/DTD/',
 	    'file://' . $dtdpath, $buffer);
-	if ($has_div)
+	if ($has_div) {
 		$cbuf .= "\n</div></div>";
+	}
 	$cbuf .= "\n</body></html>\n";
 
 	/* now check XHTML validity… two means */
@@ -205,16 +223,18 @@
 			$serr = join("\n", preg_grep(
 			    '/^-:[0-9]*: Entity'." 'nbsp' ".'not defined$/',
 			    explode("\n", $serr), PREG_GREP_INVERT));
-		} else
+		} else {
 			$valck[] = array(
-				'msg' => "could not run xmlstarlet"
+				'msg' => "could not run xmlstarlet",
 			    );
+		}
 		if ($rv) {
 			$valck[] = array(
 				'msg' => "xmlstarlet found that this document is not valid (errorlevel $rv)!",
-				'extra' => $pre_tag . htmlspecialchars(trim($serr .
+				'extra' => $pre_tag .
+				    htmlspecialchars(trim($serr .
 				    "\n\n" . $sout)) . "</pre>",
-				'type' => "error"
+				'type' => "error",
 			    );
 			$appsrc = true;
 		}
@@ -235,7 +255,7 @@
 			$valck[] = array(
 				'msg' => "Akelos XHTML Validator found some errors on this document!",
 				'extra' => $errs,
-				'type' => "error"
+				'type' => "error",
 			    );
 			$appsrc = true;
 		}
@@ -243,14 +263,19 @@
 
 	/* append XHTML source code, if validation failed */
 	if ($appsrc) {
-		if (!$sysdebug_akelos || $vbuf == $sbuf[1])
-			$vbuf = "<ol><li>" . $pre_tag . join(" </pre></li>\n<li>" . $pre_tag, explode("\n", htmlentities(rtrim($cbuf)))) . " </pre></li></ol>";
-		else
-			$vbuf = $pre_tag . htmlentities(rtrim($sbuf[0])) . "</pre>" . $vbuf;
+		if (!$sysdebug_akelos || $vbuf == $sbuf[1]) {
+			$vbuf = "<ol><li>" . $pre_tag .
+			    join(" </pre></li>\n<li>" . $pre_tag,
+			    explode("\n", htmlentities(rtrim($cbuf)))) .
+			    " </pre></li></ol>";
+		} else {
+			$vbuf = $pre_tag . htmlentities(rtrim($sbuf[0])) .
+			    "</pre>" . $vbuf;
+		}
 		$valck[] = array(
 			'msg' => "Since XHTML validation failed, here’s the checked document for you to look at:",
 			'extra' => $vbuf,
-			'type' => 'normal'
+			'type' => 'normal',
 		    );
 	}
 
@@ -263,16 +288,19 @@
 		if (!isset($msg['type']) || !$msg['type']) {
 			$msg['type'] = 'unknown';
 		}
-		$buffer .= "\n	<div class=\"" . $msg['type'] . '">' . $msg['msg'];
-		if (isset($msg['extra']))
+		$buffer .= "\n	<div class=\"" . $msg['type'] . '">' .
+		    $msg['msg'];
+		if (isset($msg['extra'])) {
 			$buffer .= "\n		<div style=\"font-weight:normal; font-size:90%; color:#333333;\">" .
 			    $msg['extra'] . "</div>\n	";
+		}
 		$buffer .= "</div>";
 	}
 
 	/* return final buffer */
-	if ($has_div)
+	if ($has_div) {
 		$buffer .= "\n</div></div>";
+	}
 	if ($sysdebug_doframe) {
 		return substr($buffer, $bufferstrip);
 	} else {
@@ -280,6 +308,7 @@
 	}
 }
 
+// exception handler function
 function ffExceptionHandler($e) {
 	global $sysdebug__aborted;
 
@@ -319,15 +348,36 @@
 }
 
 function sysdebug_off($hdr=false, $replace=true, $resp=false) {
-	global $sysdebug_enable;
+	global $ffErrors, $sysdebug_enable;
 
 	if ($sysdebug_enable) {
 		$sysdebug_enable = false;
-		$buf = ob_get_flush();
+		$buf = @ob_get_flush();
 
 		if ($buf === false) {
 			$buf = "";
 		}
+
+		/* if we had any old errors, log them */
+		$olderrors = "";
+		foreach ($ffErrors as $msg) {
+			$olderrors .= "\n(" . $msg['type'] . ") " .
+			    $msg['message'];
+		}
+		if ($olderrors) {
+			if (!forge_get_config('sysdebug_backtraces')) {
+				$olderrors .= "\n" . debug_string_backtrace();
+			}
+			$olderrors = rtrim($olderrors);
+			$pfx = "";
+			foreach (explode("\n",
+			    "sysdebug_off: previous errors found:" . $olderrors)
+			    as $olderrorline) {
+				error_log($pfx . $olderrorline);
+				/* followup lines get indented */
+				$pfx = ">>> ";
+			}
+		}
 	} else {
 		$buf = false;
 	}
@@ -349,7 +399,7 @@
 	$sysdebug_lazymode_on = $enable ? true : false;
 }
 
-function ffDebug($type,$intro,$pretext) {
+function ffDebug($type, $intro, $pretext=false) {
 	global $ffErrors;
 
 	if (!$type) {




More information about the Fusionforge-commits mailing list