N°3219 cron : reset CMDBChange for each process

This commit is contained in:
Pierre Goiffon
2020-08-04 09:21:03 +02:00
parent 1148449bb7
commit 07bd6b8539
2 changed files with 29 additions and 8 deletions

View File

@@ -95,11 +95,17 @@ abstract class CMDBObject extends DBObject
protected static $m_oCurrChange = null;
protected static $m_sInfo = null; // null => the information is built in a standard way
protected static $m_sOrigin = null; // null => the origin is 'interactive'
/**
* Specify another change (this is mainly for backward compatibility)
* Specify the change to be used by the API to attach any CMDBChangeOp* object created
*
* @see SetTrackInfo if CurrentChange is null, then a new one will be create using trackinfo
*
* @param CMDBChange|null $oChange use null so that the API will recreate a new CMDBChange using TrackInfo & TrackOrigin
*
* @since 2.7.2 N°3219 can now reset CMDBChange by passing null
*/
public static function SetCurrentChange(CMDBChange $oChange)
public static function SetCurrentChange($oChange)
{
self::$m_oCurrChange = $oChange;
}
@@ -126,11 +132,15 @@ abstract class CMDBObject extends DBObject
/**
* Override the additional information (defaulting to user name)
* A call to this verb should replace every occurence of
* $oMyChange = MetaModel::NewObject("CMDBChange");
* $oMyChange = MetaModel::NewObject("CMDBChange");
* $oMyChange->Set("date", time());
* $oMyChange->Set("userinfo", 'this is done by ... for ...');
* $iChangeId = $oMyChange->DBInsert();
*/
*
* @see SetCurrentChange to specify a CMDBObject instance instead
*
* @param string $sInfo
*/
public static function SetTrackInfo($sInfo)
{
self::$m_sInfo = $sInfo;
@@ -138,8 +148,13 @@ abstract class CMDBObject extends DBObject
/**
* Provides information about the origin of the change
* @param $sOrigin String: one of: interactive, csv-interactive, csv-import.php, webservice-soap, webservice-rest, syncho-data-source, email-processing, custom-extension
*/
*
* @see SetTrackInfo
* @see SetCurrentChange to specify a CMDBObject instance instead
*
* @param $sOrigin String: one of: interactive, csv-interactive, csv-import.php, webservice-soap, webservice-rest, syncho-data-source,
* email-processing, custom-extension
*/
public static function SetTrackOrigin($sOrigin)
{
self::$m_sOrigin = $sOrigin;

View File

@@ -244,8 +244,14 @@ function CronExec($oP, $aProcesses, $bVerbose)
foreach ($aProcesses as $oProcess)
{
$sTaskClass = get_class($oProcess);
// N°3219 for each process will use a specific CMDBChange object with a specific track info
// Any BackgroundProcess can overrides this as needed
CMDBObject::SetCurrentChange(null);
CMDBObject::SetTrackInfo("Background task ($sTaskClass)");
CMDBObject::SetTrackOrigin(null);
if (!array_key_exists($sTaskClass, $aTasks))
{
// New entry, let's create a new BackgroundTask record, and plan the first execution