Code cleanup

This commit is contained in:
Eric
2018-09-24 11:48:30 +02:00
parent 55036511ab
commit e9ecd89cda
4 changed files with 266 additions and 91 deletions

View File

@@ -1,6 +1,7 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<option name="LINE_SEPARATOR" value="&#10;" /> <option name="LINE_SEPARATOR" value="&#10;" />
<option name="RIGHT_MARGIN" value="320" />
<HTMLCodeStyleSettings> <HTMLCodeStyleSettings>
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="html,body,thead,tbody,tfoot,script,style" /> <option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="html,body,thead,tbody,tfoot,script,style" />
<option name="HTML_DO_NOT_ALIGN_CHILDREN_OF_MIN_LINES" value="4" /> <option name="HTML_DO_NOT_ALIGN_CHILDREN_OF_MIN_LINES" value="4" />

View File

@@ -19,6 +19,7 @@
<inspection_tool class="PhpUnusedParameterInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true"> <inspection_tool class="PhpUnusedParameterInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="DONT_REPORT_ABSTRACT_CLASS" value="true" /> <option name="DONT_REPORT_ABSTRACT_CLASS" value="true" />
</inspection_tool> </inspection_tool>
<inspection_tool class="SqlDialectInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SqlNoDataSourceInspection" enabled="false" level="WARNING" enabled_by_default="false" /> <inspection_tool class="SqlNoDataSourceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
</profile> </profile>
</component> </component>

View File

