From 3fa354d00d2690e033b0d1cb0924c501721fe044 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Fri, 14 Nov 2014 10:43:24 +0000 Subject: [PATCH] Predefined objects are now handled by RuntimeEnvironment SVN:trunk[3418] --- setup/applicationinstaller.class.inc.php | 47 +-------------------- setup/runtimeenv.class.inc.php | 53 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/setup/applicationinstaller.class.inc.php b/setup/applicationinstaller.class.inc.php index 4a8b0a867..17e7f07bd 100644 --- a/setup/applicationinstaller.class.inc.php +++ b/setup/applicationinstaller.class.inc.php @@ -742,52 +742,7 @@ class ApplicationInstaller } } - // Constant classes (e.g. User profiles) - // - foreach (MetaModel::GetClasses() as $sClass) - { - $aPredefinedObjects = call_user_func(array($sClass, 'GetPredefinedObjects')); - if ($aPredefinedObjects != null) - { - SetupPage::log_info("$sClass::GetPredefinedObjects() returned ".count($aPredefinedObjects)." elements."); - - // Create/Delete/Update objects of this class, - // according to the given constant values - // - $aDBIds = array(); - $oAll = new DBObjectSet(new DBObjectSearch($sClass)); - while ($oObj = $oAll->Fetch()) - { - if (array_key_exists($oObj->GetKey(), $aPredefinedObjects)) - { - $aObjValues = $aPredefinedObjects[$oObj->GetKey()]; - foreach ($aObjValues as $sAttCode => $value) - { - $oObj->Set($sAttCode, $value); - } - $oObj->DBUpdate(); - $aDBIds[$oObj->GetKey()] = true; - } - else - { - $oObj->DBDelete(); - } - } - foreach ($aPredefinedObjects as $iRefId => $aObjValues) - { - if (!array_key_exists($iRefId, $aDBIds)) - { - $oNewObj = MetaModel::NewObject($sClass); - $oNewObj->SetKey($iRefId); - foreach ($aObjValues as $sAttCode => $value) - { - $oNewObj->Set($sAttCode, $value); - } - $oNewObj->DBInsert(); - } - } - } - } + $oProductionEnv->UpdatePredefinedObjects(); if($sMode == 'install') { diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php index 018b8a48b..1155afe4c 100644 --- a/setup/runtimeenv.class.inc.php +++ b/setup/runtimeenv.class.inc.php @@ -458,6 +458,59 @@ class RunTimeEnvironment } } return true; + } + + public function UpdatePredefinedObjects() + { + // Constant classes (e.g. User profiles) + // + foreach (MetaModel::GetClasses() as $sClass) + { + $aPredefinedObjects = call_user_func(array( + $sClass, + 'GetPredefinedObjects' + )); + if ($aPredefinedObjects != null) + { + $this->log_info("$sClass::GetPredefinedObjects() returned " . count($aPredefinedObjects) . " elements."); + + // Create/Delete/Update objects of this class, + // according to the given constant values + // + $aDBIds = array(); + $oAll = new DBObjectSet(new DBObjectSearch($sClass)); + while ($oObj = $oAll->Fetch()) + { + if (array_key_exists($oObj->GetKey(), $aPredefinedObjects)) + { + $aObjValues = $aPredefinedObjects[$oObj->GetKey()]; + foreach ($aObjValues as $sAttCode => $value) + { + $oObj->Set($sAttCode, $value); + } + $oObj->DBUpdate(); + $aDBIds[$oObj->GetKey()] = true; + } + else + { + $oObj->DBDelete(); + } + } + foreach ($aPredefinedObjects as $iRefId => $aObjValues) + { + if (! array_key_exists($iRefId, $aDBIds)) + { + $oNewObj = MetaModel::NewObject($sClass); + $oNewObj->SetKey($iRefId); + foreach ($aObjValues as $sAttCode => $value) + { + $oNewObj->Set($sAttCode, $value); + } + $oNewObj->DBInsert(); + } + } + } + } } public function RecordInstallation(Config $oConfig, $sDataModelVersion, $aSelectedModules, $sModulesRelativePath)