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

@@ -94,6 +94,7 @@ abstract class CMDBObject extends DBObject
// Note: this value is static, but that could be changed because it is sometimes a real issue (see update of interfaces / connected_to
protected static $m_oCurrChange = null;
protected static $m_sInfo = null; // null => the information is built in a standard way
protected static $m_sUserId = null; // null => the user doing the change is unknown
protected static $m_sOrigin = null; // null => the origin is 'interactive'
/**
@@ -146,6 +147,21 @@ abstract class CMDBObject extends DBObject
self::$m_sInfo = $sInfo;
}
/**
* Provide information about the user doing the change
*
* @see static::SetTrackInfo
* @see static::SetCurrentChange
*
* @param string $sId ID of the user doing the change, null if not done by a user (eg. background task)
*
* @since 2.8.0
*/
public static function SetTrackUserId($sId)
{
self::$m_sUserId = $sId;
}
/**
* Provides information about the origin of the change
*
@@ -174,6 +190,25 @@ abstract class CMDBObject extends DBObject
return self::$m_sInfo;
}
}
/**
* Get the ID of the user doing the change (defaulting to null)
*
* @return string|null
* @throws \OQLException
* @since 2.8.0
*/
protected static function GetTrackUserId()
{
if (is_null(self::$m_sUserId))
{
return CMDBChange::GetCurrentUserId();
}
else
{
return self::$m_sUserId;
}
}
/**
* Get the 'origin' information (defaulting to 'interactive')
@@ -189,15 +224,24 @@ abstract class CMDBObject extends DBObject
return self::$m_sOrigin;
}
}
/**
* Create a standard change record (done here 99% of the time, and nearly once per page)
*/
*
* @throws \ArchivedObjectException
* @throws \CoreCannotSaveObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \CoreWarning
* @throws \MySQLException
* @throws \OQLException
*/
protected static function CreateChange()
{
self::$m_oCurrChange = MetaModel::NewObject("CMDBChange");
self::$m_oCurrChange->Set("date", time());
self::$m_oCurrChange->Set("userinfo", self::GetTrackInfo());
self::$m_oCurrChange->Set("user_id", self::GetTrackUserId());
self::$m_oCurrChange->Set("origin", self::GetTrackOrigin());
self::$m_oCurrChange->DBInsert();
}