mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 01:58:47 +02:00
Plugin API - alpha version
SVN:trunk[1124]
This commit is contained in:
@@ -46,6 +46,8 @@ abstract class DBObject
|
||||
private $m_bCheckStatus = null; // Means: the object has been verified and is consistent with integrity rules
|
||||
// if null, then the check has to be performed again to know the status
|
||||
protected $m_aCheckIssues = null;
|
||||
protected $m_aDeleteIssues = null;
|
||||
|
||||
protected $m_aAsArgs = null; // The current object as a standard argument (cache)
|
||||
|
||||
private $m_bFullyLoaded = false; // Compound objects can be partially loaded
|
||||
@@ -786,11 +788,14 @@ abstract class DBObject
|
||||
|
||||
// check if it is allowed to delete the existing object from the database
|
||||
// a displayable error is returned
|
||||
public function CheckToDelete()
|
||||
protected function DoCheckToDelete()
|
||||
{
|
||||
return true;
|
||||
$this->m_aDeleteIssues = array(); // Ok
|
||||
}
|
||||
|
||||
// final public function CheckToDelete() - THE EQUIVALENT OF CheckToWrite IS NOT AVAILABLE
|
||||
// Todo - split the "DeleteObject()" function (UI.php) and move the generic part in cmdbAbstractObject, etc.
|
||||
|
||||
protected function ListChangedValues(array $aProposal)
|
||||
{
|
||||
$aDelta = array();
|
||||
@@ -1346,15 +1351,24 @@ abstract class DBObject
|
||||
*/
|
||||
public function GetDeletionScheme(&$aDeletedObjs, &$aResetedObjs, $aVisited = array())
|
||||
{
|
||||
if (array_key_exists(get_class($this), $aVisited))
|
||||
$sClass = get_class($this);
|
||||
$iThisId = $this->GetKey();
|
||||
|
||||
if (array_key_exists($sClass, $aVisited))
|
||||
{
|
||||
if (in_array($this->GetKey(), $aVisited[get_class($this)]))
|
||||
if (in_array($iThisId, $aVisited[$sClass]))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
$aVisited[get_class($this)] = $this->GetKey();
|
||||
$aVisited[$sClass] = $iThisId;
|
||||
|
||||
$aDeletedObjs[$sClass][$iThisId]['to_delete'] = $this;
|
||||
$aDeletedObjs[$sClass][$iThisId]['auto_delete'] = true;
|
||||
// Check the node itself
|
||||
$this->DoCheckToDelete();
|
||||
$aDeletedObjs[$sClass][$iThisId]['issues'] = $this->m_aDeleteIssues;
|
||||
|
||||
$aDependentObjects = $this->GetReferencingObjects();
|
||||
foreach ($aDependentObjects as $sRemoteClass => $aPotentialDeletes)
|
||||
{
|
||||
@@ -1397,12 +1411,15 @@ abstract class DBObject
|
||||
{
|
||||
// First time we find the given object in the list
|
||||
// (and most likely case is that no other occurence will be found)
|
||||
$aDeletedObjs[$sRemoteClass][$iId]['to_delete'] = $oDependentObj;
|
||||
$aDeletedObjs[$sRemoteClass][$iId]['auto_delete'] = ($iDeletePropagationOption == DEL_AUTO);
|
||||
// Recursively inspect this object
|
||||
if ($iDeletePropagationOption == DEL_AUTO)
|
||||
{
|
||||
// Recursively inspect this object
|
||||
$oDependentObj->GetDeletionScheme($aDeletedObjs, $aResetedObjs, $aVisited);
|
||||
}
|
||||
else
|
||||
{
|
||||
$aDeletedObjs[$sRemoteClass][$iId]['to_delete'] = $oDependentObj;
|
||||
$aDeletedObjs[$sRemoteClass][$iId]['auto_delete'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3444,6 +3444,30 @@ abstract class MetaModel
|
||||
public static function Startup($sConfigFile, $bModelOnly = false)
|
||||
{
|
||||
self::LoadConfig($sConfigFile);
|
||||
|
||||
$aInterfaces = array('iApplicationUIExtension', 'iApplicationObjectExtension');
|
||||
foreach($aInterfaces as $sInterface)
|
||||
{
|
||||
self::$m_aExtensionClasses[$sInterface] = array();
|
||||
}
|
||||
|
||||
foreach(get_declared_classes() as $sPHPClass)
|
||||
{
|
||||
$oRefClass = new ReflectionClass($sPHPClass);
|
||||
$oExtensionInstance = null;
|
||||
foreach($aInterfaces as $sInterface)
|
||||
{
|
||||
if ($oRefClass->implementsInterface($sInterface))
|
||||
{
|
||||
if (is_null($oExtensionInstance))
|
||||
{
|
||||
$oExtensionInstance = new $sPHPClass;
|
||||
}
|
||||
self::$m_aExtensionClasses[$sInterface][] = $oExtensionInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($bModelOnly) return;
|
||||
|
||||
CMDBSource::SelectDB(self::$m_sDBName);
|
||||
@@ -3570,6 +3594,8 @@ abstract class MetaModel
|
||||
return self::$m_oConfig;
|
||||
}
|
||||
|
||||
protected static $m_aExtensionClasses = array();
|
||||
|
||||
protected static $m_aPlugins = array();
|
||||
public static function RegisterPlugin($sType, $sName, $aInitCallSpec = array())
|
||||
{
|
||||
@@ -3960,6 +3986,20 @@ abstract class MetaModel
|
||||
return str_replace($aSearches, $aReplacements, $aInput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of classes implementing the given interface
|
||||
*/
|
||||
public static function EnumPlugins($sInterface)
|
||||
{
|
||||
if (array_key_exists($sInterface, self::$m_aExtensionClasses))
|
||||
{
|
||||
return self::$m_aExtensionClasses[$sInterface];
|
||||
}
|
||||
else
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
} // class MetaModel
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user