mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
- Setup tested under IE8
- Added migration code, during the setup, for the hierarchical keys SVN:trunk[1358]
This commit is contained in:
@@ -2595,30 +2595,67 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
|
||||
CMDBSource::Query($sSQL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user