From 24eb82d1409eb6dae9b44f9d7c099aadbf517061 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Fri, 15 Nov 2019 17:37:04 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B02361=20Deprecate=20DB*Tracked=20methods?= =?UTF-8?q?=20*=20update=20methods=20PHPDoc=20*=20DBInsertTracked=20update?= =?UTF-8?q?=20callers=20*=20DBInsertTrackedNoReload=20update=20callers=20*?= =?UTF-8?q?=20DBUpdateTracked=20update=20callers=20*=20DBDeleteTracked=20u?= =?UTF-8?q?pdate=20callers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../userrights/userrightsmatrix.class.inc.php | 5 +- .../userrightsprofile.class.inc.php | 10 +- .../userrightsprofile.db.class.inc.php | 13 +-- .../userrightsprojection.class.inc.php | 29 ++---- application/cmdbabstract.class.inc.php | 2 +- application/loginwebpage.class.inc.php | 19 +--- core/bulkchange.class.inc.php | 35 +++++-- core/cmdbobject.class.inc.php | 97 +++++++++++++++++-- core/dbobject.class.php | 22 +++-- core/ormstopwatch.class.inc.php | 5 +- .../2.x/authent-cas/src/CASLoginExtension.php | 14 +-- .../2.x/authent-local/model.authent-local.php | 14 ++- .../2.x/itop-tickets/module.itop-tickets.php | 4 +- setup/xmldataloader.class.inc.php | 13 +-- synchro/synchrodatasource.class.inc.php | 50 ++++++---- test/benchmark.php | 5 +- test/test.class.inc.php | 34 +------ test/testlist.inc.php | 53 +++++----- webservices/createfrommail.php | 4 +- webservices/webservices.basic.php | 3 +- webservices/webservices.class.inc.php | 18 +++- 21 files changed, 260 insertions(+), 189 deletions(-) diff --git a/addons/userrights/userrightsmatrix.class.inc.php b/addons/userrights/userrightsmatrix.class.inc.php index f9949477a..732516f8f 100644 --- a/addons/userrights/userrightsmatrix.class.inc.php +++ b/addons/userrights/userrightsmatrix.class.inc.php @@ -128,13 +128,14 @@ class UserRightsMatrix extends UserRightsAddOnAPI $oUser->Set('language', $sLanguage); // Language was chosen during the installation // Create a change to record the history of the User object + /** @var \CMDBChange $oChange */ $oChange = MetaModel::NewObject("CMDBChange"); $oChange->Set("date", time()); $oChange->Set("userinfo", "Initialization"); - $iChangeId = $oChange->DBInsert(); // Now record the admin user object - $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true /* skip security */); + $oUser::SetCurrentChange($oChange); + $iUserId = $oUser->DBInsertNoReload(); $this->SetupUser($iUserId, true); return true; } diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index a4cee533f..3650f6f17 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -437,8 +437,6 @@ class UserRightsProfile extends UserRightsAddOnAPI { CMDBObject::SetTrackInfo('Initialization'); - $oChange = CMDBObject::GetCurrentChange(); - $iContactId = 0; // Support drastic data model changes: no organization class (or not writable)! if (MetaModel::IsValidClass('Organization') && !MetaModel::IsAbstract('Organization')) @@ -446,7 +444,7 @@ class UserRightsProfile extends UserRightsAddOnAPI $oOrg = new Organization(); $oOrg->Set('name', 'My Company/Department'); $oOrg->Set('code', 'SOMECODE'); - $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange, true /* skip security */); + $iOrgId = $oOrg->DBInsertNoReload(); // Support drastic data model changes: no Person class (or not writable)! if (MetaModel::IsValidClass('Person') && !MetaModel::IsAbstract('Person')) @@ -463,7 +461,7 @@ class UserRightsProfile extends UserRightsAddOnAPI $oContact->Set('phone', '+00 000 000 000'); } $oContact->Set('email', 'my.email@foo.org'); - $iContactId = $oContact->DBInsertTrackedNoReload($oChange, true /* skip security */); + $iContactId = $oContact->DBInsertNoReload(); } } @@ -482,14 +480,12 @@ class UserRightsProfile extends UserRightsAddOnAPI if (is_object($oAdminProfile)) { $oUserProfile = new URP_UserProfile(); - //$oUserProfile->Set('userid', $iUserId); $oUserProfile->Set('profileid', $oAdminProfile->GetKey()); $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile'); - //$oUserProfile->DBInsertTrackedNoReload($oChange, true /* skip security */); $oSet = DBObjectSet::FromObject($oUserProfile); $oUser->Set('profile_list', $oSet); } - $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true /* skip security */); + $iUserId = $oUser->DBInsertNoReload(); return true; } diff --git a/addons/userrights/userrightsprofile.db.class.inc.php b/addons/userrights/userrightsprofile.db.class.inc.php index 5183fa1f4..2fe22791d 100644 --- a/addons/userrights/userrightsprofile.db.class.inc.php +++ b/addons/userrights/userrightsprofile.db.class.inc.php @@ -533,10 +533,10 @@ class UserRightsProfile extends UserRightsAddOnAPI public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US') { // Create a change to record the history of the User object + /** @var \CMDBChange $oChange */ $oChange = MetaModel::NewObject("CMDBChange"); $oChange->Set("date", time()); $oChange->Set("userinfo", "Initialization"); - $iChangeId = $oChange->DBInsert(); $iContactId = 0; // Support drastic data model changes: no organization class (or not writable)! @@ -545,7 +545,8 @@ class UserRightsProfile extends UserRightsAddOnAPI $oOrg = new Organization(); $oOrg->Set('name', 'My Company/Department'); $oOrg->Set('code', 'SOMECODE'); - $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange, true /* skip security */); + $oOrg::SetCurrentChange($oChange); + $iOrgId = $oOrg->DBInsertNoReload(); // Support drastic data model changes: no Person class (or not writable)! if (MetaModel::IsValidClass('Person') && !MetaModel::IsAbstract('Person')) @@ -562,7 +563,8 @@ class UserRightsProfile extends UserRightsAddOnAPI $oContact->Set('phone', '+00 000 000 000'); } $oContact->Set('email', 'my.email@foo.org'); - $iContactId = $oContact->DBInsertTrackedNoReload($oChange, true /* skip security */); + $oContact::SetCurrentChange($oChange); + $iContactId = $oContact->DBInsertNoReload(); } } @@ -581,14 +583,13 @@ class UserRightsProfile extends UserRightsAddOnAPI if (is_object($oAdminProfile)) { $oUserProfile = new URP_UserProfile(); - //$oUserProfile->Set('userid', $iUserId); $oUserProfile->Set('profileid', $oAdminProfile->GetKey()); $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile'); - //$oUserProfile->DBInsertTrackedNoReload($oChange, true /* skip security */); $oSet = DBObjectSet::FromObject($oUserProfile); $oUser->Set('profile_list', $oSet); } - $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true /* skip security */); + $oUser::SetCurrentChange($oChange); + $iUserId = $oUser->DBInsertNoReload(); return true; } diff --git a/addons/userrights/userrightsprojection.class.inc.php b/addons/userrights/userrightsprojection.class.inc.php index 4e3fc0fa2..bf5e86944 100644 --- a/addons/userrights/userrightsprojection.class.inc.php +++ b/addons/userrights/userrightsprojection.class.inc.php @@ -593,25 +593,12 @@ class UserRightsProjection extends UserRightsAddOnAPI $oChange = MetaModel::NewObject("CMDBChange"); $oChange->Set("date", time()); $oChange->Set("userinfo", "Initialization"); - $iChangeId = $oChange->DBInsert(); $oOrg = new Organization(); $oOrg->Set('name', 'My Company/Department'); $oOrg->Set('code', 'SOMECODE'); -// $oOrg->Set('status', 'implementation'); - //$oOrg->Set('parent_id', xxx); - $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange, true /* skip strong security */); - - // Location : optional - //$oLocation = new bizLocation(); - //$oLocation->Set('name', 'MyOffice'); - //$oLocation->Set('status', 'implementation'); - //$oLocation->Set('org_id', $iOrgId); - //$oLocation->Set('severity', 'high'); - //$oLocation->Set('address', 'my building in my city'); - //$oLocation->Set('country', 'my country'); - //$oLocation->Set('parent_location_id', xxx); - //$iLocationId = $oLocation->DBInsertNoReload(); + $oOrg::SetCurrentChange($oChange); + $iOrgId = $oOrg->DBInsertNoReload(); $oContact = new Person(); $oContact->Set('name', 'My last name'); @@ -619,24 +606,24 @@ class UserRightsProjection extends UserRightsAddOnAPI //$oContact->Set('status', 'available'); $oContact->Set('org_id', $iOrgId); $oContact->Set('email', 'my.email@foo.org'); - //$oContact->Set('phone', ''); - //$oContact->Set('location_id', $iLocationId); - //$oContact->Set('employee_number', ''); - $iContactId = $oContact->DBInsertTrackedNoReload($oChange, true /* skip security */); + $oContact::SetCurrentChange($oChange); + $iContactId = $oContact->DBInsertNoReload(); $oUser = new UserLocal(); $oUser->Set('login', $sAdminUser); $oUser->Set('password', $sAdminPwd); $oUser->Set('contactid', $iContactId); $oUser->Set('language', $sLanguage); // Language was chosen during the installation - $iUserId = $oUser->DBInsertTrackedNoReload($oChange, true /* skip security */); + $oUser::SetCurrentChange($oChange); + $iUserId = $oUser->DBInsertNoReload(); // Add this user to the very specific 'admin' profile $oUserProfile = new URP_UserProfile(); $oUserProfile->Set('userid', $iUserId); $oUserProfile->Set('profileid', ADMIN_PROFILE_ID); $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile'); - $oUserProfile->DBInsertTrackedNoReload($oChange, true /* skip security */); + $oUserProfile::SetCurrentChange($oChange); + $oUserProfile->DBInsertNoReload(); return true; } diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 536eff996..20767828f 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -4453,7 +4453,7 @@ EOF } else { - $oObj->DBDeleteTracked(CMDBObject::GetCurrentChange(), null, $oDeletionPlan); + $oObj->DBDelete(); } } diff --git a/application/loginwebpage.class.inc.php b/application/loginwebpage.class.inc.php index 1b3986a6c..788bf6003 100644 --- a/application/loginwebpage.class.inc.php +++ b/application/loginwebpage.class.inc.php @@ -785,6 +785,7 @@ class LoginWebPage extends NiceWebPage $oPerson = null; try { + /** @var Person $oPerson */ $oPerson = MetaModel::NewObject('Person'); $oPerson->Set('first_name', $sFirstName); $oPerson->Set('name', $sLastName); @@ -808,8 +809,8 @@ class LoginWebPage extends NiceWebPage $sOrigin .= " ({$_SESSION['login_mode']})"; } $oMyChange->Set('userinfo', $sOrigin); - $oMyChange->DBInsert(); - $oPerson->DBInsertTracked($oMyChange); + $oPerson::SetCurrentChange($oMyChange); + $oPerson->DBInsert(); } catch (Exception $e) { @@ -891,19 +892,7 @@ class LoginWebPage extends NiceWebPage $oUser->Set('profile_list', $oProfilesSet); if ($oUser->IsModified()) { - /** @var \CMDBChange $oMyChange */ - $oMyChange = MetaModel::NewObject("CMDBChange"); - $oMyChange->Set("date", time()); - $oMyChange->Set('userinfo', $sOrigin); - $oMyChange->DBInsert(); - if ($oUser->IsNew()) - { - $oUser->DBInsertTracked($oMyChange); - } - else - { - $oUser->DBUpdateTracked($oMyChange); - } + $oUser->DBWrite(); } } catch (Exception $e) diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index 066e72b3f..fc6d1ce93 100644 --- a/core/bulkchange.class.inc.php +++ b/core/bulkchange.class.inc.php @@ -726,12 +726,13 @@ class BulkChange $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::Format('UI:CSVReport-Row-Issue-MissingExtKey', $sMissingKeys)); return $oTargetObj; } - - // Optionaly record the results + + // Optionally record the results // if ($oChange) { - $newID = $oTargetObj->DBInsertTrackedNoReload($oChange); + $oTargetObj::SetCurrentChange($oChange); + $newID = $oTargetObj->DBInsert(); $aResult[$iRow]["__STATUS__"] = new RowStatus_NewObj(); $aResult[$iRow]["finalclass"] = get_class($oTargetObj); $aResult[$iRow]["id"] = new CellStatus_Void($newID); @@ -744,7 +745,20 @@ class BulkChange } return $oTargetObj; } - + + /** + * @param array $aResult + * @param int $iRow + * @param \CMDBObject $oTargetObj + * @param array $aRowData + * @param \CMDBChange $oChange + * + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MissingQueryArgument + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + */ protected function UpdateObject(&$aResult, $iRow, $oTargetObj, $aRowData, CMDBChange $oChange = null) { $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors); @@ -772,7 +786,8 @@ class BulkChange { try { - $oTargetObj->DBUpdateTracked($oChange); + $oTargetObj::SetCurrentChange($oChange); + $oTargetObj->DBUpdate(); } catch(CoreException $e) { @@ -786,6 +801,14 @@ class BulkChange } } + /** + * @param array $aResult + * @param int $iRow + * @param \CMDBObject $oTargetObj + * @param \CMDBChange $oChange + * + * @throws \BulkChangeException + */ protected function UpdateMissingObject(&$aResult, $iRow, $oTargetObj, CMDBChange $oChange = null) { $aResult[$iRow] = $this->PrepareMissingObject($oTargetObj, $aErrors); @@ -813,7 +836,7 @@ class BulkChange { try { - $oTargetObj->DBUpdateTracked($oChange); + $oTargetObj->DBUpdate(); } catch(CoreException $e) { diff --git a/core/cmdbobject.class.inc.php b/core/cmdbobject.class.inc.php index fd145c222..76525316f 100644 --- a/core/cmdbobject.class.inc.php +++ b/core/cmdbobject.class.inc.php @@ -513,7 +513,23 @@ abstract class CMDBObject extends DBObject } } - + /** + * @deprecated 2.7.0 N°2361 simply use {@link DBInsert} instead, that will automatically create and persist a CMDBChange object. + * If you need to persist your own, call {@link CMDBObject::SetCurrentChange} before. + * + * @param \CMDBChange $oChange + * @param null $bSkipStrongSecurity + * + * @return int|null + * @throws \ArchivedObjectException + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \CoreWarning + * @throws \MySQLException + * @throws \OQLException + * @throws \SecurityException + */ public function DBInsertTracked(CMDBChange $oChange, $bSkipStrongSecurity = null) { self::SetCurrentChange($oChange); @@ -521,7 +537,24 @@ abstract class CMDBObject extends DBObject $ret = $this->DBInsertTracked_Internal(); return $ret; } - + + /** + * @deprecated 2.7.0 N°2361 simply use {@link DBInsertNoReload} instead, that will automatically create and persist a CMDBChange object. + * If you need to persist your own, call {@link CMDBObject::SetCurrentChange} before. + * + * @param \CMDBChange $oChange + * @param null $bSkipStrongSecurity + * + * @return int + * @throws \ArchivedObjectException + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \CoreWarning + * @throws \MySQLException + * @throws \OQLException + * @throws \SecurityException + */ public function DBInsertTrackedNoReload(CMDBChange $oChange, $bSkipStrongSecurity = null) { self::SetCurrentChange($oChange); @@ -529,13 +562,20 @@ abstract class CMDBObject extends DBObject $ret = $this->DBInsertTracked_Internal(true); return $ret; } - + /** - * To Be Obsoleted: DO NOT rely on an overload of this method since - * DBInsertTracked (resp. DBInsertTrackedNoReload) may call directly - * DBInsert (resp. DBInsertNoReload) in future versions of iTop. + * @deprecated 2.7.0 N°2361 simply use {@link DBInsert} or {@link DBInsertNoReload} instead + * * @param bool $bDoNotReload + * * @return integer Identifier of the created object + * @throws \ArchivedObjectException + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \CoreWarning + * @throws \MySQLException + * @throws \OQLException */ protected function DBInsertTracked_Internal($bDoNotReload = false) { @@ -582,6 +622,18 @@ abstract class CMDBObject extends DBObject return $ret; } + /** + * @deprecated 2.7.0 N°2361 simply use {@link DBUpdate} instead, that will automatically create and persist a CMDBChange object. + * If you need to persist your own, call {@link CMDBObject::SetCurrentChange} before. + * + * @param \CMDBChange $oChange + * @param null $bSkipStrongSecurity + * + * @return int|void + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \SecurityException + */ public function DBUpdateTracked(CMDBChange $oChange, $bSkipStrongSecurity = null) { self::SetCurrentChange($oChange); @@ -593,13 +645,38 @@ abstract class CMDBObject extends DBObject * @param null $oDeletionPlan * * @return \DeletionPlan|null + * @throws \ArchivedObjectException + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue * @throws \DeleteException + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + * @throws \OQLException */ public function DBDelete(&$oDeletionPlan = null) { return $this->DBDeleteTracked_Internal($oDeletionPlan); } + /** + * @deprecated 2.7.0 N°2361 simply use {@link DBDelete} instead, that will automatically create and persist a CMDBChange object. + * If you need to persist your own, call {@link CMDBObject::SetCurrentChange} before. + * + * @param \CMDBChange $oChange + * @param null $bSkipStrongSecurity + * @param null $oDeletionPlan + * + * @throws \ArchivedObjectException + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \DeleteException + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + * @throws \OQLException + * @throws \SecurityException + */ public function DBDeleteTracked(CMDBChange $oChange, $bSkipStrongSecurity = null, &$oDeletionPlan = null) { self::SetCurrentChange($oChange); @@ -611,11 +688,17 @@ abstract class CMDBObject extends DBObject * @param null $oDeletionPlan * * @return \DeletionPlan|null + * @throws \ArchivedObjectException + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue * @throws \DeleteException + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + * @throws \OQLException */ protected function DBDeleteTracked_Internal(&$oDeletionPlan = null) { - $prevkey = $this->GetKey(); $ret = parent::DBDelete($oDeletionPlan); return $ret; } diff --git a/core/dbobject.class.php b/core/dbobject.class.php index ed9fdd42c..3f97559b4 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -2925,16 +2925,13 @@ abstract class DBObject implements iDisplay /** * @internal * + * @deprecated 2.7.0 N°2361 simply use {@link DBInsert} instead, that will automatically create and persist a CMDBChange object. + * If you need to persist your own, call {@link CMDBObject::SetCurrentChange} before. + * * @param CMDBChange $oChange * * @return int|null - * @throws ArchivedObjectException - * @throws CoreCannotSaveObjectException * @throws CoreException - * @throws CoreUnexpectedValue - * @throws CoreWarning - * @throws MySQLException - * @throws OQLException */ public function DBInsertTracked(CMDBChange $oChange) { @@ -2945,6 +2942,9 @@ abstract class DBObject implements iDisplay /** * @internal * + * @deprecated 2.7.0 N°2361 simply use {@link DBInsertNoReload} instead, that will automatically create and persist a CMDBChange object. + * If you need to persist your own, call {@link CMDBObject::SetCurrentChange} before. + * * @param CMDBChange $oChange * * @return int @@ -3289,6 +3289,9 @@ abstract class DBObject implements iDisplay * * @internal * + * @deprecated 2.7.0 N°2361 simply use {@link DBUpdate} instead, that will automatically create and persist a CMDBChange object. + * If you need to persist your own, call {@link CMDBObject::SetCurrentChange} before. + * * @param CMDBChange $oChange * * @return int @@ -3558,9 +3561,12 @@ abstract class DBObject implements iDisplay /** * @internal * + * @deprecated 2.7.0 N°2361 simply use {@link DBDelete} instead. + * If you need to persist your own, call {@link CMDBObject::SetCurrentChange} before. + * * @param CMDBChange $oChange - * @param null $bSkipStrongSecurity - * @param null $oDeletionPlan + * @param boolean $bSkipStrongSecurity + * @param \DeletionPlan $oDeletionPlan * * @throws ArchivedObjectException * @throws CoreCannotSaveObjectException diff --git a/core/ormstopwatch.class.inc.php b/core/ormstopwatch.class.inc.php index 366cf8861..53184459f 100644 --- a/core/ormstopwatch.class.inc.php +++ b/core/ormstopwatch.class.inc.php @@ -590,9 +590,8 @@ class CheckStopWatchThresholds implements iBackgroundProcess if($oObj->IsModified()) { CMDBObject::SetTrackInfo("Automatic - threshold triggered"); - - $oMyChange = CMDBObject::GetCurrentChange(); - $oObj->DBUpdateTracked($oMyChange); + + $oObj->DBUpdate(); } // Activate any existing trigger diff --git a/datamodels/2.x/authent-cas/src/CASLoginExtension.php b/datamodels/2.x/authent-cas/src/CASLoginExtension.php index 4ec302be2..aee207670 100644 --- a/datamodels/2.x/authent-cas/src/CASLoginExtension.php +++ b/datamodels/2.x/authent-cas/src/CASLoginExtension.php @@ -510,19 +510,7 @@ class CASUserProvisioning phpCAS::log("Info: the user '".$oUser->GetName()."' (id=".$oUser->GetKey().") now has the following profiles: '".implode("', '", $aProfiles)."'."); if ($oUser->IsModified()) { - /** @var \CMDBChange $oMyChange */ - $oMyChange = MetaModel::NewObject("CMDBChange"); - $oMyChange->Set("date", time()); - $oMyChange->Set("userinfo", 'CAS/LDAP Synchro'); - $oMyChange->DBInsert(); - if ($oUser->IsNew()) - { - $oUser->DBInsertTracked($oMyChange); - } - else - { - $oUser->DBUpdateTracked($oMyChange); - } + $oUser->DBWrite(); } return true; diff --git a/datamodels/2.x/authent-local/model.authent-local.php b/datamodels/2.x/authent-local/model.authent-local.php index bde1214de..5b000b040 100755 --- a/datamodels/2.x/authent-local/model.authent-local.php +++ b/datamodels/2.x/authent-local/model.authent-local.php @@ -99,22 +99,20 @@ class UserLocal extends UserInternal public function SetPassword($sNewPassword) { $this->Set('password', $sNewPassword); - $oChange = MetaModel::NewObject("CMDBChange"); - $oChange->Set("date", time()); - $sUserString = CMDBChange::GetCurrentUserName(); - $oChange->Set("userinfo", $sUserString); - $oChange->DBInsert(); - $this->DBUpdateTracked($oChange, true); + $this->DBUpdate(); } /** * Returns the set of flags (OPT_ATT_HIDDEN, OPT_ATT_READONLY, OPT_ATT_MANDATORY...) * for the given attribute in the current state of the object + * * @param $sAttCode string $sAttCode The code of the attribute * @param $aReasons array To store the reasons why the attribute is read-only (info about the synchro replicas) - * @param $sTargetState string The target state in which to evalutate the flags, if empty the current state will be used + * @param $sTargetState string The target state in which to evaluate the flags, if empty the current state will be used + * * @return integer Flags: the binary combination of the flags applicable to this attribute - */ + * @throws \CoreException + */ public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '') { $iFlags = parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState); diff --git a/datamodels/2.x/itop-tickets/module.itop-tickets.php b/datamodels/2.x/itop-tickets/module.itop-tickets.php index 909684826..4821b9def 100755 --- a/datamodels/2.x/itop-tickets/module.itop-tickets.php +++ b/datamodels/2.x/itop-tickets/module.itop-tickets.php @@ -63,9 +63,9 @@ class TicketsInstaller extends ModuleInstallerAPI $oChange = new CMDBChange; $oChange->Set("date", time()); $oChange->Set("userinfo", "Uninstallation"); - $oChange->DBInsert(); } - $oTrigger->DBDeleteTracked($oChange); + $oTrigger::SetCurrentChange($oChange); + $oTrigger->DBDelete(); } } } diff --git a/setup/xmldataloader.class.inc.php b/setup/xmldataloader.class.inc.php index b5cd4c675..6a9e28e01 100644 --- a/setup/xmldataloader.class.inc.php +++ b/setup/xmldataloader.class.inc.php @@ -396,10 +396,14 @@ class XMLDataLoader protected function ResolveExternalKeys() { + /** + * @var string $sClass + * @var \CMDBObject[] $oObjList + */ foreach($this->m_aObjectsCache as $sClass => $oObjList) { foreach($oObjList as $oTargetObj) - { + { $bChanged = false; $sClass = get_class($oTargetObj); foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef) @@ -432,12 +436,9 @@ class XMLDataLoader { if (is_subclass_of($oTargetObj, 'CMDBObject')) { - $oTargetObj->DBUpdateTracked($this->m_oChange); - } - else - { - $oTargetObj->DBUpdate(); + $oTargetObj::SetCurrentChange($this->m_oChange); } + $oTargetObj->DBUpdate(); } catch(Exception $e) { diff --git a/synchro/synchrodatasource.class.inc.php b/synchro/synchrodatasource.class.inc.php index 948627267..cd084f260 100644 --- a/synchro/synchrodatasource.class.inc.php +++ b/synchro/synchrodatasource.class.inc.php @@ -2474,10 +2474,10 @@ class SynchroReplica extends DBObject implements iDisplay /** * Updates the destination object with the Extended data found in the synchro_data_XXXX table * - * @param $oDestObj + * @param \CMDBObject $oDestObj * @param string[] $aAttributes - * @param $oChange - * @param $oStatLog + * @param \CMDBChange $oChange + * @param \SynchroLog $oStatLog * @param string $sStatsCode * @param string $sStatsCodeError * @@ -2514,7 +2514,8 @@ class SynchroReplica extends DBObject implements iDisplay // Really modified ? if ($oDestObj->IsModified()) { - $oDestObj->DBUpdateTracked($oChange); + $oDestObj::SetCurrentChange($oChange); + $oDestObj->DBUpdate(); $bModified = true; $oStatLog->AddTrace('Updated object - Values: {'.implode(', ', $aValueTrace).'}', $this); if (($sStatsCode != '') && (MetaModel::IsValidAttCode(get_class($oStatLog), $sStatsCode.'_updated'))) @@ -2553,7 +2554,8 @@ class SynchroReplica extends DBObject implements iDisplay * @param $oChange * @param $oStatLog * - * @return bool Whether or not the object was created + * @return bool true if the object was created + * @throws \CoreException */ protected function CreateObjectFromReplica($sClass, $aAttributes, $oChange, &$oStatLog) { @@ -2571,7 +2573,8 @@ class SynchroReplica extends DBObject implements iDisplay $aValueTrace[] = "$sAttCode: $value"; } } - $iNew = $oDestObj->DBInsertTracked($oChange); + $oDestObj::SetCurrentChange($oChange); + $iNew = $oDestObj->DBInsert(); $this->Set('dest_id', $oDestObj->GetKey()); $this->Set('dest_class', get_class($oDestObj)); @@ -2612,6 +2615,7 @@ class SynchroReplica extends DBObject implements iDisplay } else { + /** @var \CMDBObject $oDestObj */ $oDestObj = MetaModel::GetObject($this->Get('dest_class'), $this->Get('dest_id')); foreach ($aValues as $sAttCode => $value) { @@ -2622,7 +2626,8 @@ class SynchroReplica extends DBObject implements iDisplay $oDestObj->Set($sAttCode, $value); } $this->Set('info_last_modified', date(AttributeDateTime::GetSQLFormat())); - $oDestObj->DBUpdateTracked($oChange); + $oDestObj::SetCurrentChange($oChange); + $oDestObj->DBUpdate(); $oStatLog->AddTrace('Replica marked as obsolete', $this); $oStatLog->Inc('stats_nb_obj_obsoleted'); } @@ -2639,6 +2644,15 @@ class SynchroReplica extends DBObject implements iDisplay * * @param CMDBChange $oChange * @param SynchroLog $oStatLog + * + * @throws \ArchivedObjectException + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \DeleteException + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + * @throws \OQLException */ public function DeleteDestObject($oChange, &$oStatLog) { @@ -2650,9 +2664,9 @@ class SynchroReplica extends DBObject implements iDisplay $oCheckDeletionPlan = new DeletionPlan(); if ($oDestObj->CheckToDelete($oCheckDeletionPlan)) { - $oActualDeletionPlan = new DeletionPlan(); - $oDestObj->DBDeleteTracked($oChange, null, $oActualDeletionPlan); - $this->DBDeleteTracked($oChange); + $oDestObj::SetCurrentChange($oChange); + $oDestObj->DBDelete(); + $this->DBDelete(); $oStatLog->Inc('stats_nb_obj_deleted'); } else @@ -2665,13 +2679,13 @@ class SynchroReplica extends DBObject implements iDisplay { $this->SetLastError('Unable to delete the destination object: ', $e); $this->Set('status', 'obsolete'); - $this->DBUpdateTracked($oChange); + $this->DBUpdate(); $oStatLog->Inc('stats_nb_obj_deleted_errors'); } } else { - $this->DBDeleteTracked($oChange); + $this->DBDelete(); $oStatLog->Inc('stats_nb_replica_disappeared_no_action'); } } @@ -3021,7 +3035,7 @@ class SynchroExecution $this->m_iCountAllReplicas = $oSetTotal->Count(); $this->m_oStatLog->Set('stats_nb_replica_total', $this->m_iCountAllReplicas); - $this->m_oStatLog->DBInsertTracked($this->m_oChange); + $this->m_oStatLog->DBInsert(); $sLastFullLoad = ($this->m_bIsImportPhaseDateKnown) ? $this->m_oImportPhaseStartDate->format('Y-m-d H:i:s') : 'not specified'; $this->m_oStatLog->AddTrace("###### STARTING SYNCHRONIZATION ##### Total: {$this->m_iCountAllReplicas} replica(s). Last full load: '$sLastFullLoad' "); $sSql = 'SELECT NOW();'; @@ -3190,7 +3204,7 @@ class SynchroExecution $this->m_oStatLog->Set('end_date', time()); $this->m_oStatLog->Set('status', 'completed'); - $this->m_oStatLog->DBUpdateTracked($this->m_oChange); + $this->m_oStatLog->DBUpdate(); $iErrors = $this->m_oStatLog->GetErrorCount(); if ($iErrors > 0) @@ -3234,7 +3248,7 @@ class SynchroExecution $this->m_oStatLog->Set('end_date', time()); $this->m_oStatLog->Set('status', 'error'); $this->m_oStatLog->Set('last_error', $e->getMessage()); - $this->m_oStatLog->DBDeleteTracked($this->m_oChange); + $this->m_oStatLog->DBDelete(); $this->m_oDataSource->SendNotification('fatal error', '

