N°4988 - History API : change consumers (iTop core)

This commit is contained in:
acognet
2022-06-21 17:24:09 +02:00
parent bd3724be8f
commit aae1e12b2e
7 changed files with 31 additions and 57 deletions

View File

@@ -121,7 +121,6 @@ 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);

View File

@@ -435,20 +435,18 @@ class UserRightsProfile extends UserRightsAddOnAPI
// Installation: create the very first user // Installation: create the very first user
public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US') public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
{ {
CMDBObject::SetTrackInfo('Initialization'); CMDBObject::SetCurrentChangeFromParams('Initialization create administrator');
$iContactId = 0; $iContactId = 0;
// Support drastic data model changes: no organization class (or not writable)! // Support drastic data model changes: no organization class (or not writable)!
if (MetaModel::IsValidClass('Organization') && !MetaModel::IsAbstract('Organization')) if (MetaModel::IsValidClass('Organization') && !MetaModel::IsAbstract('Organization')) {
{
$oOrg = MetaModel::NewObject('Organization'); $oOrg = MetaModel::NewObject('Organization');
$oOrg->Set('name', 'My Company/Department'); $oOrg->Set('name', 'My Company/Department');
$oOrg->Set('code', 'SOMECODE'); $oOrg->Set('code', 'SOMECODE');
$iOrgId = $oOrg->DBInsertNoReload(); $iOrgId = $oOrg->DBInsertNoReload();
// Support drastic data model changes: no Person class (or not writable)! // Support drastic data model changes: no Person class (or not writable)!
if (MetaModel::IsValidClass('Person') && !MetaModel::IsAbstract('Person')) if (MetaModel::IsValidClass('Person') && !MetaModel::IsAbstract('Person')) {
{
$oContact = MetaModel::NewObject('Person'); $oContact = MetaModel::NewObject('Person');
$oContact->Set('name', 'My last name'); $oContact->Set('name', 'My last name');
$oContact->Set('first_name', 'My first name'); $oContact->Set('first_name', 'My first name');

View File

@@ -508,24 +508,18 @@ class UserRightsProfile extends UserRightsAddOnAPI
public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US') public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
{ {
// Create a change to record the history of the User object // Create a change to record the history of the User object
/** @var \CMDBChange $oChange */ CMDBObject::SetCurrentChangeFromParams('Initialization : create first user admin profile');
$oChange = MetaModel::NewObject("CMDBChange");
$oChange->Set("date", time());
$oChange->Set("userinfo", "Initialization");
$iContactId = 0; $iContactId = 0;
// Support drastic data model changes: no organization class (or not writable)! // Support drastic data model changes: no organization class (or not writable)!
if (MetaModel::IsValidClass('Organization') && !MetaModel::IsAbstract('Organization')) if (MetaModel::IsValidClass('Organization') && !MetaModel::IsAbstract('Organization')) {
{
$oOrg = MetaModel::NewObject('Organization'); $oOrg = MetaModel::NewObject('Organization');
$oOrg->Set('name', 'My Company/Department'); $oOrg->Set('name', 'My Company/Department');
$oOrg->Set('code', 'SOMECODE'); $oOrg->Set('code', 'SOMECODE');
$oOrg::SetCurrentChange($oChange);
$iOrgId = $oOrg->DBInsertNoReload(); $iOrgId = $oOrg->DBInsertNoReload();
// Support drastic data model changes: no Person class (or not writable)! // Support drastic data model changes: no Person class (or not writable)!
if (MetaModel::IsValidClass('Person') && !MetaModel::IsAbstract('Person')) if (MetaModel::IsValidClass('Person') && !MetaModel::IsAbstract('Person')) {
{
$oContact = MetaModel::NewObject('Person'); $oContact = MetaModel::NewObject('Person');
$oContact->Set('name', 'My last name'); $oContact->Set('name', 'My last name');
$oContact->Set('first_name', 'My first name'); $oContact->Set('first_name', 'My first name');
@@ -534,7 +528,6 @@ class UserRightsProfile extends UserRightsAddOnAPI
$oContact->Set('org_id', $iOrgId); $oContact->Set('org_id', $iOrgId);
} }
$oContact->Set('email', 'my.email@foo.org'); $oContact->Set('email', 'my.email@foo.org');
$oContact::SetCurrentChange($oChange);
$iContactId = $oContact->DBInsertNoReload(); $iContactId = $oContact->DBInsertNoReload();
} }
} }
@@ -543,24 +536,22 @@ class UserRightsProfile extends UserRightsAddOnAPI
$oUser = new UserLocal(); $oUser = new UserLocal();
$oUser->Set('login', $sAdminUser); $oUser->Set('login', $sAdminUser);
$oUser->Set('password', $sAdminPwd); $oUser->Set('password', $sAdminPwd);
if (MetaModel::IsValidAttCode('UserLocal', 'contactid') && ($iContactId != 0)) if (MetaModel::IsValidAttCode('UserLocal', 'contactid') && ($iContactId != 0)) {
{
$oUser->Set('contactid', $iContactId); $oUser->Set('contactid', $iContactId);
} }
$oUser->Set('language', $sLanguage); // Language was chosen during the installation $oUser->Set('language', $sLanguage); // Language was chosen during the installation
// Add this user to the very specific 'admin' profile // Add this user to the very specific 'admin' profile
$oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => ADMIN_PROFILE_NAME), true /*all data*/); $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => ADMIN_PROFILE_NAME), true /*all data*/);
if (is_object($oAdminProfile)) if (is_object($oAdminProfile)) {
{
$oUserProfile = new URP_UserProfile(); $oUserProfile = new URP_UserProfile();
$oUserProfile->Set('profileid', $oAdminProfile->GetKey()); $oUserProfile->Set('profileid', $oAdminProfile->GetKey());
$oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile'); $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
$oSet = DBObjectSet::FromObject($oUserProfile); $oSet = DBObjectSet::FromObject($oUserProfile);
$oUser->Set('profile_list', $oSet); $oUser->Set('profile_list', $oSet);
} }
$oUser::SetCurrentChange($oChange); $oUser->DBInsertNoReload();
$iUserId = $oUser->DBInsertNoReload();
return true; return true;
} }

