mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°2163 DB*Tracked methods : modifications after review with Romain
Previous commit : 24eb82d1
Use \CMDBObject::SetTrackInfo
Move \CMDBObject::SetCurrentChange calls at the top most level of the stacks
Restore old behaviors that were removed in previous commit
This commit is contained in:
@@ -121,20 +121,14 @@ class UserRightsMatrix extends UserRightsAddOnAPI
|
|||||||
public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
|
public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
|
||||||
{
|
{
|
||||||
// Maybe we should check that no other user with userid == 0 exists
|
// Maybe we should check that no other user with userid == 0 exists
|
||||||
|
CMDBObject::SetTrackInfo('Initialization');
|
||||||
$oUser = new UserLocal();
|
$oUser = new UserLocal();
|
||||||
$oUser->Set('login', $sAdminUser);
|
$oUser->Set('login', $sAdminUser);
|
||||||
$oUser->Set('password', $sAdminPwd);
|
$oUser->Set('password', $sAdminPwd);
|
||||||
$oUser->Set('contactid', 1); // one is for root !
|
$oUser->Set('contactid', 1); // one is for root !
|
||||||
$oUser->Set('language', $sLanguage); // Language was chosen during the installation
|
$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");
|
|
||||||
|
|
||||||
// Now record the admin user object
|
// Now record the admin user object
|
||||||
$oUser::SetCurrentChange($oChange);
|
|
||||||
$iUserId = $oUser->DBInsertNoReload();
|
$iUserId = $oUser->DBInsertNoReload();
|
||||||
$this->SetupUser($iUserId, true);
|
$this->SetupUser($iUserId, true);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4433,7 +4433,7 @@ EOF
|
|||||||
*
|
*
|
||||||
* @param \WebPage $oP
|
* @param \WebPage $oP
|
||||||
* @param $sClass
|
* @param $sClass
|
||||||
* @param $aObjects
|
* @param \DBObject[] $aObjects
|
||||||
* @param $bPreview
|
* @param $bPreview
|
||||||
* @param $sCustomOperation
|
* @param $sCustomOperation
|
||||||
* @param array $aContextData
|
* @param array $aContextData
|
||||||
@@ -4453,7 +4453,7 @@ EOF
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$oObj->DBDelete();
|
$oObj->DBDelete($oDeletionPlan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -786,7 +786,13 @@ class LoginWebPage extends NiceWebPage
|
|||||||
$oPerson = null;
|
$oPerson = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/** @var Person $oPerson */
|
$sOrigin = 'External User provisioning';
|
||||||
|
if (isset($_SESSION['login_mode']))
|
||||||
|
{
|
||||||
|
$sOrigin .= " ({$_SESSION['login_mode']})";
|
||||||
|
}
|
||||||
|
CMDBObject::SetTrackOrigin($sOrigin);
|
||||||
|
|
||||||
$oPerson = MetaModel::NewObject('Person');
|
$oPerson = MetaModel::NewObject('Person');
|
||||||
$oPerson->Set('first_name', $sFirstName);
|
$oPerson->Set('first_name', $sFirstName);
|
||||||
$oPerson->Set('name', $sLastName);
|
$oPerson->Set('name', $sLastName);
|
||||||
@@ -801,16 +807,6 @@ class LoginWebPage extends NiceWebPage
|
|||||||
{
|
{
|
||||||
$oPerson->Set($sAttCode, $sValue);
|
$oPerson->Set($sAttCode, $sValue);
|
||||||
}
|
}
|
||||||
/** @var CMDBChange $oMyChange */
|
|
||||||
$oMyChange = MetaModel::NewObject('CMDBChange');
|
|
||||||
$oMyChange->Set("date", time());
|
|
||||||
$sOrigin = 'External User provisioning';
|
|
||||||
if (isset($_SESSION['login_mode']))
|
|
||||||
{
|
|
||||||
$sOrigin .= " ({$_SESSION['login_mode']})";
|
|
||||||
}
|
|
||||||
$oMyChange->Set('userinfo', $sOrigin);
|
|
||||||
$oPerson::SetCurrentChange($oMyChange);
|
|
||||||
$oPerson->DBInsert();
|
$oPerson->DBInsert();
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
|
|||||||
@@ -654,7 +654,7 @@ class BulkChange
|
|||||||
return $aResults;
|
return $aResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function CreateObject(&$aResult, $iRow, $aRowData, CMDBChange $oChange = null)
|
protected function CreateObject(&$aResult, $iRow, $aRowData, CMDBChange $oChange = null)
|
||||||
{
|
{
|
||||||
$oTargetObj = MetaModel::NewObject($this->m_sClass);
|
$oTargetObj = MetaModel::NewObject($this->m_sClass);
|
||||||
@@ -731,18 +731,17 @@ class BulkChange
|
|||||||
//
|
//
|
||||||
if ($oChange)
|
if ($oChange)
|
||||||
{
|
{
|
||||||
$oTargetObj::SetCurrentChange($oChange);
|
|
||||||
$newID = $oTargetObj->DBInsert();
|
$newID = $oTargetObj->DBInsert();
|
||||||
$aResult[$iRow]["__STATUS__"] = new RowStatus_NewObj();
|
|
||||||
$aResult[$iRow]["finalclass"] = get_class($oTargetObj);
|
|
||||||
$aResult[$iRow]["id"] = new CellStatus_Void($newID);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aResult[$iRow]["__STATUS__"] = new RowStatus_NewObj();
|
$newID = 0;
|
||||||
$aResult[$iRow]["finalclass"] = get_class($oTargetObj);
|
|
||||||
$aResult[$iRow]["id"] = new CellStatus_Void(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$aResult[$iRow]["__STATUS__"] = new RowStatus_NewObj();
|
||||||
|
$aResult[$iRow]["finalclass"] = get_class($oTargetObj);
|
||||||
|
$aResult[$iRow]["id"] = new CellStatus_Void($newID);
|
||||||
|
|
||||||
return $oTargetObj;
|
return $oTargetObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -786,7 +785,6 @@ class BulkChange
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oTargetObj::SetCurrentChange($oChange);
|
|
||||||
$oTargetObj->DBUpdate();
|
$oTargetObj->DBUpdate();
|
||||||
}
|
}
|
||||||
catch(CoreException $e)
|
catch(CoreException $e)
|
||||||
@@ -852,6 +850,11 @@ class BulkChange
|
|||||||
|
|
||||||
public function Process(CMDBChange $oChange = null)
|
public function Process(CMDBChange $oChange = null)
|
||||||
{
|
{
|
||||||
|
if ($oChange)
|
||||||
|
{
|
||||||
|
CMDBObject::SetCurrentChange($oChange);
|
||||||
|
}
|
||||||
|
|
||||||
// Note: $oChange can be null, in which case the aim is to check what would be done
|
// Note: $oChange can be null, in which case the aim is to check what would be done
|
||||||
|
|
||||||
// Debug...
|
// Debug...
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
namespace Combodo\iTop\Cas;
|
namespace Combodo\iTop\Cas;
|
||||||
|
|
||||||
use AbstractLoginFSMExtension;
|
use AbstractLoginFSMExtension;
|
||||||
|
use CMDBObject;
|
||||||
use DBObjectSearch;
|
use DBObjectSearch;
|
||||||
use DBObjectSet;
|
use DBObjectSet;
|
||||||
use Dict;
|
use Dict;
|
||||||
@@ -185,6 +186,7 @@ class CASLoginExtension extends AbstractLoginFSMExtension implements iLogoutExte
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CMDBObject::SetTrackInfo('CAS/LDAP Synchro');
|
||||||
$oUser = LoginWebPage::FindUser($sLogin, false);
|
$oUser = LoginWebPage::FindUser($sLogin, false);
|
||||||
if ($oUser)
|
if ($oUser)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,21 +50,13 @@ class TicketsInstaller extends ModuleInstallerAPI
|
|||||||
public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
|
public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
|
||||||
{
|
{
|
||||||
// Delete all Triggers corresponding to a no more valid class
|
// Delete all Triggers corresponding to a no more valid class
|
||||||
|
CMDBObject::SetTrackInfo('Uninstallation');
|
||||||
$oSearch = new DBObjectSearch('TriggerOnObject');
|
$oSearch = new DBObjectSearch('TriggerOnObject');
|
||||||
$oSet = new DBObjectSet($oSearch);
|
$oSet = new DBObjectSet($oSearch);
|
||||||
$oChange = null;
|
|
||||||
while($oTrigger = $oSet->Fetch())
|
while($oTrigger = $oSet->Fetch())
|
||||||
{
|
{
|
||||||
if (!MetaModel::IsValidClass($oTrigger->Get('target_class')))
|
if (!MetaModel::IsValidClass($oTrigger->Get('target_class')))
|
||||||
{
|
{
|
||||||
if ($oChange == null)
|
|
||||||
{
|
|
||||||
// Create the change for its first use
|
|
||||||
$oChange = new CMDBChange;
|
|
||||||
$oChange->Set("date", time());
|
|
||||||
$oChange->Set("userinfo", "Uninstallation");
|
|
||||||
}
|
|
||||||
$oTrigger::SetCurrentChange($oChange);
|
|
||||||
$oTrigger->DBDelete();
|
$oTrigger->DBDelete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3001,6 +3001,7 @@ class SynchroExecution
|
|||||||
$this->m_oChange->Set('userinfo', $sUserString.' '.Dict::S('Core:SyncDataExchangeComment'));
|
$this->m_oChange->Set('userinfo', $sUserString.' '.Dict::S('Core:SyncDataExchangeComment'));
|
||||||
$this->m_oChange->Set('origin', 'synchro-data-source');
|
$this->m_oChange->Set('origin', 'synchro-data-source');
|
||||||
$this->m_oChange->DBInsert();
|
$this->m_oChange->DBInsert();
|
||||||
|
CMDBObject::SetCurrentChange($oChange);
|
||||||
|
|
||||||
// Start logging this execution (stats + protection against reentrance)
|
// Start logging this execution (stats + protection against reentrance)
|
||||||
//
|
//
|
||||||
@@ -3377,6 +3378,7 @@ class SynchroExecution
|
|||||||
self::$m_oCurrentTask = $this->m_oDataSource;
|
self::$m_oCurrentTask = $this->m_oDataSource;
|
||||||
$this->m_oStatLog = $oLog;
|
$this->m_oStatLog = $oLog;
|
||||||
$this->m_oChange = $oChange;
|
$this->m_oChange = $oChange;
|
||||||
|
CMDBObject::SetCurrentChange($oChange);
|
||||||
|
|
||||||
// Prepare internal structures (not the first pass)
|
// Prepare internal structures (not the first pass)
|
||||||
$this->PrepareProcessing(false);
|
$this->PrepareProcessing(false);
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ class BenchmarkDataCreation
|
|||||||
var $m_oChange;
|
var $m_oChange;
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->m_oChange = MetaModel::NewObject("CMDBChange");
|
CMDBObject::SetTrackInfo('Benchmark setup');
|
||||||
$this->m_oChange->Set("date", time());
|
|
||||||
$this->m_oChange->Set("userinfo", "Benchmark setup");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function PlanStructure($iPlannedContacts, $iPlannedContracts)
|
public function PlanStructure($iPlannedContacts, $iPlannedContracts)
|
||||||
@@ -147,7 +145,6 @@ class BenchmarkDataCreation
|
|||||||
$oMyObject->Set($sProp, $value);
|
$oMyObject->Set($sProp, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oMyObject::SetCurrentChange($this->m_oChange);
|
|
||||||
$iId = $oMyObject->DBInsertNoReload();
|
$iId = $oMyObject->DBInsertNoReload();
|
||||||
|
|
||||||
$sClassId = "$sClass ($sClassDesc)";
|
$sClassId = "$sClass ($sClassDesc)";
|
||||||
|
|||||||
@@ -434,22 +434,13 @@ abstract class TestBizModel extends TestHandler
|
|||||||
}
|
}
|
||||||
protected function ObjectToDB($oNew, $bReload = false)
|
protected function ObjectToDB($oNew, $bReload = false)
|
||||||
{
|
{
|
||||||
if ($oNew instanceof CMDBObject)
|
if ($bReload)
|
||||||
{
|
{
|
||||||
$oChange = $this->GetCurrentChange();
|
$iId = $oNew->DBInsert();
|
||||||
$oNew::SetCurrentChange($oChange);
|
|
||||||
$oNew->DBWrite();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($bReload)
|
$iId = $oNew->DBInsertNoReload();
|
||||||
{
|
|
||||||
$iId = $oNew->DBInsert();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$iId = $oNew->DBInsertNoReload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $iId;
|
return $iId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,12 +342,9 @@ class TestMyBizModel extends TestBizModel
|
|||||||
self::DumpVariable($team->ListChanges());
|
self::DumpVariable($team->ListChanges());
|
||||||
echo "New headcount = {$team->Get("headcount")}</br>\n";
|
echo "New headcount = {$team->Get("headcount")}</br>\n";
|
||||||
echo "Computed name = {$team->Get("name")}</br>\n";
|
echo "Computed name = {$team->Get("name")}</br>\n";
|
||||||
|
|
||||||
$oMyChange = MetaModel::NewObject("CMDBChange");
|
CMDBObject::SetTrackInfo('test_setattribute / Made by robot #'.rand(1, 100));
|
||||||
$oMyChange->Set("date", time());
|
|
||||||
$oMyChange->Set("userinfo", "test_setattribute / Made by robot #".rand(1,100));
|
|
||||||
//DBSearch::StartDebugQuery();
|
//DBSearch::StartDebugQuery();
|
||||||
$team::SetCurrentChange($oMyChange);
|
|
||||||
$team->DBUpdate();
|
$team->DBUpdate();
|
||||||
//DBSearch::StopDebugQuery();
|
//DBSearch::StopDebugQuery();
|
||||||
|
|
||||||
@@ -524,12 +521,8 @@ class TestMyBizModel extends TestBizModel
|
|||||||
echo "<h5>New workshops</h5>\n";
|
echo "<h5>New workshops</h5>\n";
|
||||||
$oSetWorkshopsCurr = $oObj->Get("myworkshops");
|
$oSetWorkshopsCurr = $oObj->Get("myworkshops");
|
||||||
$this->show_list($oSetWorkshopsCurr);
|
$this->show_list($oSetWorkshopsCurr);
|
||||||
|
|
||||||
$oMyChange = MetaModel::NewObject("CMDBChange");
|
CMDBObject::SetTrackInfo('test_linkedset / Made by robot #'.rand(1, 100));
|
||||||
$oMyChange->Set("date", time());
|
|
||||||
$oMyChange->Set("userinfo", "test_linkedset / Made by robot #".rand(1,100));
|
|
||||||
$iChangeId = $oMyChange->DBInsert();
|
|
||||||
$oObj::SetCurrentChange($oMyChange);
|
|
||||||
$oObj->DBUpdate();
|
$oObj->DBUpdate();
|
||||||
$oObj = MetaModel::GetObject("cmdbContact", 18);
|
$oObj = MetaModel::GetObject("cmdbContact", 18);
|
||||||
|
|
||||||
|
|||||||
@@ -84,11 +84,8 @@ function CreateTicket($sSenderEmail, $sSubject, $sBody)
|
|||||||
$oTicket->Set('workgroup_id', DEFAULT_WORKGROUP_ID); // Same as above...
|
$oTicket->Set('workgroup_id', DEFAULT_WORKGROUP_ID); // Same as above...
|
||||||
|
|
||||||
// Record the change information about the object
|
// Record the change information about the object
|
||||||
$oMyChange = MetaModel::NewObject("CMDBChange");
|
|
||||||
$oMyChange->Set("date", time());
|
|
||||||
$sUserString = $oContact->GetName().', submitted by email';
|
$sUserString = $oContact->GetName().', submitted by email';
|
||||||
$oMyChange->Set("userinfo", $sUserString);
|
CMDBObject::SetTrackInfo($sUserString);
|
||||||
$oTicket::SetCurrentChange($oMyChange);
|
|
||||||
$oTicket->DBInsert();
|
$oTicket->DBInsert();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -172,9 +172,7 @@ class BasicServices extends WebServicesBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oMyChange = MetaModel::NewObject("CMDBChange");
|
CMDBObject::SetTrackInfo('Administrator');
|
||||||
$oMyChange->Set("date", time());
|
|
||||||
$oMyChange->Set("userinfo", "Administrator");
|
|
||||||
|
|
||||||
$oNewTicket = MetaModel::NewObject($sClass);
|
$oNewTicket = MetaModel::NewObject($sClass);
|
||||||
$this->MyObjectSetScalar('title', 'title', $sTitle, $oNewTicket, $oRes);
|
$this->MyObjectSetScalar('title', 'title', $sTitle, $oNewTicket, $oRes);
|
||||||
@@ -230,7 +228,7 @@ class BasicServices extends WebServicesBase
|
|||||||
$this->MyObjectSetScalar('impact', 'impact', $sImpact, $oNewTicket, $oRes);
|
$this->MyObjectSetScalar('impact', 'impact', $sImpact, $oNewTicket, $oRes);
|
||||||
$this->MyObjectSetScalar('urgency', 'urgency', $sUrgency, $oNewTicket, $oRes);
|
$this->MyObjectSetScalar('urgency', 'urgency', $sUrgency, $oNewTicket, $oRes);
|
||||||
|
|
||||||
$this->MyObjectInsert($oNewTicket, 'created', $oMyChange, $oRes);
|
$this->MyObjectInsert($oNewTicket, 'created', $oRes);
|
||||||
}
|
}
|
||||||
catch (CoreException $e)
|
catch (CoreException $e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -519,7 +519,6 @@ abstract class WebServicesBase
|
|||||||
/**
|
/**
|
||||||
* @param \CMDBObject $oTargetObj
|
* @param \CMDBObject $oTargetObj
|
||||||
* @param string $sResultLabel
|
* @param string $sResultLabel
|
||||||
* @param \CMDBChange $oChange
|
|
||||||
* @param \WebServiceResult $oRes
|
* @param \WebServiceResult $oRes
|
||||||
*
|
*
|
||||||
* @throws \ArchivedObjectException
|
* @throws \ArchivedObjectException
|
||||||
@@ -531,14 +530,13 @@ abstract class WebServicesBase
|
|||||||
* @throws \OQLException
|
* @throws \OQLException
|
||||||
* @throws \SecurityException
|
* @throws \SecurityException
|
||||||
*/
|
*/
|
||||||
protected function MyObjectInsert($oTargetObj, $sResultLabel, $oChange, &$oRes)
|
protected function MyObjectInsert($oTargetObj, $sResultLabel, &$oRes)
|
||||||
{
|
{
|
||||||
if ($oRes->IsOk())
|
if ($oRes->IsOk())
|
||||||
{
|
{
|
||||||
list($bRes, $aIssues) = $oTargetObj->CheckToWrite();
|
list($bRes, $aIssues) = $oTargetObj->CheckToWrite();
|
||||||
if ($bRes)
|
if ($bRes)
|
||||||
{
|
{
|
||||||
$oTargetObj::SetCurrentChange($oChange);
|
|
||||||
$iId = $oTargetObj->DBInsertNoReload();
|
$iId = $oTargetObj->DBInsertNoReload();
|
||||||
$oRes->LogInfo("Created object ".get_class($oTargetObj)."::$iId");
|
$oRes->LogInfo("Created object ".get_class($oTargetObj)."::$iId");
|
||||||
$oRes->AddResultObject($sResultLabel, $oTargetObj);
|
$oRes->AddResultObject($sResultLabel, $oTargetObj);
|
||||||
|
|||||||
Reference in New Issue
Block a user