The synchronization could not start: \''.$e->getMessage().'\'

Please check its configuration

'); } @@ -3244,7 +3258,7 @@ class SynchroExecution $this->m_oStatLog->Set('end_date', time()); $this->m_oStatLog->Set('status', 'error'); $this->m_oStatLog->Set('last_error', $e->getMessage()); - $this->m_oStatLog->DBUpdateTracked($this->m_oChange); + $this->m_oStatLog->DBUpdate(); $this->m_oDataSource->SendNotification('exception', '

The synchronization has been interrupted: \''.$e->getMessage().'\'

Please contact the application support team

'); } @@ -3491,7 +3505,7 @@ class SynchroExecution $oReplica->Set('status', 'obsolete'); } } - $oReplica->DBUpdateTracked($this->m_oChange); + $oReplica->DBUpdate(); break; case 'delete': @@ -3591,7 +3605,7 @@ class SynchroExecution $oReplica->Synchro($this->m_oDataSource, $this->m_aReconciliationKeys, $this->m_aAttributes, $this->m_oChange, $this->m_oStatLog); $this->m_oStatLog->AddTrace("Updating replica id=$iLastReplicaProcessed."); - $oReplica->DBUpdateTracked($this->m_oChange); + $oReplica->DBUpdate(); } if ($iMaxReplica) diff --git a/test/benchmark.php b/test/benchmark.php index abe4d3aa3..a24afe339 100644 --- a/test/benchmark.php +++ b/test/benchmark.php @@ -39,13 +39,13 @@ class BenchmarkDataCreation var $m_aStatsByClass = array(); + /** @var \CMDBChange $m_oChange */ var $m_oChange; public function __construct() { $this->m_oChange = MetaModel::NewObject("CMDBChange"); $this->m_oChange->Set("date", time()); $this->m_oChange->Set("userinfo", "Benchmark setup"); - $iChangeId = $this->m_oChange->DBInsertNoReload(); } public function PlanStructure($iPlannedContacts, $iPlannedContracts) @@ -147,7 +147,8 @@ class BenchmarkDataCreation $oMyObject->Set($sProp, $value); } - $iId = $oMyObject->DBInsertTrackedNoReload($this->m_oChange, true /* skip security */); + $oMyObject::SetCurrentChange($this->m_oChange); + $iId = $oMyObject->DBInsertNoReload(); $sClassId = "$sClass ($sClassDesc)"; $this->m_aCreatedByDesc[$sClassId][] = $iId; diff --git a/test/test.class.inc.php b/test/test.class.inc.php index d0137d423..516be37bc 100644 --- a/test/test.class.inc.php +++ b/test/test.class.inc.php @@ -434,31 +434,11 @@ abstract class TestBizModel extends TestHandler } protected function ObjectToDB($oNew, $bReload = false) { -// list($bRes, $aIssues) = $oNew->CheckToWrite(); -// if (!$bRes) -// { -// throw new CoreException('Could not create object, unexpected values', array('issues' => $aIssues)); -// } if ($oNew instanceof CMDBObject) { - if (!isset($this->m_oChange)) - { - new CMDBChange(); - $oMyChange = MetaModel::NewObject("CMDBChange"); - $oMyChange->Set("date", time()); - $oMyChange->Set("userinfo", "Someone doing some tests"); - $iChangeId = $oMyChange->DBInsertNoReload(); - $this->m_oChange = $oMyChange; - } $oChange = $this->GetCurrentChange(); - if ($bReload) - { - $iId = $oNew->DBInsertTracked($oChange); - } - else - { - $iId = $oNew->DBInsertTrackedNoReload($oChange); - } + $oNew::SetCurrentChange($oChange); + $oNew->DBWrite(); } else { @@ -476,15 +456,7 @@ abstract class TestBizModel extends TestHandler protected function UpdateObjectInDB($oObject) { - if ($oObject instanceof CMDBObject) - { - $oChange = $this->GetCurrentChange(); - $oObject->DBUpdateTracked($oChange); - } - else - { - $oObject->DBUpdate(); - } + $oObject->DBUpdate(); } protected function ResetDB() { diff --git a/test/testlist.inc.php b/test/testlist.inc.php index b0cb07737..8567362dd 100644 --- a/test/testlist.inc.php +++ b/test/testlist.inc.php @@ -337,6 +337,7 @@ class TestMyBizModel extends TestBizModel function test_setattribute() { echo "

