Bläddra i källkod

#234 Removed the error_reporting directive and implemented a workaround to reduce the potential warnings issued by PHP

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@759 a333f486-631f-4898-b8df-5754b55c2be0
romainq 14 år sedan
förälder
incheckning
fdd499670a
3 ändrade filer med 41 tillägg och 98 borttagningar
  1. 0 76
      core/cmdbobject.class.inc.php
  2. 6 3
      core/metamodel.class.php
  3. 35 19
      pages/UI.php

+ 0 - 76
core/cmdbobject.class.inc.php

@@ -75,82 +75,6 @@ require_once('cmdbchangeop.class.inc.php');
 require_once('csvparser.class.inc.php');
 require_once('bulkchange.class.inc.php');
 
-
-//
-// Error handling
-// To be finalized... or removed ?
-//
-function cmdbErrorHandler($errno, $errstr, $errfile, $errline)
-{
-//		font-family: Courier-New, Courier, Arial, Helevtica;
-	$sErrorStyle = "
-		background-color: #ffaaaa;
-		color: #000000;
-		border: 1px dashed #000000;
-		padding: 0.25em;
-		margin-top: 1em;
-	";
-	$sCallStackStyle = "
-		font-size: smaller;
-		background-color: #ffcccc;
-		color: #000000;
-		border: 1px dashed #000000;
-		padding: 0.25em;
-		margin-top: 1em;
-	";
-
-	switch ($errno)
-	{
-	case E_USER_ERROR:
-	case E_ERROR:
-		echo "<div style=\"$sErrorStyle\">\n";
-		echo "<b>Error</b> [$errno] $errstr<br />\n";
-		echo "<div style=\"$sCallStackStyle\">\n";
-		MyHelpers::dump_callstack(1);
-		echo "</div>\n";
-		echo "Hereafter the biz model internals:<br />\n";
-		echo "<pre>\n";
-		MetaModel::static_var_dump();
-		echo "</pre>\n";
-		echo "Aborting...<br />\n";
-		echo "</div>\n";
-		exit(1);
-		break;
-	case E_USER_WARNING:
-	case E_WARNING:
-		echo "<div style=\"background-color:#FAA;\">\n";
-		echo "<b>Warning</b> [$errno] $errstr<br />\n";
-		echo "<div style=\"background-color:#FCC;\">\n";
-		MyHelpers::dump_callstack(1);
-		echo "</div>\n";
-		echo "</div>\n";
-		break;
-	case E_USER_NOTICE:
-	case E_NOTICE:
-		echo "<div style=\"background-color:#FAA;\">\n";
-		echo "<b>Notice</b> [$errno] $errstr<br />\n";
-		echo "<div style=\"background-color:#FCC;\">\n";
-		MyHelpers::dump_callstack(1);
-		echo "</div>\n";
-		echo "</div>\n";
-		break;
-	default:
-		echo "Unknown error type: [$errno] $errstr<br />\n";
-		MyHelpers::dump_callstack(1);
-		break;
-	}
-}
-
-error_reporting(E_ALL | E_STRICT);
-//set_error_handler("cmdbErrorHandler");
-
-
-
-//
-//
-//
-
-
 /**
  * A persistent object, which changes are accurately recorded
  *

+ 6 - 3
core/metamodel.class.php

@@ -2080,7 +2080,8 @@ abstract class MetaModel
 				self::DbgTrace("External key $sKeyAttCode (class: $sKeyClass), call MakeQuery()");
 				$oSelectExtKey = self::MakeQuery($aSelectedClasses, $oConditionTree, $aClassAliases, $aTableAliases, $aTranslation, $oExtFilter, $aExpAtts);
 
-				$sLocalKeyField = current($oKeyAttDef->GetSQLExpressions()); // get the first column for an external key
+				$aCols = $oKeyAttDef->GetSQLExpressions(); // Workaround a PHP bug: sometimes issuing a Notice if invoking current(somefunc())
+				$sLocalKeyField = current($aCols); // get the first column for an external key
 				$sExternalKeyField = self::DBGetKey($sKeyClass);
 				self::DbgTrace("External key $sKeyAttCode, Join on $sLocalKeyField = $sExternalKeyField");
 				if ($oKeyAttDef->IsNullAllowed())
@@ -2992,7 +2993,8 @@ abstract class MetaModel
 					$sRemoteTable = self::DBGetTable($sRemoteClass);
 					$sRemoteKey = self::DBGetKey($sRemoteClass);
 
-					$sExtKeyField = current($oAttDef->GetSQLExpressions()); // get the first column for an external key
+					$aCols = $oKeyAttDef->GetSQLExpressions(); // Workaround a PHP bug: sometimes issuing a Notice if invoking current(somefunc())
+					$sExtKeyField = current($aCols); // get the first column for an external key
 
 					// Note: a class/table may have an external key on itself
 					$sSelBase = "SELECT DISTINCT maintable.`$sKeyField` AS id, maintable.`$sExtKeyField` AS extkey FROM `$sTable` AS maintable LEFT JOIN `$sRemoteTable` ON maintable.`$sExtKeyField` = `$sRemoteTable`.`$sRemoteKey`";
@@ -3038,7 +3040,8 @@ abstract class MetaModel
 					{
 						$sExpectedValues = implode(",", CMDBSource::Quote(array_keys($aAllowedValues), true));
 	
-						$sMyAttributeField = current($oAttDef->GetSQLExpressions()); // get the first column for the moment
+						$aCols = $oKeyAttDef->GetSQLExpressions(); // Workaround a PHP bug: sometimes issuing a Notice if invoking current(somefunc())
+						$sMyAttributeField = current($aCols); // get the first column for the moment
 						$sDefaultValue = $oAttDef->GetDefaultValue();
 						$sSelWrongRecs = "SELECT DISTINCT maintable.`$sKeyField` AS id FROM `$sTable` AS maintable WHERE maintable.`$sMyAttributeField` NOT IN ($sExpectedValues)";
 						self::DBCheckIntegrity_Check2Update($sSelWrongRecs, "Record having a column ('<em>$sAttCode</em>') with an unexpected value", $sMyAttributeField, CMDBSource::Quote($sDefaultValue), $sClass, $aErrorsAndFixes, $iNewDelCount, $aPlannedDel);

+ 35 - 19
pages/UI.php

@@ -1395,8 +1395,10 @@ EOF
 		}
 	}
 	$oKPI->ComputeAndReport('GUI creation before output');
+
 	ExecutionKPI::ReportStats();
-	////MetaModel::ShowQueryTrace();
+	MetaModel::ShowQueryTrace();
+
 	$oP->output();
 }
 catch(CoreException $e)
@@ -1411,15 +1413,22 @@ catch(CoreException $e)
 	{
 		if (MetaModel::IsValidClass('EventIssue'))
 		{
-			$oLog = new EventIssue();
-
-			$oLog->Set('message', $e->getMessage());
-			$oLog->Set('userinfo', '');
-			$oLog->Set('issue', $e->GetIssue());
-			$oLog->Set('impact', 'Page could not be displayed');
-			$oLog->Set('callstack', $e->getTrace());
-			$oLog->Set('data', $e->getContextData());
-			$oLog->DBInsertNoReload();
+			try
+			{
+				$oLog = new EventIssue();
+	
+				$oLog->Set('message', $e->getMessage());
+				$oLog->Set('userinfo', '');
+				$oLog->Set('issue', $e->GetIssue());
+				$oLog->Set('impact', 'Page could not be displayed');
+				$oLog->Set('callstack', $e->getTrace());
+				$oLog->Set('data', $e->getContextData());
+				$oLog->DBInsertNoReload();
+			}
+			catch(Exception $e)
+			{
+				IssueLog::Error("Failed to log issue into the DB");
+			}
 		}
 
 		IssueLog::Error($e->getMessage());
@@ -1440,15 +1449,22 @@ catch(Exception $e)
 	{
 		if (MetaModel::IsValidClass('EventIssue'))
 		{
-			$oLog = new EventIssue();
-
-			$oLog->Set('message', $e->getMessage());
-			$oLog->Set('userinfo', '');
-			$oLog->Set('issue', 'PHP Exception');
-			$oLog->Set('impact', 'Page could not be displayed');
-			$oLog->Set('callstack', $e->getTrace());
-			$oLog->Set('data', array());
-			$oLog->DBInsertNoReload();
+			try
+			{
+				$oLog = new EventIssue();
+	
+				$oLog->Set('message', $e->getMessage());
+				$oLog->Set('userinfo', '');
+				$oLog->Set('issue', 'PHP Exception');
+				$oLog->Set('impact', 'Page could not be displayed');
+				$oLog->Set('callstack', $e->getTrace());
+				$oLog->Set('data', array());
+				$oLog->DBInsertNoReload();
+			}
+			catch(Exception $e)
+			{
+				IssueLog::Error("Failed to log issue into the DB");
+			}
 		}
 
 		IssueLog::Error($e->getMessage());