diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index b86449710..e2966b6ad 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -5877,6 +5877,11 @@ JS $this->FireEvent(EVENT_DB_CHECK_TO_WRITE); } + final protected function FireEventBeforeDatabaseCreate() + { + $this->FireEvent(EVENT_DB_BEFORE_CREATE); + } + /** * @return void * @throws \CoreException @@ -5894,6 +5899,16 @@ JS /// UPDATE /// + + /** + * @return void + * @throws \CoreException + */ + final protected function FireEventBeforeDatabaseUpdate() + { + $this->FireEvent(EVENT_DB_BEFORE_UPDATE); + } + /** * @param array $aChanges * diff --git a/application/datamodel.application.xml b/application/datamodel.application.xml index ad3324e9c..a8075fb68 100644 --- a/application/datamodel.application.xml +++ b/application/datamodel.application.xml @@ -203,6 +203,23 @@ + + An object is about to be created into the database. The object can be modified. + + cmdbAbstractObject + + DBObject::OnInsert + + + The object inserted + DBObject + + + Debug string + string + + + An object has been created into the database. The modifications can be propagated to other objects. @@ -220,6 +237,23 @@ + + An object is about to be updated into the database. The object can be modified. + + cmdbAbstractObject + + DBObject::OnUpdate + + + The object updated + DBObject + + + Debug string + string + + + An object has been updated into the database and reloaded. diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 978394e59..a4bffb960 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -3086,6 +3086,8 @@ abstract class DBObject implements iDisplay $this->ComputeStopWatchesDeadline(true); + $this->FireEventBeforeDatabaseCreate(); + $iTransactionRetry = 1; $bIsTransactionEnabled = MetaModel::GetConfig()->Get('db_core_transactions_enabled'); if ($bIsTransactionEnabled) { @@ -3276,6 +3278,8 @@ abstract class DBObject implements iDisplay $this->ComputeStopWatchesDeadline(false); $this->OnUpdate(); + $this->FireEventBeforeDatabaseUpdate(); + // Freeze the changes at this point $this->InitPreviousValuesForUpdatedAttributes(); $aChanges = $this->ListChanges(); @@ -6053,6 +6057,14 @@ abstract class DBObject implements iDisplay { } + /** + * @return void + * @since 3.1.0 + */ + protected function FireEventBeforeDatabaseCreate() + { + } + /** * @return void * @since 3.1.0 @@ -6069,6 +6081,16 @@ abstract class DBObject implements iDisplay * @return void * @since 3.1.0 */ + protected function FireEventBeforeDatabaseUpdate() + { + } + + /** + * @param array $aChanges + * + * @return void + * @since 3.1.0 + */ protected function FireEventUpdateDone(array $aChanges): void { } @@ -6078,6 +6100,8 @@ abstract class DBObject implements iDisplay /// /** + * @param \DeletionPlan $oDeletionPlan + * * @return void * @since 3.1.0 */ diff --git a/sources/Service/Events/EventService.php b/sources/Service/Events/EventService.php index d1c1c2ff2..85db6e0da 100644 --- a/sources/Service/Events/EventService.php +++ b/sources/Service/Events/EventService.php @@ -340,7 +340,7 @@ final class EventService foreach (self::$aEventDescriptions as $sEvent => $aEventInfo) { if (is_array($aEventInfo['description']->GetEventSources())) { foreach ($aEventInfo['description']->GetEventSources() as $sSource) { - if (\MetaModel::IsValidClass($sSource) && ($sClass == $sSource || $oClass->isSubclassOf($sSource))) { + if (class_exists($sSource) && ($sClass == $sSource || $oClass->isSubclassOf($sSource))) { $aRes[$sEvent] = $aEventInfo; } }