Set attribute and update

"; + /** @var cmdbTeam $team */ $team = MetaModel::GetObject("cmdbTeam", "2"); $team->Set("headcount", rand(1,1000)); $team->Set("email", "Luis ".rand(9,250)); @@ -347,10 +348,9 @@ class TestMyBizModel extends TestBizModel $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); $oMyChange->Set("userinfo", "test_setattribute / Made by robot #".rand(1,100)); - $iChangeId = $oMyChange->DBInsert(); - //DBSearch::StartDebugQuery(); - $team->DBUpdateTracked($oMyChange); + $team::SetCurrentChange($oMyChange); + $team->DBUpdate(); //DBSearch::StopDebugQuery(); echo "

Check the modified team

"; @@ -359,11 +359,6 @@ class TestMyBizModel extends TestBizModel } function test_newobject() { - $oMyChange = MetaModel::NewObject("CMDBChange"); - $oMyChange->Set("date", time()); - $oMyChange->Set("userinfo", "test_newobject / Made by robot #".rand(1,100)); - $iChangeId = $oMyChange->DBInsert(); - echo "

Create a new object (team)

"; $oNewTeam = MetaModel::NewObject("cmdbTeam"); $oNewTeam->Set("name", "ekip2choc #".rand(1000, 2000)); @@ -371,11 +366,11 @@ class TestMyBizModel extends TestBizModel $oNewTeam->Set("email", null); $oNewTeam->Set("owner", "ITOP"); $oNewTeam->Set("headcount", "0".rand(38000, 38999)); // should be reset to an int value - $iId = $oNewTeam->DBInsertTracked($oMyChange); + $iId = $oNewTeam->DBInsert(); echo "Created new team: $iId
"; echo "

