Przeglądaj źródła

- Setup tested under IE8
- Added migration code, during the setup, for the hierarchical keys

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1358 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 14 lat temu
rodzic
commit
e4365b6a3d
4 zmienionych plików z 52 dodań i 13 usunięć
  1. 45 8
      core/metamodel.class.php
  2. 4 4
      setup/index.php
  3. 1 1
      setup/setup.js
  4. 2 0
      setup/setuppage.class.inc.php

+ 45 - 8
core/metamodel.class.php

@@ -2596,29 +2596,66 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
 	}
 
 	/**
+	 * Check (and updates if needed) the hierarchical keys
+	 * @param $bForceComputation boolean If true, the _left and _right parameters will be recomputed even if some values already exist in the DB	 
+	 */	 	
+	public static function CheckHKeys($bForceComputation = false)
+	{
+		foreach (self::GetClasses() as $sClass)
+		{
+			if (!self::HasTable($sClass)) continue;
+
+			foreach(self::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
+			{
+				// Check (once) all the attributes that are hierarchical keys
+				if((self::GetAttributeOrigin($sClass, $sAttCode) == $sClass) && $oAttDef->IsHierarchicalKey())
+				{
+					self::HKInit($sClass, $sAttCode, $bForceComputation);
+				}
+			}
+		}
+	}
+
+	/**
 	 * Initializes (i.e converts) a hierarchy stored using a 'parent_id' external key
 	 * into a hierarchy stored with a HierarchicalKey, by initializing the _left and _right values
 	 * to correspond to the existing hierarchy in the database
 	 * @param $sClass string Name of the class to process
 	 * @param $sAttCode string Code of the attribute to process
+	 * @param $bForceComputation boolean If true, the _left and _right parameters will be recomputed even if some values already exist in the DB	 
 	 */
-	public static function HKInit($sClass, $sAttCode)
+	public static function HKInit($sClass, $sAttCode, $bForceComputation = false)
 	{
 		$idx = 1;
+		$bUpdateNeeded = $bForceComputation;
 		$oAttDef = self::GetAttributeDef($sClass, $sAttCode);
 		$sTable = self::DBGetTable($sClass, $sAttCode);
 		if ($oAttDef->IsHierarchicalKey())
 		{
-			try
+			if (!$bForceComputation)
 			{
-				CMDBSource::Query('START TRANSACTION');
-				self::HKInitChildren($sTable, $sAttCode, $oAttDef, 0, $idx);
-				CMDBSource::Query('COMMIT');
+				// Check if some values already exist in the table for the _right value, if so, do nothing
+				$sRight = $oAttDef->GetSQLRight();
+				$sSQL = "SELECT MAX(`$sRight`) AS MaxRight FROM `$sTable`";
+				$iMaxRight = CMDBSource::QueryToScalar($sSQL);
+				if ($iMaxRight == 0)
+				{
+					$bUpdateNeeded = true;
+				}
 			}
-			catch(Exception $e)
+			if ($bUpdateNeeded)
 			{
-				CMDBSource::Query('ROLLBACK');
-				throw new Exception("An error occured (".$e->getMessage().") while initializing the hierarchy for ($sClass, $sAttCode). The database was not modified.");
+				try
+				{
+					CMDBSource::Query('START TRANSACTION');
+					self::HKInitChildren($sTable, $sAttCode, $oAttDef, 0, $idx);
+					CMDBSource::Query('COMMIT');
+				}
+				catch(Exception $e)
+				{
+					CMDBSource::Query('ROLLBACK');
+					throw new Exception("An error occured (".$e->getMessage().") while initializing the hierarchy for ($sClass, $sAttCode). The database was not modified.");
+				}
 			}
 		}
 	}

+ 4 - 4
setup/index.php

@@ -1229,12 +1229,12 @@ function DisplaySummary(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $
 		$oP->add('</div>');
 		
 		$oP->add("<form id=\"theForm\" method=\"post\">\n");
-		$oP->add("<input type=\"hidden\" name=\"operation\" value=\"step8\">\n");
+		$oP->add("<input type=\"hidden\" name=\"operation\" value=\"step9\">\n");
 		AddParamsToForm($oP, $aParamValues);
 		$oP->add("<table style=\"width:100%\"><tr>\n");
 		$oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"return DoGoBack(7)\"><< Back</button></td>\n");
 		// Note: the Next >> button is NOT a submit, since moving to the next page is triggered asynchronously
-		$oP->add("<td style=\"text-align:right;\"><button type=\"button\" onClick=\"DoSubmit('Installing...', 9)\"> Install ! >></button></td>\n");
+		$oP->add("<td style=\"text-align:right;\"><button type=\"button\" onClick=\"DoSubmit('Installing...', 8)\"> Install ! </button></td>\n");
 		$oP->add("</tr></table>\n");
 		$oP->add("</form>\n");
 		break;
@@ -1342,7 +1342,7 @@ function DisplaySummary(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $
 		$oP->add("<table style=\"width:100%\"><tr>\n");
 		$oP->add("<td style=\"text-align:left;\"><button type=\"button\" onClick=\"DoGoBack(6)\"><< Back</button></td>\n");
 		// Note: the Next >> button is NOT a submit, since moving to the next page is triggered asynchronously
-		$oP->add("<td style=\"text-align:right;\"><button type=\"button\" onClick=\"DoSubmit('', 7)\"> Upgrade ! >></button></td>\n");
+		$oP->add("<td style=\"text-align:right;\"><button type=\"button\" onClick=\"DoSubmit('', 8)\"> Upgrade ! </button></td>\n");
 		$oP->add("</tr></table>\n");
 		$oP->add("</form>\n");
 		break;
@@ -1354,7 +1354,7 @@ function DisplaySummary(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $
 	// have been processed
 	$oP->add("<form id=\"GoToNextStep\" method=\"post\">\n");
 	AddParamsToForm($oP, $aParamValues);
-	$oP->add("<input type=\"hidden\" name=\"operation\" value=\"step8\">\n");
+	$oP->add("<input type=\"hidden\" name=\"operation\" value=\"step9\">\n");
 	$oP->add("</form>\n");
 	
 	$oP->add("<div id=\"log\" style=\"color:#F00;\"></div>\n");

+ 1 - 1
setup/setup.js

@@ -289,7 +289,7 @@ function LoadNextDataFile(response, status, xhr)
 		{
 			// We're done
 			$("#progress").progression({ Current: 100, Maximum: 100, aBackgroundImg: 'orange-progress.gif', aTextColor: '#000000' });
-			$('#setup').unblock();
+			//$('#setup').unblock();
 			$('#GoToNextStep').submit(); // Use the hidden form to navigate to the next step
 		}
 	}

+ 2 - 0
setup/setuppage.class.inc.php

@@ -676,6 +676,8 @@ function CreateDatabaseStructure(Config $oConfig, $aSelectedModules, $sMode)
 		{
 			MetaModel::DBCreate();
 			SetupWebPage::log_ok("Database structure successfully created.");
+			// Check (and update only if it seems needed) the hierarchical keys
+			MetaModel::CheckHKeys(false /* bForceUpdate */);
 		}
 		else
 		{