N°4756 - Ease extensibility for CRUD operations : Events renamed

This commit is contained in:
Eric Espie
2022-12-22 15:16:52 +01:00
parent eff2afbc69
commit 44fac686f9
4 changed files with 455 additions and 193 deletions

View File

@@ -5661,31 +5661,160 @@ JS
);
}
//////////////////
/// CREATE
///
/**
* @inheritDoc
* @throws \CoreException
* @since 3.1.0
*/
final protected function EventInsertRequested(): void
final protected function EventCreateComputeValues(): void
{
$this->FireEvent(EVENT_SERVICE_DB_INSERT_REQUESTED);
$this->FireEvent(EVENT_DB_CREATE_COMPUTE_VALUES);
}
/**
* @inheritDoc
* @throws \CoreException
* @since 3.1.0
*/
final protected function EventInsertBefore(): void
final protected function EventCreateRequested(): void
{
$this->FireEvent(EVENT_SERVICE_DB_ABOUT_TO_INSERT);
$this->FireEvent(EVENT_DB_CREATE_REQUESTED);
}
/**
* @inheritDoc
* @throws \CoreException
* @since 3.1.0
*/
final protected function EventInsertAfter(): void
final protected function EventCheckToCreate(): void
{
$this->FireEvent(EVENT_SERVICE_DB_INSERT_DONE);
$this->FireEvent(EVENT_DB_CHECK_TO_CREATE);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCheckToCreateFailed(array $aData): void
{
$this->FireEvent(EVENT_DB_CHECK_TO_CREATE_FAILED, $aData);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventAboutToCreate(): void
{
$this->FireEvent(EVENT_DB_ABOUT_TO_CREATE);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCreateDone(): void
{
$this->FireEvent(EVENT_DB_CREATE_DONE);
}
/////////////
/// UPDATE
///
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventUpdateComputeValues(): void
{
$this->FireEvent(EVENT_DB_UPDATE_COMPUTE_VALUES);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventUpdateRequested(): void
{
$this->FireEvent(EVENT_DB_UPDATE_REQUESTED);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCheckToUpdate(): void
{
$this->FireEvent(EVENT_DB_CHECK_TO_UPDATE);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCheckToUpdateFailed(array $aData): void
{
$this->FireEvent(EVENT_DB_CHECK_TO_UPDATE_FAILED, $aData);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventAboutToUpdate(): void
{
$this->FireEvent(EVENT_DB_ABOUT_TO_UPDATE);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventUpdateDone(array $aData): void
{
$this->FireEvent(EVENT_DB_UPDATE_DONE, $aData);
}
//////////////
/// DELETE
///
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCheckToDelete(): void
{
$this->FireEvent(EVENT_DB_CHECK_TO_DELETE);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCheckToDeleteFailed(array $aData): void
{
$this->FireEvent(EVENT_DB_CHECK_TO_DELETE_FAILED, $aData);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventAboutToDelete(): void
{
$this->FireEvent(EVENT_DB_ABOUT_TO_DELETE);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventDeleteDone(): void
{
$this->FireEvent(EVENT_DB_DELETE_DONE);
}
/**
@@ -5694,70 +5823,7 @@ JS
*/
final protected function EventComputeValues(): void
{
$this->FireEvent(EVENT_SERVICE_DB_COMPUTE_VALUES);
}
/**
* @inheritDoc
* @throws \CoreException
*/
final protected function EventCheckToWrite(): void
{
$this->FireEvent(EVENT_SERVICE_DB_CHECK_TO_WRITE);
}
/**
* @inheritDoc
* @throws \CoreException
*/
final protected function EventCheckToDelete(): void
{
$this->FireEvent(EVENT_SERVICE_DB_CHECK_TO_DELETE);
}
/**
* @inheritDoc
* @throws \CoreException
*/
final protected function EventUpdateRequested(): void
{
$this->FireEvent(EVENT_SERVICE_DB_UPDATE_REQUESTED);
}
/**
* @inheritDoc
* @throws \CoreException
*/
final protected function EventUpdateBefore(): void
{
$this->FireEvent(EVENT_SERVICE_DB_ABOUT_TO_UPDATE);
}
/**
* @inheritDoc
* @throws \CoreException
*/
final protected function EventUpdateAfter(array $aEventData): void
{
$this->FireEvent(EVENT_SERVICE_DB_UPDATE_DONE, $aEventData);
}
/**
* @inheritDoc
* @throws \CoreException
*/
final protected function EventDeleteBefore(): void
{
$this->FireEvent(EVENT_SERVICE_DB_ABOUT_TO_DELETE);
}
/**
* @inheritDoc
* @throws \CoreException
*/
final protected function EventDeleteAfter(): void
{
$this->FireEvent(EVENT_SERVICE_DB_DELETE_DONE);
$this->FireEvent(EVENT_DB_COMPUTE_VALUES);
}
/**
@@ -5766,21 +5832,22 @@ JS
*/
final protected function EventArchive(): void
{
$this->FireEvent(EVENT_SERVICE_DB_ARCHIVE);
$this->FireEvent(EVENT_DB_ARCHIVE);
}
/**
* @inheritDoc
* @throws \CoreException
*/
final protected function EventUnarchive(): void
final protected function EventUnArchive(): void
{
$this->FireEvent(EVENT_SERVICE_DB_UNARCHIVE);
$this->FireEvent(EVENT_DB_UNARCHIVE);
}
/**
* Append $iFlags to $sAttCode attribute in $sTargetState
*
* @api
* @param string $sAttCode
* @param int $iFlags
* @param string $sTargetState
@@ -5803,6 +5870,7 @@ JS
/**
* Force $iFlags to $sAttCode attribute in $sTargetState
*
* @api
* @param string $sAttCode
* @param int $iFlags
* @param string $sTargetState
@@ -5833,7 +5901,7 @@ JS
$aEventData = [
'target_state' => $sTargetState,
];
$this->FireEvent(EVENT_SERVICE_DB_SET_ATTRIBUTES_FLAGS, $aEventData);
$this->FireEvent(EVENT_DB_SET_ATTRIBUTES_FLAGS, $aEventData);
}
$iFlags = $this->aAttributesFlags[$sTargetState][$sAttCode]['flags'] ?? 0;
$aReasons += ($this->aAttributesFlags[$sTargetState][$sAttCode]['reasons'] ?? []);
@@ -5845,6 +5913,7 @@ JS
/**
* Append $iFlags to $sAttCode attribute in initial state
*
* @api
* @param string $sAttCode
* @param int $iFlags
* @param string|null $sReason
@@ -5866,6 +5935,7 @@ JS
/**
* Force $iFlags to $sAttCode attribute in initial state
*
* @api
* @param string $sAttCode
* @param int $iFlags
* @param string|null $sReason
@@ -5892,7 +5962,7 @@ JS
{
if (!isset($this->aInitialAttributesFlags)) {
$this->aInitialAttributesFlags = [];
$this->FireEvent(EVENT_SERVICE_DB_SET_INITIAL_ATTRIBUTES_FLAGS);
$this->FireEvent(EVENT_DB_SET_INITIAL_ATTRIBUTES_FLAGS);
}
$iFlags = $this->aInitialAttributesFlags[$sAttCode]['flags'] ?? 0;
$aReasons += ($this->aInitialAttributesFlags[$sAttCode]['reasons'] ?? []);

View File

@@ -186,8 +186,25 @@
</menu>
</menus>
<events>
<event id="EVENT_SERVICE_DB_INSERT_REQUESTED" _delta="define">
<description>An object insert in the database has been requested. All changes to the object will be persisted automatically.</description>
<event id="EVENT_DB_CREATE_COMPUTE_VALUES" _delta="define">
<description>An object needs to be recomputed after changes</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>DBObject::ComputeValues</replaces>
<event_data>
<event_datum id="object">
<description>The object inserted</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_DB_CREATE_REQUESTED" _delta="define">
<description>An object create in the database has been requested. All changes to the object will be persisted automatically.</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
@@ -203,8 +220,46 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_ABOUT_TO_INSERT" _delta="define">
<description>An object is about to be inserted in the database (no change possible)</description>
<event id="EVENT_DB_CHECK_TO_CREATE" _delta="define">
<description>Check an object before it is created into the database (no change possible). Call DBObject::AddCheckIssue() to signal an issue</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>cmdbAbstractObject::DoCheckToWrite</replaces>
<event_data>
<event_datum id="object">
<description>The object to check</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_DB_CHECK_TO_CREATE_FAILED" _delta="define">
<description>A check has failed, it is not possible to create the object</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>cmdbAbstractObject::DoCheckToWrite</replaces>
<event_data>
<event_datum id="check_issues">
<description>Array of the issues (string) that prevented the object creation</description>
<type>array</type>
</event_datum>
<event_datum id="object">
<description>The object to check</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_DB_ABOUT_TO_CREATE" _delta="define">
<description>An object is about to be created in the database (no change possible)</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
@@ -220,8 +275,8 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_INSERT_DONE" _delta="define">
<description>An object has been inserted into the database (but not reloaded). All changes to the object will be persisted automatically.</description>
<event id="EVENT_DB_CREATE_DONE" _delta="define">
<description>An object has been created into the database. The modifications can be propagated to other objects.</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
@@ -237,7 +292,24 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_UPDATE_REQUESTED" _delta="define">
<event id="EVENT_DB_UPDATE_COMPUTE_VALUES" _delta="define">
<description>An object needs to be recomputed after changes</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>DBObject::ComputeValues</replaces>
<event_data>
<event_datum id="object">
<description>The object inserted</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_DB_UPDATE_REQUESTED" _delta="define">
<description>An object update has been requested. All changes to the object will be persisted automatically.</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -254,7 +326,45 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_ABOUT_TO_UPDATE" _delta="define">
<event id="EVENT_DB_CHECK_TO_UPDATE" _delta="define">
<description>Check an object before it is written into the database (no change possible). Call DBObject::AddCheckIssue() to signal an issue</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>cmdbAbstractObject::DoCheckToWrite</replaces>
<event_data>
<event_datum id="object">
<description>The object to check</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_DB_CHECK_TO_UPDATE_FAILED" _delta="define">
<description>A check has failed, it is not possible to update the object</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>cmdbAbstractObject::DoCheckToWrite</replaces>
<event_data>
<event_datum id="check_issues">
<description>Array of the issues (string) that prevented the object update</description>
<type>array</type>
</event_datum>
<event_datum id="object">
<description>The object to check</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_DB_ABOUT_TO_UPDATE" _delta="define">
<description>An object is about to be updated in the database (no change possible)</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -271,8 +381,8 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_UPDATE_DONE" _delta="define">
<description>An object has been updated into the database and reloaded. All changes to the object will be persisted automatically.</description>
<event id="EVENT_DB_UPDATE_DONE" _delta="define">
<description>An object has been updated into the database and reloaded.</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
@@ -288,7 +398,45 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_ABOUT_TO_DELETE" _delta="define">
<event id="EVENT_DB_CHECK_TO_DELETE" _delta="define">
<description>Check an object before it is deleted from the database. Call DBObject::AddDeleteIssue() to signal an issue</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>cmdbAbstractObject::DoCheckToDelete</replaces>
<event_data>
<event_datum id="object">
<description>The object to check</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_DB_CHECK_TO_DELETE_FAILED" _delta="define">
<description>A check has failed, it is not possible to delete the object</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>cmdbAbstractObject::DoCheckToWrite</replaces>
<event_data>
<event_datum id="check_issues">
<description>Array of the issues (string) that prevented the object deletion</description>
<type>array</type>
</event_datum>
<event_datum id="object">
<description>The object to check</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_DB_ABOUT_TO_DELETE" _delta="define">
<description>An object is about to be deleted in the database</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -305,7 +453,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_DELETE_DONE" _delta="define">
<event id="EVENT_DB_DELETE_DONE" _delta="define">
<description>An object has been deleted into the database</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -322,7 +470,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_BEFORE_APPLY_STIMULUS" _delta="define">
<event id="EVENT_DB_BEFORE_APPLY_STIMULUS" _delta="define">
<description>A stimulus is about to be applied to an object</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -354,7 +502,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_AFTER_APPLY_STIMULUS" _delta="define">
<event id="EVENT_DB_AFTER_APPLY_STIMULUS" _delta="define">
<description>A stimulus has been applied to an object</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -386,7 +534,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_APPLY_STIMULUS_FAILED" _delta="define">
<event id="EVENT_DB_APPLY_STIMULUS_FAILED" _delta="define">
<description>A stimulus has failed</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -422,7 +570,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_OBJECT_RELOAD" _delta="define">
<event id="EVENT_DB_OBJECT_RELOAD" _delta="define">
<description>An object has been re-loaded from the database</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -438,7 +586,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_COMPUTE_VALUES" _delta="define">
<event id="EVENT_DB_COMPUTE_VALUES" _delta="define">
<description>An object needs to be recomputed after changes</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -455,41 +603,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_CHECK_TO_WRITE" _delta="define">
<description>Check an object before it is written into the database (no change possible). Call DBObject::AddCheckIssue() to signal an issue</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>cmdbAbstractObject::DoCheckToWrite</replaces>
<event_data>
<event_datum id="object">
<description>The object to check</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_CHECK_TO_DELETE" _delta="define">
<description>Check an object before it is deleted from the database (no change possible). Call DBObject::AddDeleteIssue() to signal an issue</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
</sources>
<replaces>cmdbAbstractObject::DoCheckToDelete</replaces>
<event_data>
<event_datum id="object">
<description>The object to check</description>
<type>DBObject</type>
</event_datum>
<event_datum id="debug_info">
<description>Debug string</description>
<type>string</type>
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_ARCHIVE" _delta="define">
<event id="EVENT_DB_ARCHIVE" _delta="define">
<description>An object has been archived</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -505,7 +619,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_UNARCHIVE" _delta="define">
<event id="EVENT_DB_UNARCHIVE" _delta="define">
<description>An object has been unarchived</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -521,7 +635,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_SET_ATTRIBUTES_FLAGS" _delta="define">
<event id="EVENT_DB_SET_ATTRIBUTES_FLAGS" _delta="define">
<description>Set object attributes flags. Call cmdbAbstractObject::AddAttributeFlags() for all the attributes to be set for this target state.</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
@@ -541,7 +655,7 @@
</event_datum>
</event_data>
</event>
<event id="EVENT_SERVICE_DB_SET_INITIAL_ATTRIBUTES_FLAGS" _delta="define">
<event id="EVENT_DB_SET_INITIAL_ATTRIBUTES_FLAGS" _delta="define">
<description>Set object initial attributes flags. Call cmdbAbstractObject::AddInitialAttributeFlags() for all the initial attributes to be set initially.</description>
<sources>
<source id="cmdbAbstractObject">cmdbAbstractObject</source>

View File

@@ -355,7 +355,7 @@ abstract class DBObject implements iDisplay
public function Reload($bAllowAllData = false)
{
assert($this->m_bIsInDB);
$this->FireEvent(EVENT_SERVICE_DB_OBJECT_RELOAD);
$this->FireEvent(EVENT_DB_OBJECT_RELOAD);
$aRow = MetaModel::MakeSingleRow(get_class($this), $this->m_iKey, false /* must be found */, true /* AllowAllData */);
if (empty($aRow))
{
@@ -2357,10 +2357,6 @@ abstract class DBObject implements iDisplay
$this->DoComputeValues();
}
$this->SetReadOnly('No modification allowed during CheckToWrite');
$this->EventCheckToWrite();
$this->SetReadWrite();
$this->DoCheckToWrite();
$oKPI->ComputeStats('CheckToWrite', get_class($this));
if (count($this->m_aCheckIssues) == 0)
@@ -2969,8 +2965,9 @@ abstract class DBObject implements iDisplay
$sRootClass = MetaModel::GetRootClass($sClass);
// Ensure the update of the values (we are accessing the data directly)
$this->EventCreateComputeValues();
$this->DoComputeValues();
$this->EventInsertRequested();
$this->EventCreateRequested();
$this->OnInsert();
if ($this->m_iKey < 0) {
@@ -2986,14 +2983,19 @@ abstract class DBObject implements iDisplay
}
// Ultimate check - ensure DB integrity
$this->SetReadOnly('No modification allowed during CheckToCreate');
$this->EventCheckToCreate();
$this->SetReadWrite();
list($bRes, $aIssues) = $this->CheckToWrite(false);
if (!$bRes) {
$this->EventCheckToCreateFailed(['check_issues' => $aIssues]);
throw new CoreCannotSaveObjectException(array('issues' => $aIssues, 'class' => get_class($this), 'id' => $this->GetKey()));
}
$this->ComputeStopWatchesDeadline(true);
$this->SetReadOnly('No modification allowed during The Event :'.EVENT_SERVICE_DB_ABOUT_TO_INSERT);
$this->EventInsertBefore();
$this->SetReadOnly('No modification allowed during The Event :'.EVENT_DB_ABOUT_TO_INSERT);
$this->EventAboutToCreate();
$this->SetReadWrite();
$iTransactionRetry = 1;
@@ -3073,7 +3075,7 @@ abstract class DBObject implements iDisplay
// Prevent DBUpdate at this point (reentrance protection)
MetaModel::StartReentranceProtection(Metamodel::REENTRANCE_TYPE_UPDATE, $this);
$this->EventInsertAfter();
$this->EventCreateDone();
$this->AfterInsert();
// Activate any existing trigger
@@ -3172,6 +3174,7 @@ abstract class DBObject implements iDisplay
try
{
$this->EventUpdateComputeValues();
$this->DoComputeValues();
$this->ComputeStopWatchesDeadline(false);
$this->EventUpdateRequested();
@@ -3191,10 +3194,12 @@ abstract class DBObject implements iDisplay
// Ultimate check - ensure DB integrity
$this->SetReadOnly('No modification allowed during CheckToWrite');
list($bRes, $aIssues) = $this->CheckToWrite(false);
$this->EventCheckToUpdate();
$this->SetReadWrite();
list($bRes, $aIssues) = $this->CheckToWrite(false);
if (!$bRes)
{
$this->EventCheckToUpdateFailed(['check_issues' => $aIssues]);
throw new CoreCannotSaveObjectException(['issues' => $aIssues, 'class' => $sClass, 'id' => $this->GetKey()]);
}
@@ -3229,8 +3234,8 @@ abstract class DBObject implements iDisplay
$iIsTransactionRetryDelay = MetaModel::GetConfig()->Get('db_core_transactions_retry_delay_ms');
$iTransactionRetry = $iTransactionRetryCount;
}
$this->SetReadOnly('No modification allowed during The Event :'.EVENT_SERVICE_DB_ABOUT_TO_UPDATE);
$this->EventUpdateBefore();
$this->SetReadOnly('No modification allowed during The Event :'.EVENT_DB_ABOUT_TO_UPDATE);
$this->EventAboutToUpdate();
$this->SetReadWrite();
while ($iTransactionRetry > 0)
@@ -3361,7 +3366,7 @@ abstract class DBObject implements iDisplay
$this->m_aModifiedAtt = array();
try {
$this->EventUpdateAfter(['changes' => $aChanges]);
$this->EventUpdateDone(['changes' => $aChanges]);
$this->AfterUpdate();
// Reset original values although the object has not been reloaded
@@ -3610,7 +3615,7 @@ abstract class DBObject implements iDisplay
return;
}
$this->EventDeleteBefore();
$this->EventAboutToDelete();
$this->OnDelete();
// Activate any existing trigger
@@ -3721,7 +3726,7 @@ abstract class DBObject implements iDisplay
}
}
$this->EventDeleteAfter();
$this->EventDeleteDone();
$this->AfterDelete();
@@ -3770,6 +3775,7 @@ abstract class DBObject implements iDisplay
if ($oDeletionPlan->FoundStopper())
{
$aIssues = $oDeletionPlan->GetIssues();
$this->EventCheckToDeleteFailed(['check_issues' => $aIssues]);
throw new DeleteException('Found issue(s)', array('target_class' => get_class($this), 'target_id' => $this->GetKey(), 'issues' => implode(', ', $aIssues)));
}
@@ -3925,7 +3931,7 @@ abstract class DBObject implements iDisplay
'new_state' => $sNewState,
'save_object' => !$bDoNotWrite,
];
$this->FireEvent(EVENT_SERVICE_DB_BEFORE_APPLY_STIMULUS, $aEventData);
$this->FireEvent(EVENT_DB_BEFORE_APPLY_STIMULUS, $aEventData);
// $aTransitionDef is an
// array('target_state'=>..., 'actions'=>array of handlers procs, 'user_restriction'=>TBD
@@ -4040,7 +4046,7 @@ abstract class DBObject implements iDisplay
}
}
$this->FireEvent(EVENT_SERVICE_DB_AFTER_APPLY_STIMULUS, $aEventData);
$this->FireEvent(EVENT_DB_AFTER_APPLY_STIMULUS, $aEventData);
}
else
{
@@ -4050,7 +4056,7 @@ abstract class DBObject implements iDisplay
$this->m_aCurrValues[$sAttCode] = $aBackupValues[$sAttCode];
}
$aEventData['action'] = $sActionDesc;
$this->FireEvent(EVENT_SERVICE_DB_APPLY_STIMULUS_FAILED, $aEventData);
$this->FireEvent(EVENT_DB_APPLY_STIMULUS_FAILED, $aEventData);
}
return $bSuccess;
}
@@ -5626,7 +5632,7 @@ abstract class DBObject implements iDisplay
$this->m_aOrigValues['archive_flag'] = false;
$this->m_aCurrValues['archive_date'] = null;
$this->m_aOrigValues['archive_date'] = null;
$this->EventUnarchive();
$this->EventUnArchive();
}
@@ -5822,6 +5828,7 @@ abstract class DBObject implements iDisplay
}
/**
* @api
* @param string $sIssue
*
* @return void
@@ -5833,14 +5840,46 @@ abstract class DBObject implements iDisplay
}
/**
* @api
* @param string $sIssue
* @param bool $bIsSecurityIssue
*
* @return void
* @since 3.1.0
*/
final public function AddDeleteIssue(string $sIssue)
final public function AddDeleteIssue(string $sIssue, bool $bIsSecurityIssue = false)
{
$this->m_aDeleteIssues[] = $sIssue;
if ($bIsSecurityIssue) {
$this->m_bSecurityIssue = true;
}
}
/**
* @api
* @param string $sAttCode
* @param array $aReasons
* @param string $sTargetState
*
* @return int
* @since 3.1.0
*/
protected function GetExtensionsAttributeFlags(string $sAttCode, array &$aReasons, string $sTargetState): int
{
return OPT_ATT_NORMAL;
}
/**
* @api
* @param string $sAttCode
* @param array $aReasons
*
* @return int
* @since 3.1.0
*/
protected function GetExtensionsInitialStateAttributeFlags(string $sAttCode, array &$aReasons): int
{
return OPT_ATT_NORMAL;
}
/**
@@ -5865,11 +5904,15 @@ abstract class DBObject implements iDisplay
}
}
//////////////////
/// CREATE
///
/**
* @return void
* @since 3.1.0
*/
protected function EventInsertRequested(): void
protected function EventCreateComputeValues(): void
{
}
@@ -5877,11 +5920,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventInsertBefore(): void
{
}
protected function EventInsertAfter(): void
protected function EventCreateRequested(): void
{
}
@@ -5889,7 +5928,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventComputeValues(): void
protected function EventCheckToCreate(): void
{
}
@@ -5897,7 +5936,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventCheckToWrite(): void
protected function EventCheckToCreateFailed(array $aData): void
{
}
@@ -5905,7 +5944,27 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventCheckToDelete(): void
protected function EventAboutToCreate(): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventCreateDone(): void
{
}
/////////////
/// UPDATE
///
/**
* @return void
* @since 3.1.0
*/
protected function EventUpdateComputeValues(): void
{
}
@@ -5921,7 +5980,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventUpdateBefore(): void
protected function EventCheckToUpdate(): void
{
}
@@ -5929,7 +5988,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventUpdateAfter(array $aEventData): void
protected function EventCheckToUpdateFailed(array $aData): void
{
}
@@ -5937,7 +5996,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventDeleteBefore(): void
protected function EventAboutToUpdate(): void
{
}
@@ -5945,7 +6004,51 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventDeleteAfter(): void
protected function EventUpdateDone(array $aData): void
{
}
//////////////
/// DELETE
///
/**
* @return void
* @since 3.1.0
*/
protected function EventCheckToDelete(): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventCheckToDeleteFailed(array $aData): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventAboutToDelete(): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventDeleteDone(): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventComputeValues(): void
{
}
@@ -5962,33 +6065,8 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventUnarchive(): void
protected function EventUnArchive(): void
{
}
/**
* @param string $sAttCode
* @param array $aReasons
* @param string $sTargetState
*
* @return int
* @since 3.1.0
*/
protected function GetExtensionsAttributeFlags(string $sAttCode, array &$aReasons, string $sTargetState): int
{
return OPT_ATT_NORMAL;
}
/**
* @param string $sAttCode
* @param array $aReasons
*
* @return int
* @since 3.1.0
*/
protected function GetExtensionsInitialStateAttributeFlags(string $sAttCode, array &$aReasons): int
{
return OPT_ATT_NORMAL;
}
}

View File

@@ -103,7 +103,7 @@ class ItopDataTestCase extends ItopTestCase
$this->CreateTestOrganization();
}
EventService::RegisterListener(EVENT_SERVICE_DB_OBJECT_RELOAD, [$this, 'CountObjectReload']);
EventService::RegisterListener(EVENT_DB_OBJECT_RELOAD, [$this, 'CountObjectReload']);
}
/**