diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 3d097b1ab..9412add37 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -35,6 +35,7 @@ abstract class DBObject private $m_aCurrValues = array(); protected $m_aOrigValues = array(); + private $m_bDirty = false; // The object may have incorrect external keys, then any attempt of reload must be avoided private $m_bFullyLoaded = false; // Compound objects can be partially loaded private $m_aLoadedAtt = array(); // Compound objects can be partially loaded, array of sAttCode @@ -71,6 +72,13 @@ abstract class DBObject } } + public function RegisterAsDirty() + { + // While the object may be written to the DB, it is NOT possible to reload it + // or at least not possible to reload it the same way + $this->m_bDirty = true; + } + public function IsNew() { return (!$this->m_bIsInDB); @@ -228,7 +236,7 @@ abstract class DBObject throw new CoreException("Unknown attribute code '$sAttCode' for the class ".get_class($this)); } $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); - if ($this->m_bIsInDB && !$this->m_bFullyLoaded) + if ($this->m_bIsInDB && !$this->m_bFullyLoaded && !$this->m_bDirty) { // First time Set is called... ensure that the object gets fully loaded // Otherwise we would lose the values on a further Reload diff --git a/setup/ajax.dataloader.php b/setup/ajax.dataloader.php index bc8f75f61..17f899a5e 100644 --- a/setup/ajax.dataloader.php +++ b/setup/ajax.dataloader.php @@ -19,6 +19,7 @@ define('TMP_CONFIG_FILE', '../tmp-config-itop.php'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Fri, 17 Jul 1970 05:00:00 GMT"); // Date in the past + /** * Main program */ @@ -26,6 +27,7 @@ $sFileName = Utils::ReadParam('file', ''); $sSessionStatus = Utils::ReadParam('session_status', ''); $iPercent = (integer)Utils::ReadParam('percent', 0); setup_web_page::log("Info - Loading file: $sFileName"); + try { if (empty($sFileName) || !file_exists($sFileName)) @@ -40,25 +42,26 @@ try $oChange->Set("date", time()); $oChange->Set("userinfo", "Initialization"); $iChangeId = $oChange->DBInsert(); + setup_web_page::log("Info - starting data load session"); $oDataLoader->StartSession($oChange); } $oDataLoader->LoadFile($sFileName); + $sResult = sprintf("Info - loading of %s done. (Overall %d %% completed).", basename($sFileName), $iPercent); + echo $sResult; + setup_web_page::log($sResult); if ($sSessionStatus == 'end') { $oDataLoader->EndSession(); + setup_web_page::log("Info - ending data load session"); } - $sResult = sprintf("Info - loading of %s done. (Overall %d %% completed).", basename($sFileName), $iPercent); - echo $sResult; - setup_web_page::log($sResult); } catch(Exception $e) { echo "
An error happened while loading the data
\n"; echo ''.$e."
\n"; setup_web_page::log("Error - An error happened while loading the data. ".$e); - } ?> diff --git a/setup/data/99.contactteam.xml b/setup/data/90.contactteam.xml similarity index 100% rename from setup/data/99.contactteam.xml rename to setup/data/90.contactteam.xml diff --git a/setup/data/100.contactobject.xml b/setup/data/91.contactobject.xml similarity index 100% rename from setup/data/100.contactobject.xml rename to setup/data/91.contactobject.xml diff --git a/setup/data/101.infragroup.xml b/setup/data/92.infragroup.xml similarity index 100% rename from setup/data/101.infragroup.xml rename to setup/data/92.infragroup.xml diff --git a/setup/xmldataloader.class.inc.php b/setup/xmldataloader.class.inc.php index f4149aa41..ab11bbf12 100644 --- a/setup/xmldataloader.class.inc.php +++ b/setup/xmldataloader.class.inc.php @@ -9,7 +9,7 @@ define ('KEYS_CACHE_FILE', '../keyscache.tmp'); * $oLoader->LoadFile('./organizations.xml'); * $oLoader->LoadFile('./locations.xml'); * $oLoader->EndSession(); - */ + */ class XMLDataLoader { protected $m_aKeys; @@ -32,6 +32,9 @@ class XMLDataLoader public function StartSession($oChange) { + // Do cleanup any existing cache file (shall not be necessary unless a setup was interrupted abruptely) + $this->ClearKeysCache(); + $this->m_oChange = $oChange; $this->m_bSessionActive = true; } @@ -91,7 +94,7 @@ class XMLDataLoader } else { - echo "Error: Cannot write to file: '{$this->m_sCacheFileName}'!
"; + throw new Exception("Cannot write to file: '{$this->m_sCacheFileName}'"); } } @@ -158,10 +161,12 @@ class XMLDataLoader if ($oAttDef->IsExternalKey()) { $iDstObj = (integer)($oXmlObj->$sAttCode); + // Attempt to find the object in the list of loaded objects $iExtKey = $this->GetObjectKey($oAttDef->GetTargetClass(), $iDstObj); if ($iExtKey == 0) { $iExtKey = -$iDstObj; // Convention: Unresolved keys are stored as negative ! + $oTargetObj->RegisterAsDirty(); } // tested by Romain, little impact on perf (not significant on the intial setup) //$oTargetObj->CheckValue($sAttCode, $iExtKey); @@ -240,12 +245,17 @@ class XMLDataLoader { if ( ($oAttDef->IsExternalKey()) && ($oTargetObj->Get($sAttCode) < 0) ) // Convention unresolved key = negative { - $iExtKey = $this->GetObjectKey($oAttDef->GetTargetClass(), -$oTargetObj->Get($sAttCode)); + $sTargetClass = $oAttDef->GetTargetClass(); + $iTempKey = $oTargetObj->Get($sAttCode); + + $iExtKey = $this->GetObjectKey($sTargetClass, -$iTempKey); if ($iExtKey == 0) { - echo "Warning: unresolved extkey in $sClass::".$oTargetObj->GetName()."(".$oTargetObj->GetKey().")::$sAttCode=".$oAttDef->GetTargetClass()."[".$oTargetObj->Get($sAttCode)."]aKeys[".$oAttDef->GetTargetClass()."]:\n";
- print_r($this->m_aKeys[$oAttDef->GetTargetClass()]);
+ $sMsg = "unresolved extkey in $sClass::".$oTargetObj->GetName()."(".$oTargetObj->GetKey().")::$sAttCode=$sTargetClass[$iTempKey]";
+ setup_web_page::log("Warning - $sMsg");
+ echo "Warning: $sMsg
\n";
+ echo "aKeys[".$sTargetClass."]:\n";
+ print_r($this->m_aKeys[$sTargetClass]);
echo "
\n";
}
else