From 0a5411d411c08dad00c4b3c3970f2121418b61ca Mon Sep 17 00:00:00 2001 From: acognet Date: Mon, 9 May 2022 10:53:53 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02363=20-=20API=20:=20deprecate=20old=20l?= =?UTF-8?q?inkedset=20update=20pattern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/loginwebpage.class.inc.php | 4 ---- application/wizardhelper.class.inc.php | 5 ++++- core/dbobject.class.php | 29 ++++++++------------------ core/ormlinkset.class.inc.php | 3 +-- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/application/loginwebpage.class.inc.php b/application/loginwebpage.class.inc.php index 9f0735784..2a1eb406b 100644 --- a/application/loginwebpage.class.inc.php +++ b/application/loginwebpage.class.inc.php @@ -131,10 +131,6 @@ class LoginWebPage extends NiceWebPage //add profiles not already linked with user foreach ($aProfiles as $iProfileId) { - $oLink = new URP_UserProfile(); - $oLink->Set('profileid', $iProfileId); - $oLink->Set('reason', $sOrigin); - $oProfilesSet->AddItem(MetaModel::NewObject('URP_UserProfile', array('profileid' => $iProfileId, 'reason' => $sOrigin))); } $oUser->Set('profile_list', $oProfilesSet); diff --git a/application/wizardhelper.class.inc.php b/application/wizardhelper.class.inc.php index 998386eaf..1d145203a 100644 --- a/application/wizardhelper.class.inc.php +++ b/application/wizardhelper.class.inc.php @@ -358,7 +358,10 @@ class WizardHelper {$sWizardHelperJsVar}.UpdateFields(); JS; } - +/* + * Function with an old pattern of code + * @deprecated since 3.1 +*/ static function ParseJsonSet($oMe, $sLinkClass, $sExtKeyToMe, $sJsonSet) { $aSet = json_decode($sJsonSet, true); // true means hash array instead of object diff --git a/core/dbobject.class.php b/core/dbobject.class.php index e973be870..89adc3165 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -5209,45 +5209,34 @@ abstract class DBObject implements iDisplay if ($sSourceAttCode == 'id') { $oSourceAttDef = null; - } - else - { - if (!MetaModel::IsValidAttCode(get_class($this), $sDestAttCode)) - { + } else { + if (!MetaModel::IsValidAttCode(get_class($this), $sDestAttCode)) { throw new Exception("Unknown attribute ".get_class($this)."::".$sDestAttCode); } - if (!MetaModel::IsValidAttCode(get_class($oSourceObject), $sSourceAttCode)) - { + if (!MetaModel::IsValidAttCode(get_class($oSourceObject), $sSourceAttCode)) { throw new Exception("Unknown attribute ".get_class($oSourceObject)."::".$sSourceAttCode); } $oSourceAttDef = MetaModel::GetAttributeDef(get_class($oSourceObject), $sSourceAttCode); } - if (is_object($oSourceAttDef) && $oSourceAttDef->IsLinkSet()) - { + if (is_object($oSourceAttDef) && $oSourceAttDef->IsLinkSet()) { // The copy requires that we create a new object set (the semantic of DBObject::Set is unclear about link sets) /** @var \AttributeLinkedSet $oSourceAttDef */ - $oDestSet = DBObjectSet::FromScratch($oSourceAttDef->GetLinkedClass()); + $oDestSet = $this->Get($sDestAttCode); $oSourceSet = $oSourceObject->Get($sSourceAttCode); $oSourceSet->Rewind(); /** @var \DBObject $oSourceLink */ - while ($oSourceLink = $oSourceSet->Fetch()) - { + while ($oSourceLink = $oSourceSet->Fetch()) { // Clone the link $sLinkClass = get_class($oSourceLink); $oLinkClone = MetaModel::NewObject($sLinkClass); - foreach(MetaModel::ListAttributeDefs($sLinkClass) as $sAttCode => $oAttDef) - { + foreach (MetaModel::ListAttributeDefs($sLinkClass) as $sAttCode => $oAttDef) { // As of now, ignore other attribute (do not attempt to recurse!) - if ($oAttDef->IsScalar() && $oAttDef->IsWritable()) - { + if ($oAttDef->IsScalar() && $oAttDef->IsWritable()) { $oLinkClone->Set($sAttCode, $oSourceLink->Get($sAttCode)); } } - - // Not necessary - this will be handled by DBObject - // $oLinkClone->Set($oSourceAttDef->GetExtKeyToMe(), 0); - $oDestSet->AddObject($oLinkClone); + $oDestSet->AddItem($oLinkClone); } $this->Set($sDestAttCode, $oDestSet); } diff --git a/core/ormlinkset.class.inc.php b/core/ormlinkset.class.inc.php index 43d433c12..caa5be16c 100644 --- a/core/ormlinkset.class.inc.php +++ b/core/ormlinkset.class.inc.php @@ -153,8 +153,7 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator */ public function AddObject(DBObject $oObject, $sClassAlias = '') { - // cannot notify depreciation for now as this is still MASSIVELY used in iTop core ! - //DeprecatedCallsLog::NotifyDeprecatedPhpMethod('use \ormLinkSet::AddItem() instead'); + DeprecatedCallsLog::NotifyDeprecatedPhpMethod('use \ormLinkSet::AddItem() instead'); $this->AddItem($oObject); }