N°2847 - Add optional user_id to CMDBChange

Important: This can make the setup / toolkit to take a very long time on large databases as the "priv_change" table is one of the largest. SQL queries to run and/or a migration tool will be provided when 2.8.0 will be released.
This commit is contained in:
Molkobain
2020-08-28 19:46:40 +02:00
parent 3add77308a
commit c2fcadd54d
3 changed files with 61 additions and 2 deletions

View File

@@ -52,6 +52,7 @@ class CMDBChange extends DBObject
//MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeDateTime("date", array("allowed_values"=>null, "sql"=>"date", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("userinfo", array("allowed_values"=>null, "sql"=>"userinfo", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeInteger("user_id", array("allowed_values" => null, "sql" => "user_id", "default_value" => null, "is_null_allowed" => true, "depends_on" => array(),)));
MetaModel::Init_AddAttribute(new AttributeEnum("origin", array("allowed_values"=>new ValueSetEnum('interactive,csv-interactive,csv-import.php,webservice-soap,webservice-rest,synchro-data-source,email-processing,custom-extension'), "sql"=>"origin", "default_value"=>"interactive", "is_null_allowed"=>true, "depends_on"=>array())));
}
@@ -75,6 +76,19 @@ class CMDBChange extends DBObject
return $sUserString;
}
/**
* Return the current user
*
* @return string|null
* @throws \OQLException
* @since 2.8.0
*/
public static function GetCurrentUserId()
{
// Note: We might have use only UserRights::GetRealUserId() as it would have done the same thing in the end
return UserRights::IsImpersonated() ? UserRights::GetRealUserId() : UserRights::GetUserId();
}
public function GetUserName()
{
if (preg_match('/^(.*)\\(CSV\\)$/i', $this->Get('userinfo'), $aMatches))