N°2361 Deprecate DB*Tracked methods

* update methods PHPDoc
* DBInsertTracked update callers
* DBInsertTrackedNoReload update callers
* DBUpdateTracked update callers
* DBDeleteTracked update callers
This commit is contained in:
Pierre Goiffon
2019-11-15 17:37:04 +01:00
parent cdc8edb56b
commit 24eb82d140
21 changed files with 260 additions and 189 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -4453,7 +4453,7 @@ EOF
}
else
{
$oObj->DBDeleteTracked(CMDBObject::GetCurrentChange(), null, $oDeletionPlan);
$oObj->DBDelete();
}
}

View File

@@ -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)

View File

@@ -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)
{

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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);

View File

@@ -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();
}
}
}

View File

@@ -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)
{

View File

@@ -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',
'<p>The synchronization could not start: \''.$e->getMessage().'\'</p><p>Please check its configuration</p>');
}
@@ -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',
'<p>The synchronization has been interrupted: \''.$e->getMessage().'\'</p><p>Please contact the application support team</p>');
}
@@ -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)

View File

@@ -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;

View File

@@ -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()
{

View File

@@ -337,6 +337,7 @@ class TestMyBizModel extends TestBizModel
function test_setattribute()
{
echo "<h4>Set attribute and update</h4>";
/** @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 "<h4>Check the modified team</h4>";
@@ -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 "<h4>Create a new object (team)</h4>";
$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</br>";
echo "<h4>Delete team #$iId</h4>";
$oTeam = MetaModel::GetObject("cmdbTeam", $iId);
$oTeam->DBDeleteTracked($oMyChange);
$oTeam->DBDelete();
echo "Deleted team: $iId</br>";
self::DumpVariable($oTeam);
}
@@ -409,26 +404,27 @@ class TestMyBizModel extends TestBizModel
function test_changetracking()
{
echo "<h4>Create a change</h4>";
$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</br>";
echo '<h4>Create a change</h4>';
/** @var CMDBChange $oMyChange * */
$oMyChange = MetaModel::NewObject('CMDBChange');
$oMyChange->Set('date', time());
$oMyChange->Set('userinfo', 'Made by robot #'.rand(1, 100));
self::DumpVariable($oMyChange);
echo "<h4>Create a new object (team)</h4>";
$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 '<h4>Create a new object (team)</h4>';
$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</br>";
echo "<h4>Delete team #$iId</h4>";
$oTeam = MetaModel::GetObject("cmdbTeam", $iId);
$oTeam->DBDeleteTracked($oMyChange);
$oTeam = MetaModel::GetObject('cmdbTeam', $iId);
$oTeam::SetCurrentChange($oMyChange);
$oTeam->DBDelete();
echo "Deleted team: $iId</br>";
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 "<h5>After the write</h5>\n";

View File

@@ -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
{

View File

@@ -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);

View File

@@ -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);
}