Delete team #$iId

"; $oTeam = MetaModel::GetObject("cmdbTeam", $iId); - $oTeam->DBDeleteTracked($oMyChange); + $oTeam->DBDelete(); echo "Deleted team: $iId
"; self::DumpVariable($oTeam); } @@ -409,26 +404,27 @@ class TestMyBizModel extends TestBizModel function test_changetracking() { - echo "

Create a change

"; - $oMyChange = MetaModel::NewObject("CMDBChange"); - $oMyChange->Set("date", time()); - $oMyChange->Set("userinfo", "Made by robot #".rand(1,100)); - $iChangeId = $oMyChange->DBInsert(); - echo "Created new change: $iChangeId
"; + echo '

Create a change

'; + /** @var CMDBChange $oMyChange * */ + $oMyChange = MetaModel::NewObject('CMDBChange'); + $oMyChange->Set('date', time()); + $oMyChange->Set('userinfo', 'Made by robot #'.rand(1, 100)); self::DumpVariable($oMyChange); - - echo "

Create a new object (team)

"; - $oNewTeam = MetaModel::NewObject("cmdbTeam"); - $oNewTeam->Set("name", "ekip2choc #".rand(1000, 2000)); - $oNewTeam->Set("email", "machin".rand(1,100)."@tnut.com"); - $oNewTeam->Set("email", null); - $oNewTeam->Set("owner", "ITOP"); - $oNewTeam->Set("headcount", "0".rand(38000, 38999)); // should be reset to an int value - $iId = $oNewTeam->DBInsertTracked($oMyChange); + + echo '