View File

@@ -568,14 +568,11 @@ class UserRightsProjection extends UserRightsAddOnAPI
public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US') public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
{ {
// Create a change to record the history of the User object // Create a change to record the history of the User object
$oChange = MetaModel::NewObject("CMDBChange"); CMDBObject::SetCurrentChangeFromParams('Initialization : create first user admin');
$oChange->Set("date", time());
$oChange->Set("userinfo", "Initialization");
$oOrg = new Organization(); $oOrg = new Organization();
$oOrg->Set('name', 'My Company/Department'); $oOrg->Set('name', 'My Company/Department');
$oOrg->Set('code', 'SOMECODE'); $oOrg->Set('code', 'SOMECODE');
$oOrg::SetCurrentChange($oChange);
$iOrgId = $oOrg->DBInsertNoReload(); $iOrgId = $oOrg->DBInsertNoReload();
$oContact = new Person(); $oContact = new Person();
@@ -584,7 +581,6 @@ class UserRightsProjection extends UserRightsAddOnAPI
//$oContact->Set('status', 'available'); //$oContact->Set('status', 'available');
$oContact->Set('org_id', $iOrgId); $oContact->Set('org_id', $iOrgId);
$oContact->Set('email', 'my.email@foo.org'); $oContact->Set('email', 'my.email@foo.org');
$oContact::SetCurrentChange($oChange);
$iContactId = $oContact->DBInsertNoReload(); $iContactId = $oContact->DBInsertNoReload();
$oUser = new UserLocal(); $oUser = new UserLocal();
@@ -592,7 +588,6 @@ class UserRightsProjection extends UserRightsAddOnAPI
$oUser->Set('password', $sAdminPwd); $oUser->Set('password', $sAdminPwd);
$oUser->Set('contactid', $iContactId); $oUser->Set('contactid', $iContactId);
$oUser->Set('language', $sLanguage); // Language was chosen during the installation $oUser->Set('language', $sLanguage); // Language was chosen during the installation
$oUser::SetCurrentChange($oChange);
$iUserId = $oUser->DBInsertNoReload(); $iUserId = $oUser->DBInsertNoReload();
// Add this user to the very specific 'admin' profile // Add this user to the very specific 'admin' profile
@@ -600,7 +595,6 @@ class UserRightsProjection extends UserRightsAddOnAPI
$oUserProfile->Set('userid', $iUserId); $oUserProfile->Set('userid', $iUserId);
$oUserProfile->Set('profileid', ADMIN_PROFILE_ID); $oUserProfile->Set('profileid', ADMIN_PROFILE_ID);
$oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile'); $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
$oUserProfile::SetCurrentChange($oChange);
$oUserProfile->DBInsertNoReload(); $oUserProfile->DBInsertNoReload();
return true; return true;
} }