@@ -1,5 +1,5 @@
<?php <?php
// Copyright (C) 2010-2017 Combodo SARL // Copyright (C) 2010-2018 Combodo SARL
// //
// This file is part of iTop. // This file is part of iTop.
// //
@@ -292,6 +292,7 @@ abstract class DBObject implements iDisplay
} }
else else
{ {
/** @var \AttributeCustomFields $oAttDef */
$value = $oAttDef->ReadValue($this); $value = $oAttDef->ReadValue($this);
$bIsDefined = true; $bIsDefined = true;
} }
@@ -370,6 +371,7 @@ abstract class DBObject implements iDisplay
// Setting an external key with a whole object (instead of just an ID) // Setting an external key with a whole object (instead of just an ID)
// let's initialize also the external fields that depend on it // let's initialize also the external fields that depend on it
// (useful when building objects in memory and not from a query) // (useful when building objects in memory and not from a query)
/** @var \AttributeExternalKey $oAttDef */
if ( (get_class($value) != $oAttDef->GetTargetClass()) && (!is_subclass_of($value, $oAttDef->GetTargetClass()))) if ( (get_class($value) != $oAttDef->GetTargetClass()) && (!is_subclass_of($value, $oAttDef->GetTargetClass())))
{ {
throw new CoreUnexpectedValue("Trying to set the value of '$sAttCode', to an object of class '".get_class($value)."', whereas it's an ExtKey to '".$oAttDef->GetTargetClass()."'. Ignored"); throw new CoreUnexpectedValue("Trying to set the value of '$sAttCode', to an object of class '".get_class($value)."', whereas it's an ExtKey to '".$oAttDef->GetTargetClass()."'. Ignored");
@@ -377,8 +379,10 @@ abstract class DBObject implements iDisplay
foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sCode => $oDef) foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sCode => $oDef)
{ {
/** @var \AttributeExternalField $oDef */
if ($oDef->IsExternalField() && ($oDef->GetKeyAttCode() == $sAttCode)) if ($oDef->IsExternalField() && ($oDef->GetKeyAttCode() == $sAttCode))
{ {
/** @var \DBObject $value */
$this->m_aCurrValues[$sCode] = $value->Get($oDef->GetExtAttCode()); $this->m_aCurrValues[$sCode] = $value->Get($oDef->GetExtAttCode());
$this->m_aLoadedAtt[$sCode] = true; $this->m_aLoadedAtt[$sCode] = true;
} }
@@ -390,6 +394,7 @@ abstract class DBObject implements iDisplay
// Invalidate the corresponding fields so that they get reloaded in case they are needed (See Get()) // Invalidate the corresponding fields so that they get reloaded in case they are needed (See Get())
foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sCode => $oDef) foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sCode => $oDef)
{ {
/** @var \AttributeExternalKey $oDef */
if ($oDef->IsExternalField() && ($oDef->GetKeyAttCode() == $sAttCode)) if ($oDef->IsExternalField() && ($oDef->GetKeyAttCode() == $sAttCode))
{ {
$this->m_aCurrValues[$sCode] = $this->GetDefaultValue($sCode); $this->m_aCurrValues[$sCode] = $this->GetDefaultValue($sCode);
@@ -411,6 +416,7 @@ abstract class DBObject implements iDisplay
foreach (MetaModel::ListMetaAttributes(get_class($this), $sAttCode) as $sMetaAttCode => $oMetaAttDef) foreach (MetaModel::ListMetaAttributes(get_class($this), $sAttCode) as $sMetaAttCode => $oMetaAttDef)
{ {
/** @var \AttributeMetaEnum $oMetaAttDef */
$this->_Set($sMetaAttCode, $oMetaAttDef->MapValue($this)); $this->_Set($sMetaAttCode, $oMetaAttDef->MapValue($this));
} }
@@ -459,11 +465,13 @@ abstract class DBObject implements iDisplay
$oExtFieldAtt = MetaModel::FindExternalField(get_class($this), $sExtKeyAttCode, $sRemoteAttCode); $oExtFieldAtt = MetaModel::FindExternalField(get_class($this), $sExtKeyAttCode, $sRemoteAttCode);
if (!is_null($oExtFieldAtt)) if (!is_null($oExtFieldAtt))
{ {
/** @var \AttributeExternalField $oExtFieldAtt */
return $this->GetStrict($oExtFieldAtt->GetCode()); return $this->GetStrict($oExtFieldAtt->GetCode());
} }
else else
{ {
$oKeyAttDef = MetaModel::GetAttributeDef(get_class($this), $sExtKeyAttCode); $oKeyAttDef = MetaModel::GetAttributeDef(get_class($this), $sExtKeyAttCode);
/** @var \AttributeExternalKey $oKeyAttDef */
$sRemoteClass = $oKeyAttDef->GetTargetClass(); $sRemoteClass = $oKeyAttDef->GetTargetClass();
$oRemoteObj = MetaModel::GetObject($sRemoteClass, $this->GetStrict($sExtKeyAttCode), false); $oRemoteObj = MetaModel::GetObject($sRemoteClass, $this->GetStrict($sExtKeyAttCode), false);
if (is_null($oRemoteObj)) if (is_null($oRemoteObj))
@@ -520,6 +528,7 @@ abstract class DBObject implements iDisplay
// Let's get the object and compute all of the corresponding attributes // Let's get the object and compute all of the corresponding attributes
// (i.e not only the requested attribute) // (i.e not only the requested attribute)
// //
/** @var \AttributeExternalField $oAttDef */
$sExtKeyAttCode = $oAttDef->GetKeyAttCode(); $sExtKeyAttCode = $oAttDef->GetKeyAttCode();
if (($iRemote = $this->Get($sExtKeyAttCode)) && ($iRemote > 0)) // Objects in memory have negative IDs if (($iRemote = $this->Get($sExtKeyAttCode)) && ($iRemote > 0)) // Objects in memory have negative IDs
@@ -528,6 +537,7 @@ abstract class DBObject implements iDisplay
// Note: "allow all data" must be enabled because the external fields are always visible // Note: "allow all data" must be enabled because the external fields are always visible
// to the current user even if this is not the case for the remote object // to the current user even if this is not the case for the remote object
// This is consistent with the behavior of the lists // This is consistent with the behavior of the lists
/** @var \AttributeExternalKey $oExtKeyAttDef */
$oRemote = MetaModel::GetObject($oExtKeyAttDef->GetTargetClass(), $iRemote, true, true); $oRemote = MetaModel::GetObject($oExtKeyAttDef->GetTargetClass(), $iRemote, true, true);
} }
else else
@@ -537,6 +547,7 @@ abstract class DBObject implements iDisplay
foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sCode => $oDef) foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sCode => $oDef)
{ {
/** @var \AttributeExternalField $oDef */
if ($oDef->IsExternalField() && ($oDef->GetKeyAttCode() == $sExtKeyAttCode)) if ($oDef->IsExternalField() && ($oDef->GetKeyAttCode() == $sExtKeyAttCode))
{ {
if ($oRemote) if ($oRemote)
@@ -665,6 +676,7 @@ abstract class DBObject implements iDisplay
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
if ($oAttDef->IsExternalField()) if ($oAttDef->IsExternalField())
{ {
/** @var \AttributeExternalField $oAttDef */
$sTargetClass = $oAttDef->GetTargetClass(); $sTargetClass = $oAttDef->GetTargetClass();
$objkey = $this->Get($oAttDef->GetKeyAttCode()); $objkey = $this->Get($oAttDef->GetKeyAttCode());
// Note: "allow all data" must be enabled because the external fields are always visible // Note: "allow all data" must be enabled because the external fields are always visible
@@ -719,6 +731,7 @@ abstract class DBObject implements iDisplay
if ($oAtt->IsExternalKey(EXTKEY_ABSOLUTE)) if ($oAtt->IsExternalKey(EXTKEY_ABSOLUTE))
{ {
//return $this->Get($sAttCode.'_friendlyname'); //return $this->Get($sAttCode.'_friendlyname');
/** @var \AttributeExternalKey $oAtt */
$sTargetClass = $oAtt->GetTargetClass(EXTKEY_ABSOLUTE); $sTargetClass = $oAtt->GetTargetClass(EXTKEY_ABSOLUTE);
$iTargetKey = $this->Get($sAttCode); $iTargetKey = $this->Get($sAttCode);
if ($iTargetKey < 0) if ($iTargetKey < 0)
@@ -746,6 +759,7 @@ abstract class DBObject implements iDisplay
if ($oAtt->IsExternalKey()) if ($oAtt->IsExternalKey())
{ {
/** @var \AttributeExternalKey $oAtt */
$sTargetClass = $oAtt->GetTargetClass(); $sTargetClass = $oAtt->GetTargetClass();
if ($this->IsNew()) if ($this->IsNew())
{ {
@@ -1215,6 +1229,7 @@ abstract class DBObject implements iDisplay
{ {
if (!MetaModel::SkipCheckExtKeys()) if (!MetaModel::SkipCheckExtKeys())
{ {
/** @var \AttributeExternalKey $oAtt */
$sTargetClass = $oAtt->GetTargetClass(); $sTargetClass = $oAtt->GetTargetClass();
$oTargetObj = MetaModel::GetObject($sTargetClass, $toCheck, false /*must be found*/, true /*allow all data*/); $oTargetObj = MetaModel::GetObject($sTargetClass, $toCheck, false /*must be found*/, true /*allow all data*/);
if (is_null($oTargetObj)) if (is_null($oTargetObj))
@@ -1310,7 +1325,7 @@ abstract class DBObject implements iDisplay
// Note: $aReasonInfo['name'] could be reported (the task owning the attribute) // Note: $aReasonInfo['name'] could be reported (the task owning the attribute)
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
$sAttLabel = $oAttDef->GetLabel(); $sAttLabel = $oAttDef->GetLabel();
foreach($aReasons as $aReasonInfo) if (!empty($aReasons))
{ {
// Todo: associate the attribute code with the error // Todo: associate the attribute code with the error
$this->m_aCheckIssues[] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $sAttLabel); $this->m_aCheckIssues[] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $sAttLabel);
@@ -1347,6 +1362,11 @@ abstract class DBObject implements iDisplay
// check if it is allowed to delete the existing object from the database // check if it is allowed to delete the existing object from the database
// a displayable error is returned // a displayable error is returned
/**
* @param \DeletionPlan $oDeletionPlan
*
* @throws \CoreException
*/
protected function DoCheckToDelete(&$oDeletionPlan) protected function DoCheckToDelete(&$oDeletionPlan)
{ {
$this->m_aDeleteIssues = array(); // Ok $this->m_aDeleteIssues = array(); // Ok
@@ -1360,6 +1380,7 @@ abstract class DBObject implements iDisplay
{ {
$oDeletionPlan->AddToDelete($oReplica, DEL_SILENT); $oDeletionPlan->AddToDelete($oReplica, DEL_SILENT);
} }
/** @var \SynchroDataSource $oDataSource */
$oDataSource = $aSourceData['source']; $oDataSource = $aSourceData['source'];
if ($oDataSource->GetKey() == SynchroExecution::GetCurrentTaskId()) if ($oDataSource->GetKey() == SynchroExecution::GetCurrentTaskId())
{ {
@@ -1397,7 +1418,12 @@ abstract class DBObject implements iDisplay
} }
} }
public function CheckToDelete(&$oDeletionPlan) /**
* @param \DeletionPlan $oDeletionPlan
*
* @return bool
*/
public function CheckToDelete(&$oDeletionPlan)
{ {
$this->MakeDeletionPlan($oDeletionPlan); $this->MakeDeletionPlan($oDeletionPlan);
$oDeletionPlan->ComputeResults(); $oDeletionPlan->ComputeResults();
@@ -1481,6 +1507,11 @@ abstract class DBObject implements iDisplay
return (count($aChanges) != 0); return (count($aChanges) != 0);
} }
/**
* @param \DBObject $oSibling
*
* @return bool
*/
public function Equals($oSibling) public function Equals($oSibling)
{ {
if (get_class($oSibling) != get_class($this)) if (get_class($oSibling) != get_class($this))
@@ -1545,6 +1576,7 @@ abstract class DBObject implements iDisplay
if ($oAttDef->LoadFromDB()) continue; if ($oAttDef->LoadFromDB()) continue;
if (!array_key_exists($sAttCode, $this->m_aTouchedAtt)) continue; if (!array_key_exists($sAttCode, $this->m_aTouchedAtt)) continue;
if (array_key_exists($sAttCode, $this->m_aModifiedAtt) && ($this->m_aModifiedAtt[$sAttCode] == false)) continue; if (array_key_exists($sAttCode, $this->m_aModifiedAtt) && ($this->m_aModifiedAtt[$sAttCode] == false)) continue;
/** @var \AttributeCustomFields $oAttDef */
$oAttDef->WriteValue($this, $this->m_aCurrValues[$sAttCode]); $oAttDef->WriteValue($this, $this->m_aCurrValues[$sAttCode]);
} }
} }
@@ -1568,7 +1600,7 @@ abstract class DBObject implements iDisplay
{ {
$sValues = implode(', ', self::$m_aBulkInsertItems[$sClass][$sTable]); $sValues = implode(', ', self::$m_aBulkInsertItems[$sClass][$sTable]);
$sInsertSQL = "INSERT INTO `$sTable` ($sColumns) VALUES $sValues"; $sInsertSQL = "INSERT INTO `$sTable` ($sColumns) VALUES $sValues";
$iNewKey = CMDBSource::InsertInto($sInsertSQL); CMDBSource::InsertInto($sInsertSQL);
} }
} }
@@ -1582,7 +1614,7 @@ abstract class DBObject implements iDisplay
{ {
$sTable = MetaModel::DBGetTable($sTableClass); $sTable = MetaModel::DBGetTable($sTableClass);
// Abstract classes or classes having no specific attribute do not have an associated table // Abstract classes or classes having no specific attribute do not have an associated table
if ($sTable == '') return; if ($sTable == '') return false;
$sClass = get_class($this); $sClass = get_class($this);
@@ -1758,6 +1790,7 @@ abstract class DBObject implements iDisplay
$oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObjectCreate AS t WHERE t.target_class IN ('$sClassList')")); $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObjectCreate AS t WHERE t.target_class IN ('$sClassList')"));
while ($oTrigger = $oSet->Fetch()) while ($oTrigger = $oSet->Fetch())
{ {
/** @var \Trigger $oTrigger */
$oTrigger->DoActivate($this->ToArgs('this')); $oTrigger->DoActivate($this->ToArgs('this'));
} }
@@ -1781,8 +1814,6 @@ abstract class DBObject implements iDisplay
// Abstract classes or classes having no specific attribute do not have an associated table // Abstract classes or classes having no specific attribute do not have an associated table
if ($sTable == '') return; if ($sTable == '') return;
$sClass = get_class($this);
// fields in first array, values in the second // fields in first array, values in the second
$aFieldsToWrite = array(); $aFieldsToWrite = array();
$aValuesToWrite = array(); $aValuesToWrite = array();
@@ -1805,6 +1836,7 @@ abstract class DBObject implements iDisplay
$value = $this->m_aCurrValues[$sAttCode]; $value = $this->m_aCurrValues[$sAttCode];
if ($oAttDef->IsExternalKey()) if ($oAttDef->IsExternalKey())
{ {
/** @var \AttributeExternalKey $oAttDef */
$sTargetClass = $oAttDef->GetTargetClass(); $sTargetClass = $oAttDef->GetTargetClass();
if (is_array($aAuthorizedExtKeys)) if (is_array($aAuthorizedExtKeys))
{ {
@@ -1826,7 +1858,7 @@ abstract class DBObject implements iDisplay
} }
} }
if (count($aValuesToWrite) == 0) return false; if (count($aValuesToWrite) == 0) return;
if (count($aHierarchicalKeys) > 0) if (count($aHierarchicalKeys) > 0)
{ {
@@ -1919,7 +1951,7 @@ abstract class DBObject implements iDisplay
$sKey = get_class($this).'::'.$this->GetKey(); $sKey = get_class($this).'::'.$this->GetKey();
if (array_key_exists($sKey, $aUpdateReentrance)) if (array_key_exists($sKey, $aUpdateReentrance))
{ {
return; return false;
} }
$aUpdateReentrance[$sKey] = true; $aUpdateReentrance[$sKey] = true;
@@ -2125,6 +2157,7 @@ abstract class DBObject implements iDisplay
{ {
// Update the left & right indexes for each hierarchical key // Update the left & right indexes for each hierarchical key
$sTable = $sTable = MetaModel::DBGetTable(get_class($this), $sAttCode); $sTable = $sTable = MetaModel::DBGetTable(get_class($this), $sAttCode);
/** @var \AttributeHierarchicalKey $oAttDef */
$sSQL = "SELECT `".$oAttDef->GetSQLRight()."` AS `right`, `".$oAttDef->GetSQLLeft()."` AS `left` FROM `$sTable` WHERE id=".CMDBSource::Quote($this->m_iKey); $sSQL = "SELECT `".$oAttDef->GetSQLRight()."` AS `right`, `".$oAttDef->GetSQLLeft()."` AS `left` FROM `$sTable` WHERE id=".CMDBSource::Quote($this->m_iKey);
$aRes = CMDBSource::QueryToArray($sSQL); $aRes = CMDBSource::QueryToArray($sSQL);
$iMyLeft = $aRes[0]['left']; $iMyLeft = $aRes[0]['left'];
@@ -2147,6 +2180,7 @@ abstract class DBObject implements iDisplay
} }
elseif (!$oAttDef->LoadFromDB()) elseif (!$oAttDef->LoadFromDB())
{ {
/** @var \AttributeCustomFields $oAttDef */
$oAttDef->DeleteValue($this); $oAttDef->DeleteValue($this);
} }
} }
@@ -2195,6 +2229,7 @@ abstract class DBObject implements iDisplay
{ {
foreach ($aToDelete as $iId => $aData) foreach ($aToDelete as $iId => $aData)
{ {
/** @var \DBObject $oToDelete */
$oToDelete = $aData['to_delete']; $oToDelete = $aData['to_delete'];
// The deletion based on a deletion plan should not be done for each oject if the deletion plan is common (Trac #457) // The deletion based on a deletion plan should not be done for each oject if the deletion plan is common (Trac #457)
// because for each object we would try to update all the preceding ones... that are already deleted // because for each object we would try to update all the preceding ones... that are already deleted
@@ -2213,6 +2248,7 @@ abstract class DBObject implements iDisplay
foreach ($aToUpdate as $iId => $aData) foreach ($aToUpdate as $iId => $aData)
{ {
$oToUpdate = $aData['to_reset']; $oToUpdate = $aData['to_reset'];
/** @var \DBObject $oToUpdate */
foreach ($aData['attributes'] as $sRemoteExtKey => $aRemoteAttDef) foreach ($aData['attributes'] as $sRemoteExtKey => $aRemoteAttDef)
{ {
$oToUpdate->Set($sRemoteExtKey, $aData['values'][$sRemoteExtKey]); $oToUpdate->Set($sRemoteExtKey, $aData['values'][$sRemoteExtKey]);
@@ -2243,6 +2279,22 @@ abstract class DBObject implements iDisplay
return MetaModel::EnumTransitions(get_class($this), $sState); return MetaModel::EnumTransitions(get_class($this), $sState);
} }
/**
* Designed as an action to be called when a stop watch threshold times out
*/
public function ResetStopWatch($sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
if (!$oAttDef instanceof AttributeStopWatch)
{
throw new CoreException("Invalid stop watch id: '$sAttCode'");
}
$oSW = $this->Get($sAttCode);
$oSW->Reset($this, $oAttDef);
$this->Set($sAttCode, $oSW);
return true;
}
/** /**
* Designed as an action to be called when a stop watch threshold times out * Designed as an action to be called when a stop watch threshold times out
* or from within the framework * or from within the framework
@@ -2306,24 +2358,24 @@ abstract class DBObject implements iDisplay
switch($sParamType) switch($sParamType)
{ {
case 'int': case 'int':
$value = (int)$aDefinition['value']; $value = (int)$aDefinition['value'];
break; break;
case 'float': case 'float':
$value = (float)$aDefinition['value']; $value = (float)$aDefinition['value'];
break; break;
case 'bool': case 'bool':
$value = (bool)$aDefinition['value']; $value = (bool)$aDefinition['value'];
break; break;
case 'reference': case 'reference':
$value = ${$aDefinition['value']}; $value = ${$aDefinition['value']};
break; break;
case 'string': case 'string':
default: default:
$value = (string)$aDefinition['value']; $value = (string)$aDefinition['value'];
} }
$aParams[] = $value; $aParams[] = $value;
} }
@@ -2370,12 +2422,14 @@ abstract class DBObject implements iDisplay
$oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnStateLeave AS t WHERE t.target_class IN ('$sClassList') AND t.state='$sPreviousState'")); $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnStateLeave AS t WHERE t.target_class IN ('$sClassList') AND t.state='$sPreviousState'"));
while ($oTrigger = $oSet->Fetch()) while ($oTrigger = $oSet->Fetch())
{ {
/** @var \Trigger $oTrigger */
$oTrigger->DoActivate($this->ToArgs('this')); $oTrigger->DoActivate($this->ToArgs('this'));
} }
$oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnStateEnter AS t WHERE t.target_class IN ('$sClassList') AND t.state='$sNewState'")); $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnStateEnter AS t WHERE t.target_class IN ('$sClassList') AND t.state='$sNewState'"));
while ($oTrigger = $oSet->Fetch()) while ($oTrigger = $oSet->Fetch())
{ {
/** @var \Trigger $oTrigger */
$oTrigger->DoActivate($this->ToArgs('this')); $oTrigger->DoActivate($this->ToArgs('this'));
} }
} }
@@ -2383,22 +2437,6 @@ abstract class DBObject implements iDisplay
return $bSuccess; return $bSuccess;
} }
/**
* Designed as an action to be called when a stop watch threshold times out
*/
public function ResetStopWatch($sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
if (!$oAttDef instanceof AttributeStopWatch)
{
throw new CoreException("Invalid stop watch id: '$sAttCode'");
}
$oSW = $this->Get($sAttCode);
$oSW->Reset($this, $oAttDef);
$this->Set($sAttCode, $oSW);
return true;
}
/** /**
* Lifecycle action: Recover the default value (aka when an object is being created) * Lifecycle action: Recover the default value (aka when an object is being created)
*/ */
@@ -2441,6 +2479,7 @@ abstract class DBObject implements iDisplay
{ {
if ($oAttDef->IsExternalKey()) if ($oAttDef->IsExternalKey())
{ {
/** @var \AttributeExternalKey $oAttDef */
if ($oAttDef->GetTargetClass() != 'User') if ($oAttDef->GetTargetClass() != 'User')
{ {
throw new Exception("SetCurrentUser: the attribute $sAttCode must be an external key to 'User', found '".$oAttDef->GetTargetClass()."'"); throw new Exception("SetCurrentUser: the attribute $sAttCode must be an external key to 'User', found '".$oAttDef->GetTargetClass()."'");
@@ -2474,6 +2513,7 @@ abstract class DBObject implements iDisplay
{ {
if ($oAttDef->IsExternalKey()) if ($oAttDef->IsExternalKey())
{ {
/** @var \AttributeExternalKey $oAttDef */
if (!MetaModel::IsParentClass($oAttDef->GetTargetClass(), 'Person')) if (!MetaModel::IsParentClass($oAttDef->GetTargetClass(), 'Person'))
{ {
throw new Exception("SetCurrentContact: the attribute $sAttCode must be an external key to 'Person' or any other class above 'Person', found '".$oAttDef->GetTargetClass()."'"); throw new Exception("SetCurrentContact: the attribute $sAttCode must be an external key to 'Person' or any other class above 'Person', found '".$oAttDef->GetTargetClass()."'");
@@ -2665,6 +2705,16 @@ abstract class DBObject implements iDisplay
/** /**
* Common to the recording of link set changes (add/remove/modify) * Common to the recording of link set changes (add/remove/modify)
*
* @param $iLinkSetOwnerId
* @param \AttributeLinkedSet $oLinkSet
* @param $sChangeOpClass
* @param array $aOriginalValues
*
* @return \DBObject|null
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
*/ */
private function PrepareChangeOpLinkSet($iLinkSetOwnerId, $oLinkSet, $sChangeOpClass, $aOriginalValues = null) private function PrepareChangeOpLinkSet($iLinkSetOwnerId, $oLinkSet, $sChangeOpClass, $aOriginalValues = null)
{ {
@@ -2684,8 +2734,10 @@ abstract class DBObject implements iDisplay
if ($oLinkSet->IsIndirect()) if ($oLinkSet->IsIndirect())
{ {
// The "item" is on the other end (N-N links) // The "item" is on the other end (N-N links)
/** @var \AttributeLinkedSetIndirect $oLinkSet */
$sExtKeyToRemote = $oLinkSet->GetExtKeyToRemote(); $sExtKeyToRemote = $oLinkSet->GetExtKeyToRemote();
$oExtKeyToRemote = MetaModel::GetAttributeDef(get_class($this), $sExtKeyToRemote); $oExtKeyToRemote = MetaModel::GetAttributeDef(get_class($this), $sExtKeyToRemote);
/** @var \AttributeExternalKey $oExtKeyToRemote */
$sItemClass = $oExtKeyToRemote->GetTargetClass(); $sItemClass = $oExtKeyToRemote->GetTargetClass();
if ($aOriginalValues) if ($aOriginalValues)
{ {
@@ -2731,9 +2783,9 @@ abstract class DBObject implements iDisplay
*/ */
private function RecordLinkSetListChange($bAdd = true) private function RecordLinkSetListChange($bAdd = true)
{ {
$aForwardChangeTracking = MetaModel::GetTrackForwardExternalKeys(get_class($this));
foreach(MetaModel::GetTrackForwardExternalKeys(get_class($this)) as $sExtKeyAttCode => $oLinkSet) foreach(MetaModel::GetTrackForwardExternalKeys(get_class($this)) as $sExtKeyAttCode => $oLinkSet)
{ {
/** @var \AttributeLinkedSet $oLinkSet */
if (($oLinkSet->GetTrackingLevel() & LINKSET_TRACKING_LIST) == 0) continue; if (($oLinkSet->GetTrackingLevel() & LINKSET_TRACKING_LIST) == 0) continue;
$iLinkSetOwnerId = $this->Get($sExtKeyAttCode); $iLinkSetOwnerId = $this->Get($sExtKeyAttCode);
@@ -2748,7 +2800,7 @@ abstract class DBObject implements iDisplay
{ {
$oMyChangeOp->Set("type", "removed"); $oMyChangeOp->Set("type", "removed");
} }
$iId = $oMyChangeOp->DBInsertNoReload(); $oMyChangeOp->DBInsertNoReload();
} }
} }
} }
@@ -2765,12 +2817,12 @@ abstract class DBObject implements iDisplay
protected function RecordAttChanges(array $aValues, array $aOrigValues) protected function RecordAttChanges(array $aValues, array $aOrigValues)
{ {
$aForwardChangeTracking = MetaModel::GetTrackForwardExternalKeys(get_class($this));
foreach(MetaModel::GetTrackForwardExternalKeys(get_class($this)) as $sExtKeyAttCode => $oLinkSet) foreach(MetaModel::GetTrackForwardExternalKeys(get_class($this)) as $sExtKeyAttCode => $oLinkSet)
{ {
if (array_key_exists($sExtKeyAttCode, $aValues)) if (array_key_exists($sExtKeyAttCode, $aValues))
{ {
/** @var \AttributeLinkedSet $oLinkSet */
if (($oLinkSet->GetTrackingLevel() & LINKSET_TRACKING_LIST) == 0) continue; if (($oLinkSet->GetTrackingLevel() & LINKSET_TRACKING_LIST) == 0) continue;
// Keep track of link added/removed // Keep track of link added/removed
@@ -2802,7 +2854,7 @@ abstract class DBObject implements iDisplay
if ($oMyChangeOp) if ($oMyChangeOp)
{ {
$oMyChangeOp->Set("link_id", $this->GetKey()); $oMyChangeOp->Set("link_id", $this->GetKey());
$iId = $oMyChangeOp->DBInsertNoReload(); $oMyChangeOp->DBInsertNoReload();
} }
} }
} }
@@ -2931,6 +2983,7 @@ abstract class DBObject implements iDisplay
foreach($aExtKeys as $sExtKeyAttCode => $oExtKeyAttDef) foreach($aExtKeys as $sExtKeyAttCode => $oExtKeyAttDef)
{ {
// skip if this external key is behind an external field // skip if this external key is behind an external field
/** @var \AttributeDefinition $oExtKeyAttDef */
if (!$oExtKeyAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) continue; if (!$oExtKeyAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) continue;
$oSearch = new DBObjectSearch($sRemoteClass); $oSearch = new DBObjectSearch($sRemoteClass);
@@ -2952,6 +3005,13 @@ abstract class DBObject implements iDisplay
return $aDependentObjects; return $aDependentObjects;
} }
/**
* @param \DeletionPlan $oDeletionPlan
* @param array $aVisited
* @param int $iDeleteOption
*
* @throws \CoreException
*/
private function MakeDeletionPlan(&$oDeletionPlan, $aVisited = array(), $iDeleteOption = null) private function MakeDeletionPlan(&$oDeletionPlan, $aVisited = array(), $iDeleteOption = null)
{ {
static $iLoopTimeLimit = null; static $iLoopTimeLimit = null;
@@ -2962,7 +3022,7 @@ abstract class DBObject implements iDisplay
$sClass = get_class($this); $sClass = get_class($this);
$iThisId = $this->GetKey(); $iThisId = $this->GetKey();
$iDeleteOption = $oDeletionPlan->AddToDelete($this, $iDeleteOption); $oDeletionPlan->AddToDelete($this, $iDeleteOption);
if (array_key_exists($sClass, $aVisited)) if (array_key_exists($sClass, $aVisited))
{ {
@@ -2994,13 +3054,14 @@ abstract class DBObject implements iDisplay
{ {
set_time_limit($iLoopTimeLimit); set_time_limit($iLoopTimeLimit);
/** @var \AttributeExternalKey $oAttDef */
$oAttDef = $aData['attribute']; $oAttDef = $aData['attribute'];
$iDeletePropagationOption = $oAttDef->GetDeletionPropagationOption(); $iDeletePropagationOption = $oAttDef->GetDeletionPropagationOption();
/** @var \DBObjectSet $oDepSet */
$oDepSet = $aData['objects']; $oDepSet = $aData['objects'];
$oDepSet->Rewind(); $oDepSet->Rewind();
while ($oDependentObj = $oDepSet->fetch()) while ($oDependentObj = $oDepSet->fetch())
{ {
$iId = $oDependentObj->GetKey();
if ($oAttDef->IsNullAllowed()) if ($oAttDef->IsNullAllowed())
{ {
// Optional external key, list to reset // Optional external key, list to reset
@@ -3032,8 +3093,9 @@ abstract class DBObject implements iDisplay
* Use GetSynchroData instead * Use GetSynchroData instead
* *
* Get all the synchro replica related to this object * Get all the synchro replica related to this object
* @param none *
* @return DBObjectSet Set with two columns: R=SynchroReplica S=SynchroDataSource * @return DBObjectSet Set with two columns: R=SynchroReplica S=SynchroDataSource
* @throws \OQLException
*/ */
public function GetMasterReplica() public function GetMasterReplica()
{ {
@@ -3044,11 +3106,15 @@ abstract class DBObject implements iDisplay
/** /**
* Get all the synchro data related to this object * Get all the synchro data related to this object
* @param none *
* @return array of data_source_id => array * @return array of data_source_id => array
* 'source' => $oSource, * 'source' => $oSource,
* 'attributes' => array of $oSynchroAttribute * 'attributes' => array of $oSynchroAttribute
* 'replica' => array of $oReplica (though only one should exist, misuse of the data sync can have this consequence) * 'replica' => array of $oReplica (though only one should exist, misuse of the data sync can have this consequence)
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
* @throws \OQLException
*/ */
public function GetSynchroData() public function GetSynchroData()
{ {
@@ -3059,6 +3125,7 @@ abstract class DBObject implements iDisplay
$this->m_aSynchroData = array(); $this->m_aSynchroData = array();
while($aData = $oReplicaSet->FetchAssoc()) while($aData = $oReplicaSet->FetchAssoc())
{ {
/** @var \DBObject[] $aData */
$iSourceId = $aData['datasource']->GetKey(); $iSourceId = $aData['datasource']->GetKey();
if (!array_key_exists($iSourceId, $this->m_aSynchroData)) if (!array_key_exists($iSourceId, $this->m_aSynchroData))
{ {
@@ -3066,6 +3133,7 @@ abstract class DBObject implements iDisplay
$oAttrSet = $aData['datasource']->Get('attribute_list'); $oAttrSet = $aData['datasource']->Get('attribute_list');
while($oSyncAttr = $oAttrSet->Fetch()) while($oSyncAttr = $oAttrSet->Fetch())
{ {
/** @var \DBObject $oSyncAttr */
$aAttributes[$oSyncAttr->Get('attcode')] = $oSyncAttr; $aAttributes[$oSyncAttr->Get('attcode')] = $oSyncAttr;
} }
$this->m_aSynchroData[$iSourceId] = array( $this->m_aSynchroData[$iSourceId] = array(
@@ -3096,10 +3164,12 @@ abstract class DBObject implements iDisplay
$oSource = $aSourceData['source']; $oSource = $aSourceData['source'];
if (array_key_exists($sAttCode, $aSourceData['attributes'])) if (array_key_exists($sAttCode, $aSourceData['attributes']))
{ {
/** @var \DBObject $oSyncAttr */
$oSyncAttr = $aSourceData['attributes'][$sAttCode]; $oSyncAttr = $aSourceData['attributes'][$sAttCode];
if (($oSyncAttr->Get('update') == 1) && ($oSyncAttr->Get('update_policy') == 'master_locked')) if (($oSyncAttr->Get('update') == 1) && ($oSyncAttr->Get('update_policy') == 'master_locked'))
{ {
$iFlags |= OPT_ATT_SLAVE; $iFlags |= OPT_ATT_SLAVE;
/** @var \SynchroDataSource $oSource */
$sUrl = $oSource->GetApplicationUrl($this, $oReplica); $sUrl = $oSource->GetApplicationUrl($this, $oReplica);
$aReason[] = array('name' => $oSource->GetName(), 'description' => $oSource->Get('description'), 'url_application' => $sUrl); $aReason[] = array('name' => $oSource->GetName(), 'description' => $oSource->Get('description'), 'url_application' => $sUrl);
} }
@@ -3184,7 +3254,9 @@ abstract class DBObject implements iDisplay
* *
* @param $iType string Any of the CALLBACK_x constants * @param $iType string Any of the CALLBACK_x constants
* @param $callback callable Call specification like a function name, or array('<class>', '<method>') or array($object, '<method>') * @param $callback callable Call specification like a function name, or array('<class>', '<method>') or array($object, '<method>')
* @param $aParameters Array Values that will be passed to the callback, after $this * @param $aParameters array Values that will be passed to the callback, after $this
*
* @throws \Exception
*/ */
public function RegisterCallback($iType, $callback, $aParameters = array()) public function RegisterCallback($iType, $callback, $aParameters = array())
{ {
@@ -3226,7 +3298,7 @@ abstract class DBObject implements iDisplay
* See ExecAction for the syntax and features of the scripted actions * See ExecAction for the syntax and features of the scripted actions
* *
* @param $aActions array of statements (e.g. "set(name, Made after $source->name$)") * @param $aActions array of statements (e.g. "set(name, Made after $source->name$)")
* @param $aSourceObjects Array of Alias => Context objects (Convention: some statements require the 'source' element * @param $aSourceObjects array of Alias => Context objects (Convention: some statements require the 'source' element
* @throws Exception * @throws Exception
*/ */
public function ExecActions($aActions, $aSourceObjects) public function ExecActions($aActions, $aSourceObjects)
@@ -3275,6 +3347,14 @@ abstract class DBObject implements iDisplay
/** /**
* Helper to copy an attribute between two objects (in memory) * Helper to copy an attribute between two objects (in memory)
* Originally designed for ExecAction() * Originally designed for ExecAction()
*
* @param \DBObject $oSourceObject
* @param $sSourceAttCode
* @param $sDestAttCode
*
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
*/ */
public function CopyAttribute($oSourceObject, $sSourceAttCode, $sDestAttCode) public function CopyAttribute($oSourceObject, $sSourceAttCode, $sDestAttCode)
{ {
@@ -3298,9 +3378,11 @@ abstract class DBObject implements iDisplay
if (is_object($oSourceAttDef) && $oSourceAttDef->IsLinkSet()) if (is_object($oSourceAttDef) && $oSourceAttDef->IsLinkSet())
{ {
// The copy requires that we create a new object set (the semantic of DBObject::Set is unclear about link sets) // The copy requires that we create a new object set (the semantic of DBObject::Set is unclear about link sets)
/** @var \AttributeLinkedSet $oSourceAttDef */
$oDestSet = DBObjectSet::FromScratch($oSourceAttDef->GetLinkedClass()); $oDestSet = DBObjectSet::FromScratch($oSourceAttDef->GetLinkedClass());
$oSourceSet = $oSourceObject->Get($sSourceAttCode); $oSourceSet = $oSourceObject->Get($sSourceAttCode);
$oSourceSet->Rewind(); $oSourceSet->Rewind();
/** @var \DBObject $oSourceLink */
while ($oSourceLink = $oSourceSet->Fetch()) while ($oSourceLink = $oSourceSet->Fetch())
{ {
// Clone the link // Clone the link
@@ -3343,7 +3425,7 @@ abstract class DBObject implements iDisplay
* *
* @param $sVerb string Any of the verb listed above (e.g. "set") * @param $sVerb string Any of the verb listed above (e.g. "set")
* @param $aParams array of strings (e.g. array('name', 'copied from $source->name$') * @param $aParams array of strings (e.g. array('name', 'copied from $source->name$')
* @param $aSourceObjects Array of Alias => Context objects (Convention: some statements require the 'source' element * @param $aSourceObjects array of Alias => Context objects (Convention: some statements require the 'source' element
* @throws CoreException * @throws CoreException
* @throws CoreUnexpectedValue * @throws CoreUnexpectedValue
* @throws Exception * @throws Exception
@@ -3516,7 +3598,9 @@ abstract class DBObject implements iDisplay
{ {
$oLinkSet = $this->Get($sTargetListAttCode); $oLinkSet = $this->Get($sTargetListAttCode);
/** @var \AttributeLinkedSetIndirect $oListAttDef */
$oListAttDef = MetaModel::GetAttributeDef(get_class($this), $sTargetListAttCode); $oListAttDef = MetaModel::GetAttributeDef(get_class($this), $sTargetListAttCode);
/** @var \AttributeLinkedSet $oListAttDef */
$oLnk = MetaModel::NewObject($oListAttDef->GetLinkedClass()); $oLnk = MetaModel::NewObject($oListAttDef->GetLinkedClass());
$oLnk->Set($oListAttDef->GetExtKeyToRemote(), $iObjKey); $oLnk->Set($oListAttDef->GetExtKeyToRemote(), $iObjKey);
if (isset($sRoleAttCode)) if (isset($sRoleAttCode))

View File

@@ -1,5 +1,5 @@
<?php <?php
// Copyright (C) 2010-2012 Combodo SARL // Copyright (C) 2010-2018 Combodo SARL
// //
// This file is part of iTop. // This file is part of iTop.
// //
@@ -21,7 +21,7 @@
* Persistent class Trigger and derived * Persistent class Trigger and derived
* User defined triggers, that may be used in conjunction with user defined actions * User defined triggers, that may be used in conjunction with user defined actions
* *
* @copyright Copyright (C) 2010-2012 Combodo SARL * @copyright Copyright (C) 2010-2018 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0 * @license http://opensource.org/licenses/AGPL-3.0
*/ */
@@ -34,6 +34,10 @@
*/ */
abstract class Trigger extends cmdbAbstractObject abstract class Trigger extends cmdbAbstractObject
{ {
/**
* @throws \CoreException
* @throws \Exception
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -50,25 +54,32 @@ abstract class Trigger extends cmdbAbstractObject
); );
MetaModel::Init_Params($aParams); MetaModel::Init_Params($aParams);
//MetaModel::Init_InheritAttributes(); //MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => true, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("action_list", array("linked_class" => "lnkTriggerAction", "ext_key_to_me" => "trigger_id", "ext_key_to_remote" => "action_id", "allowed_values" => null, "count_min" => 1, "count_max" => 0, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("action_list", array("linked_class"=>"lnkTriggerAction", "ext_key_to_me"=>"trigger_id", "ext_key_to_remote"=>"action_id", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array())));
// Display lists // Display lists
MetaModel::Init_SetZListItems('details', array('finalclass', 'description', 'action_list')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('details', array('finalclass', 'description', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('finalclass')); // Attributes to be displayed for a list MetaModel::Init_SetZListItems('list', array('finalclass')); // Attributes to be displayed for a list
// Search criteria // Search criteria
// MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
} }
/**
* @param $aContextArgs
*
* @throws \ArchivedObjectException
* @throws \CoreException
*/
public function DoActivate($aContextArgs) public function DoActivate($aContextArgs)
{ {
// Find the related actions // Find the related actions
$oLinkedActions = $this->Get('action_list'); $oLinkedActions = $this->Get('action_list');
while ($oLink = $oLinkedActions->Fetch()) while ($oLink = $oLinkedActions->Fetch())
{ {
/** @var \DBObject $oLink */
$iActionId = $oLink->Get('action_id'); $iActionId = $oLink->Get('action_id');
/** @var \Action $oAction */
$oAction = MetaModel::GetObject('Action', $iActionId); $oAction = MetaModel::GetObject('Action', $iActionId);
if ($oAction->IsActive()) if ($oAction->IsActive())
{ {
@@ -80,7 +91,9 @@ abstract class Trigger extends cmdbAbstractObject
/** /**
* Check whether the given object is in the scope of this trigger * Check whether the given object is in the scope of this trigger
* and can potentially be the subject of notifications * and can potentially be the subject of notifications
*
* @param DBObject $oObject The object to check * @param DBObject $oObject The object to check
*
* @return bool * @return bool
*/ */
public function IsInScope(DBObject $oObject) public function IsInScope(DBObject $oObject)
@@ -91,8 +104,15 @@ abstract class Trigger extends cmdbAbstractObject
} }
} }
/**
* Class TriggerOnObject
*/
abstract class TriggerOnObject extends Trigger abstract class TriggerOnObject extends Trigger
{ {
/**
* @throws \CoreException
* @throws \Exception
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -109,17 +129,20 @@ abstract class TriggerOnObject extends Trigger
); );
MetaModel::Init_Params($aParams); MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes(); MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeClass("target_class", array("class_category"=>"bizmodel", "more_values"=>"User,UserExternal,UserInternal,UserLDAP,UserLocal", "sql"=>"target_class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeClass("target_class", array("class_category" => "bizmodel", "more_values" => "User,UserExternal,UserInternal,UserLDAP,UserLocal", "sql" => "target_class", "default_value" => null, "is_null_allowed" => false, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeOQL("filter", array("allowed_values"=>null, "sql"=>"filter", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeOQL("filter", array("allowed_values" => null, "sql" => "filter", "default_value" => null, "is_null_allowed" => true, "depends_on" => array())));
// Display lists // Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'action_list')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
// Search criteria // Search criteria
MetaModel::Init_SetZListItems('default_search', array('description', 'target_class')); // Default criteria of the search banner MetaModel::Init_SetZListItems('default_search', array('description', 'target_class')); // Default criteria of the search banner
// MetaModel::Init_SetZListItems('standard_search', array('name', 'target_class', 'description')); // Criteria of the search form // MetaModel::Init_SetZListItems('standard_search', array('name', 'target_class', 'description')); // Criteria of the search form
} }
/**
* @throws \CoreException
*/
public function DoCheckToWrite() public function DoCheckToWrite()
{ {
parent::DoCheckToWrite(); parent::DoCheckToWrite();
@@ -135,8 +158,7 @@ abstract class TriggerOnObject extends Trigger
{ {
$this->m_aCheckIssues[] = Dict::Format('TriggerOnObject:WrongFilterClass', $this->Get('target_class')); $this->m_aCheckIssues[] = Dict::Format('TriggerOnObject:WrongFilterClass', $this->Get('target_class'));
} }
} } catch (OqlException $e)
catch(OqlException $e)
{ {
$this->m_aCheckIssues[] = Dict::Format('TriggerOnObject:WrongFilterQuery', $e->getMessage()); $this->m_aCheckIssues[] = Dict::Format('TriggerOnObject:WrongFilterQuery', $e->getMessage());
} }
@@ -146,21 +168,33 @@ abstract class TriggerOnObject extends Trigger
/** /**
* Check whether the given object is in the scope of this trigger * Check whether the given object is in the scope of this trigger
* and can potentially be the subject of notifications * and can potentially be the subject of notifications
*
* @param DBObject $oObject The object to check * @param DBObject $oObject The object to check
*
* @return bool * @return bool
* @throws \CoreException
*/ */
public function IsInScope(DBObject $oObject) public function IsInScope(DBObject $oObject)
{ {
$sRootClass = $this->Get('target_class'); $sRootClass = $this->Get('target_class');
return ($oObject instanceof $sRootClass); return ($oObject instanceof $sRootClass);
} }
/**
* @param $aContextArgs
*
* @throws \ArchivedObjectException
* @throws \CoreException
*/
public function DoActivate($aContextArgs) public function DoActivate($aContextArgs)
{ {
$bGo = true; $bGo = true;
if (isset($aContextArgs['this->object()'])) if (isset($aContextArgs['this->object()']))
{ {
$bGo = $this->IsTargetObject($aContextArgs['this->object()']->GetKey()); /** @var \DBObject $oObject */
$oObject = $aContextArgs['this->object()'];
$bGo = $this->IsTargetObject($oObject->GetKey());
} }
if ($bGo) if ($bGo)
{ {
@@ -168,6 +202,16 @@ abstract class TriggerOnObject extends Trigger
} }
} }
/**
* @param $iObjectId
*
* @return bool
* @throws \CoreException
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
* @throws \OQLException
*/
public function IsTargetObject($iObjectId) public function IsTargetObject($iObjectId)
{ {
$sFilter = trim($this->Get('filter')); $sFilter = trim($this->Get('filter'));
@@ -182,14 +226,19 @@ abstract class TriggerOnObject extends Trigger
{ {
$bRet = true; $bRet = true;
} }
return $bRet; return $bRet;
} }
} }
/** /**
* To trigger notifications when a ticket is updated from the portal * To trigger notifications when a ticket is updated from the portal
*/ */
class TriggerOnPortalUpdate extends TriggerOnObject class TriggerOnPortalUpdate extends TriggerOnObject
{ {
/**
* @throws \CoreException
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -214,8 +263,15 @@ class TriggerOnPortalUpdate extends TriggerOnObject
} }
} }
/**
* Class TriggerOnStateChange
*/
abstract class TriggerOnStateChange extends TriggerOnObject abstract class TriggerOnStateChange extends TriggerOnObject
{ {
/**
* @throws \CoreException
* @throws \Exception
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -232,19 +288,25 @@ abstract class TriggerOnStateChange extends TriggerOnObject
); );
MetaModel::Init_Params($aParams); MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes(); MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeString("state", array("allowed_values"=>null, "sql"=>"state", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeString("state", array("allowed_values" => null, "sql" => "state", "default_value" => null, "is_null_allowed" => false, "depends_on" => array())));
// Display lists // Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'state', 'action_list')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'state', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'state')); // Attributes to be displayed for a list MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'state')); // Attributes to be displayed for a list
// Search criteria // Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
} }
} }
/**
* Class TriggerOnStateEnter
*/
class TriggerOnStateEnter extends TriggerOnStateChange class TriggerOnStateEnter extends TriggerOnStateChange
{ {
/**
* @throws \CoreException
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -267,12 +329,18 @@ class TriggerOnStateEnter extends TriggerOnStateChange
MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list
// Search criteria // Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
} }
} }
/**
* Class TriggerOnStateLeave
*/
class TriggerOnStateLeave extends TriggerOnStateChange class TriggerOnStateLeave extends TriggerOnStateChange
{ {
/**
* @throws \CoreException
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -295,12 +363,18 @@ class TriggerOnStateLeave extends TriggerOnStateChange
MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list
// Search criteria // Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
// MetaModel::Init_SetZListItems('advanced_search', array('')); // Criteria of the advanced search form // MetaModel::Init_SetZListItems('advanced_search', array('')); // Criteria of the advanced search form
} }
} }
/**
* Class TriggerOnObjectCreate
*/
class TriggerOnObjectCreate extends TriggerOnObject class TriggerOnObjectCreate extends TriggerOnObject
{ {
/**
* @throws \CoreException
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -323,12 +397,19 @@ class TriggerOnObjectCreate extends TriggerOnObject
MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class')); // Attributes to be displayed for a list MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class')); // Attributes to be displayed for a list
// Search criteria // Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class')); // Criteria of the std search form MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class')); // Criteria of the std search form
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
} }
} }
/**
* Class lnkTriggerAction
*/
class lnkTriggerAction extends cmdbAbstractObject class lnkTriggerAction extends cmdbAbstractObject
{ {
/**
* @throws \CoreException
* @throws \Exception
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -345,11 +426,11 @@ class lnkTriggerAction extends cmdbAbstractObject
"is_link" => true, "is_link" => true,
); );
MetaModel::Init_Params($aParams); MetaModel::Init_Params($aParams);
MetaModel::Init_AddAttribute(new AttributeExternalKey("action_id", array("targetclass"=>"Action", "jointype"=> '', "allowed_values"=>null, "sql"=>"action_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeExternalKey("action_id", array("targetclass" => "Action", "jointype" => '', "allowed_values" => null, "sql" => "action_id", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeExternalField("action_name", array("allowed_values"=>null, "extkey_attcode"=> 'action_id', "target_attcode"=>"name"))); MetaModel::Init_AddAttribute(new AttributeExternalField("action_name", array("allowed_values" => null, "extkey_attcode" => 'action_id', "target_attcode" => "name")));
MetaModel::Init_AddAttribute(new AttributeExternalKey("trigger_id", array("targetclass"=>"Trigger", "jointype"=> '', "allowed_values"=>null, "sql"=>"trigger_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeExternalKey("trigger_id", array("targetclass" => "Trigger", "jointype" => '', "allowed_values" => null, "sql" => "trigger_id", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeExternalField("trigger_name", array("allowed_values"=>null, "extkey_attcode"=> 'trigger_id', "target_attcode"=>"description"))); MetaModel::Init_AddAttribute(new AttributeExternalField("trigger_name", array("allowed_values" => null, "extkey_attcode" => 'trigger_id', "target_attcode" => "description")));
MetaModel::Init_AddAttribute(new AttributeInteger("order", array("allowed_values"=>null, "sql"=>"order", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeInteger("order", array("allowed_values" => null, "sql" => "order", "default_value" => 0, "is_null_allowed" => true, "depends_on" => array())));
// Display lists // Display lists
MetaModel::Init_SetZListItems('details', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list MetaModel::Init_SetZListItems('details', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list
@@ -360,8 +441,15 @@ class lnkTriggerAction extends cmdbAbstractObject
} }
} }
/**
* Class TriggerOnThresholdReached
*/
class TriggerOnThresholdReached extends TriggerOnObject class TriggerOnThresholdReached extends TriggerOnObject
{ {
/**
* @throws \CoreException
* @throws \Exception
*/
public static function Init() public static function Init()
{ {
$aParams = array $aParams = array
@@ -379,15 +467,16 @@ class TriggerOnThresholdReached extends TriggerOnObject
MetaModel::Init_Params($aParams); MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes(); MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeString("stop_watch_code", array("allowed_values"=>null, "sql"=>"stop_watch_code", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeString("stop_watch_code", array("allowed_values" => null, "sql" => "stop_watch_code", "default_value" => null, "is_null_allowed" => false, "depends_on" => array())));
MetaModel::Init_AddAttribute(new AttributeString("threshold_index", array("allowed_values"=>null, "sql"=>"threshold_index", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeString("threshold_index", array("allowed_values" => null, "sql" => "threshold_index", "default_value" => null, "is_null_allowed" => false, "depends_on" => array())));
// Display lists // Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'stop_watch_code', 'threshold_index', 'filter', 'action_list')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'stop_watch_code', 'threshold_index', 'filter', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('target_class', 'threshold_index', 'threshold_index')); // Attributes to be displayed for a list MetaModel::Init_SetZListItems('list', array('target_class', 'threshold_index', 'threshold_index')); // Attributes to be displayed for a list
// Search criteria // Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class')); // Criteria of the std search form MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class')); // Criteria of the std search form
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
} }
} }
?> ?>