code cleanup

This commit is contained in:
Eric
2018-11-07 11:57:08 +01:00
parent a327b5fb5e
commit ed02e3522e
2 changed files with 45 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2010-2017 Combodo SARL
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -85,8 +85,12 @@ class ormStopWatch
/**
* Get the working elapsed time since the start of the stop watch
* even if it is currently running
* @param oAttDef AttributeDefinition Attribute hosting the stop watch
* @param oObject Hosting object (used for query parameters)
*
* @param AttributeDefinition oAttDef Attribute hosting the stop watch
* @param Object oObject Hosting object (used for query parameters)
*
* @return int|mixed
* @throws \CoreException
*/
public function GetElapsedTime($oAttDef, $oObject)
{
@@ -260,6 +264,16 @@ class ormStopWatch
return $iRet;
}
/**
* @param $oObject
* @param $oAttDef
* @param $iPercent
* @param $iStartTime
* @param $iDurationSec
*
* @return mixed
* @throws \CoreException
*/
protected function ComputeDeadline($oObject, $oAttDef, $iPercent, $iStartTime, $iDurationSec)
{
$sWorkingTimeComputer = $oAttDef->Get('working_time_computing');
@@ -267,11 +281,6 @@ class ormStopWatch
{
$sWorkingTimeComputer = class_exists('SLAComputation') ? 'SLAComputation' : 'DefaultWorkingTimeComputer';
}
$aCallSpec = array($sWorkingTimeComputer, '__construct');
if (!is_callable($aCallSpec))
{
//throw new CoreException("Pas de constructeur pour $sWorkingTimeComputer!");
}
$oComputer = new $sWorkingTimeComputer();
$aCallSpec = array($oComputer, 'GetDeadline');
if (!is_callable($aCallSpec))
@@ -285,6 +294,15 @@ class ormStopWatch
return $iRet;
}
/**
* @param $oObject
* @param $oAttDef
* @param $iStartTime
* @param $iEndTime
*
* @return mixed
* @throws \CoreException
*/
protected function ComputeDuration($oObject, $oAttDef, $iStartTime, $iEndTime)
{
$sWorkingTimeComputer = $oAttDef->Get('working_time_computing');
@@ -398,7 +416,7 @@ class ormStopWatch
$aThresholdData['triggered'] = false;
$aThresholdData['overrun'] = null;
}
else
// else
{
// The new threshold is in the past
// Note: the overrun can be wrong, but the correct algorithm to compute
@@ -558,7 +576,7 @@ class CheckStopWatchThresholds implements iBackgroundProcess
CMDBObject::SetTrackInfo("Automatic - threshold triggered");
$oMyChange = CMDBObject::GetCurrentChange();
$oObj->DBUpdateTracked($oMyChange, true /*skip security*/);
$oObj->DBUpdateTracked($oMyChange);
}
// Activate any existing trigger

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2010-2014 Combodo SARL
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -30,24 +30,28 @@
*/
class SLAComputation implements iWorkingTimeComputer
{
/**
* @var \SLAComputationAddOnAPI
*/
protected static $m_oAddOn;
/**
* Generic "extensibility" method: select which extension is actually used
*
* @param $sClassName string The name of the class (derived from SLAComputationAddOnAPI) to use
*
* @return void
* @throws \CoreException
*/
public static function SelectModule($sClassName)
{
if (!class_exists($sClassName))
{
throw new CoreException("Could not select this module, '$sClassName' in not a valid class name");
return;
}
if (($sClassName != 'SLAComputationAddOnAPI') && !is_subclass_of($sClassName, 'SLAComputationAddOnAPI'))
{
throw new CoreException("Could not select this module, the class '$sClassName' is not derived from SLAComputationAddOnAPI (parent class:".get_parent_class($sClassName)." )");
return;
}
self::$m_oAddOn = new $sClassName;
self::$m_oAddOn->Init();
@@ -70,10 +74,13 @@ class SLAComputation implements iWorkingTimeComputer
/**
* Get the date/time corresponding to a given delay in the future from the present
* considering only the valid (open) hours for a specified object
* @param $oObject DBObject The object for which to compute the deadline
*
* @param $oObject Ticket The object for which to compute the deadline
* @param $iDuration integer The duration (in seconds) in the future
* @param $oStartDate DateTime The starting point for the computation
*
* @return DateTime The date/time for the deadline
* @throws \Exception
*/
public function GetDeadline($oObject, $iDuration, DateTime $oStartDate)
{
@@ -90,11 +97,14 @@ class SLAComputation implements iWorkingTimeComputer
}
/**
* Get duration (considering only open hours) elapsed bewteen two given DateTimes
* @param $oObject DBObject The object for which to compute the duration
* Get duration (considering only open hours) elapsed between two given DateTimes
*
* @param $oObject Ticket The object for which to compute the duration
* @param $oStartDate DateTime The starting point for the computation (default = now)
* @param $oEndDate DateTime The ending point for the computation (default = now)
*
* @return integer The duration (number of seconds) of open hours elapsed between the two dates
* @throws \Exception
*/
public function GetOpenDuration($oObject, DateTime $oStartDate, DateTime $oEndDate)
{
@@ -149,7 +159,7 @@ class SLAComputationAddOnAPI
}
/**
* Get duration (considering only open hours) elapsed bewteen two given DateTimes
* Get duration (considering only open hours) elapsed between two given DateTimes
* @param $oTicket Ticket The ticket for which to compute the duration
* @param $oStartDate DateTime The starting point for the computation (default = now)
* @param $oEndDate DateTime The ending point for the computation (default = now)