View File

@@ -597,9 +597,8 @@ class CheckStopWatchThresholds implements iBackgroundProcess
$oSW->MarkThresholdAsTriggered($iThreshold); $oSW->MarkThresholdAsTriggered($iThreshold);
$oObj->Set($sAttCode, $oSW); $oObj->Set($sAttCode, $oSW);
if($oObj->IsModified()) if ($oObj->IsModified()) {
{ CMDBObject::SetCurrentChangeFromParams("Automatic - threshold triggered");
CMDBObject::SetTrackInfo("Automatic - threshold triggered");
$oObj->DBUpdate(); $oObj->DBUpdate();
} }

View File

@@ -356,9 +356,7 @@ try {
if (!$bSimulate) if (!$bSimulate)
{ {
// We're doing it for real, let's create a change // We're doing it for real, let's create a change
$sUserString = CMDBChange::GetCurrentUserName().' (CSV)'; CMDBObject::SetCurrentChangeFromParams('$sUserString', CMDBChangeOrigin::CSV_INTERACTIVE);
CMDBObject::SetTrackInfo($sUserString);
CMDBObject::SetTrackOrigin(CMDBChangeOrigin::CSV_INTERACTIVE);
$oMyChange = CMDBObject::GetCurrentChange(); $oMyChange = CMDBObject::GetCurrentChange();
} }
CMDBObject::SetTrackOrigin('csv-interactive'); CMDBObject::SetTrackOrigin('csv-interactive');

View File

@@ -1109,29 +1109,24 @@ class RunTimeEnvironment
*/ */
public function LoadData($aAvailableModules, $aSelectedModules, $bSampleData) public function LoadData($aAvailableModules, $aSelectedModules, $bSampleData)
{ {
$oDataLoader = new XMLDataLoader(); $oDataLoader = new XMLDataLoader();
CMDBObject::SetTrackInfo("Initialization"); CMDBObject::SetCurrentChangeFromParams("Initialization from XML files for the selected modules ");
$oMyChange = CMDBObject::GetCurrentChange(); $oMyChange = CMDBObject::GetCurrentChange();
SetupLog::Info("starting data load session"); SetupLog::Info("starting data load session");
$oDataLoader->StartSession($oMyChange); $oDataLoader->StartSession($oMyChange);
$aFiles = array(); $aFiles = array();
$aPreviouslyLoadedFiles = array(); $aPreviouslyLoadedFiles = array();
foreach($aAvailableModules as $sModuleId => $aModule) foreach ($aAvailableModules as $sModuleId => $aModule) {
{ if (($sModuleId != ROOT_MODULE)) {
if (($sModuleId != ROOT_MODULE)) $sRelativePath = 'env-'.$this->sTargetEnv.'/'.basename($aModule['root_dir']);
{ // Load data only for selected AND newly installed modules
$sRelativePath = 'env-'.$this->sTargetEnv.'/'.basename($aModule['root_dir']); if (in_array($sModuleId, $aSelectedModules)) {
// Load data only for selected AND newly installed modules if ($aModule['version_db'] != '') {
if (in_array($sModuleId, $aSelectedModules)) // Simulate the load of the previously loaded XML files to get the mapping of the keys
{ if ($bSampleData) {
if ($aModule['version_db'] != '')
{
// Simulate the load of the previously loaded XML files to get the mapping of the keys
if ($bSampleData)
{
$aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']); $aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
$aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.sample']); $aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.sample']);
} }