浏览代码

Enhanced reporting during the setup: all the queries (create table / alter table) are now logged into "setup.log" along with their execution time.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3446 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 10 年之前
父节点
当前提交
d5bdd2d45f
共有 2 个文件被更改,包括 23 次插入5 次删除
  1. 9 3
      core/metamodel.class.php
  2. 14 2
      setup/runtimeenv.class.inc.php

+ 9 - 3
core/metamodel.class.php

@@ -3801,7 +3801,7 @@ abstract class MetaModel
 	}
 
 
-	public static function DBCreate()
+	public static function DBCreate($aCallback = null)
 	{
 		// Note: we have to check if the DB does exist, because we may share the DB
 		//       with other applications (in which case the DB does exist, not the tables with the given prefix)
@@ -3809,18 +3809,24 @@ abstract class MetaModel
 		{
 			CMDBSource::CreateDB(self::$m_sDBName);
 		}
-		self::DBCreateTables();
+		self::DBCreateTables($aCallback);
 		self::DBCreateViews();
 	}
 
-	protected static function DBCreateTables()
+	protected static function DBCreateTables($aCallback = null)
 	{
 		list($aErrors, $aSugFix, $aCondensedQueries) = self::DBCheckFormat();
 
 		//$sSQL = implode('; ', $aCondensedQueries); Does not work - multiple queries not allowed
 		foreach($aCondensedQueries as $sQuery)
 		{
+			$fStart = microtime(true);
 			CMDBSource::CreateTable($sQuery);
+			$fDuration = microtime(true) - $fStart;
+			if ($aCallback != null)
+			{
+				call_user_func($aCallback, $sQuery, $fDuration);
+			}
 		}
 	}
 

+ 14 - 2
setup/runtimeenv.class.inc.php

@@ -47,6 +47,18 @@ class RunTimeEnvironment
 	}
 
 	/**
+	 * Callback function for logging the queries run by the setup.
+	 * According to the documentation the function must be defined before passing it to call_user_func...
+	 * @param string $sQuery
+	 * @param float $fDuration
+	 * @return void
+	 */
+	public function LogQueryCallback($sQuery, $fDuration)
+	{
+		$this->log_info(sprintf('%.3fs - query: %s ', $fDuration, $sQuery));
+	}
+	
+	/**
 	 * Helper function to initialize the ORM and load the data model
 	 * from the given file
 	 * @param $oConfig object The configuration (volatile, not necessarily already on disk)
@@ -411,7 +423,7 @@ class RunTimeEnvironment
 		{
 			if (!MetaModel::DBExists(/* bMustBeComplete */ false))
 			{
-				MetaModel::DBCreate();
+				MetaModel::DBCreate(array($this, 'LogQueryCallback'));
 				$this->log_ok("Database structure successfully created.");
 			}
 			else
@@ -430,7 +442,7 @@ class RunTimeEnvironment
 		{
 			if (MetaModel::DBExists(/* bMustBeComplete */ false))
 			{
-				MetaModel::DBCreate();
+				MetaModel::DBCreate(array($this, 'LogQueryCallback'));
 				$this->log_ok("Database structure successfully updated.");
 	
 				// Check (and update only if it seems needed) the hierarchical keys