Create a new object (team)

'; + $oNewTeam = MetaModel::NewObject('cmdbTeam'); + $oNewTeam->Set('name', 'ekip2choc #'.rand(1000, 2000)); + $oNewTeam->Set('email', 'machin'.rand(1, 100).'@tnut.com'); + $oNewTeam->Set('email', null); + $oNewTeam->Set('owner', 'ITOP'); + $oNewTeam->Set('headcount', '0'.rand(38000, 38999)); // should be reset to an int value + $oNewTeam::SetCurrentChange($oMyChange); + $iId = $oNewTeam->DBInsert(); echo "Created new team: $iId
"; echo "

Delete team #$iId

"; - $oTeam = MetaModel::GetObject("cmdbTeam", $iId); - $oTeam->DBDeleteTracked($oMyChange); + $oTeam = MetaModel::GetObject('cmdbTeam', $iId); + $oTeam::SetCurrentChange($oMyChange); + $oTeam->DBDelete(); echo "Deleted team: $iId
"; self::DumpVariable($oTeam); } @@ -535,7 +531,8 @@ class TestMyBizModel extends TestBizModel $oMyChange->Set("date", time()); $oMyChange->Set("userinfo", "test_linkedset / Made by robot #".rand(1,100)); $iChangeId = $oMyChange->DBInsert(); - $oObj->DBUpdateTracked($oMyChange); + $oObj::SetCurrentChange($oMyChange); + $oObj->DBUpdate(); $oObj = MetaModel::GetObject("cmdbContact", 18); echo "
After the write
\n"; diff --git a/webservices/createfrommail.php b/webservices/createfrommail.php index f33afa8d1..2b1867ced 100644 --- a/webservices/createfrommail.php +++ b/webservices/createfrommail.php @@ -88,8 +88,8 @@ function CreateTicket($sSenderEmail, $sSubject, $sBody) $oMyChange->Set("date", time()); $sUserString = $oContact->GetName().', submitted by email'; $oMyChange->Set("userinfo", $sUserString); - $iChangeId = $oMyChange->DBInsert(); - $oTicket->DBInsertTracked($oMyChange); + $oTicket::SetCurrentChange($oMyChange); + $oTicket->DBInsert(); } else { diff --git a/webservices/webservices.basic.php b/webservices/webservices.basic.php index 54c187825..95a397c4e 100644 --- a/webservices/webservices.basic.php +++ b/webservices/webservices.basic.php @@ -175,8 +175,7 @@ class BasicServices extends WebServicesBase $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); $oMyChange->Set("userinfo", "Administrator"); - $iChangeId = $oMyChange->DBInsertNoReload(); - + $oNewTicket = MetaModel::NewObject($sClass); $this->MyObjectSetScalar('title', 'title', $sTitle, $oNewTicket, $oRes); $this->MyObjectSetScalar('description', 'description', $sDescription, $oNewTicket, $oRes); diff --git a/webservices/webservices.class.inc.php b/webservices/webservices.class.inc.php index 33008e11b..187611a36 100644 --- a/webservices/webservices.class.inc.php +++ b/webservices/webservices.class.inc.php @@ -516,6 +516,21 @@ abstract class WebServicesBase return $aItemsNotFound; } + /** + * @param \CMDBObject $oTargetObj + * @param string $sResultLabel + * @param \CMDBChange $oChange + * @param \WebServiceResult $oRes + * + * @throws \ArchivedObjectException + * @throws \CoreCannotSaveObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \CoreWarning + * @throws \MySQLException + * @throws \OQLException + * @throws \SecurityException + */ protected function MyObjectInsert($oTargetObj, $sResultLabel, $oChange, &$oRes) { if ($oRes->IsOk()) @@ -523,7 +538,8 @@ abstract class WebServicesBase list($bRes, $aIssues) = $oTargetObj->CheckToWrite(); if ($bRes) { - $iId = $oTargetObj->DBInsertTrackedNoReload($oChange); + $oTargetObj::SetCurrentChange($oChange); + $iId = $oTargetObj->DBInsertNoReload(); $oRes->LogInfo("Created object ".get_class($oTargetObj)."::$iId"); $oRes->AddResultObject($sResultLabel, $oTargetObj); }