N°4756 - Ease extensibility for CRUD operations : Reduce events after review

This commit is contained in:
Eric Espie
2023-01-04 12:23:23 +01:00
parent 259eb60f97
commit cd17eb484a
3 changed files with 12 additions and 277 deletions

View File

@@ -5669,36 +5669,18 @@ JS
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCreateRequested(): void
final protected function EventCheckToWrite(): void
{
$this->FireEvent(EVENT_DB_CREATE_REQUESTED);
$this->FireEvent(EVENT_DB_CHECK_TO_WRITE);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCheckToCreate(): void
final protected function EventCheckToWriteFailed(array $aIssues): void
{
$this->FireEvent(EVENT_DB_CHECK_TO_CREATE);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCheckToCreateFailed(array $aIssues): void
{
$this->FireEvent(EVENT_DB_CHECK_TO_CREATE_FAILED, ['check_issues' => $aIssues]);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventAboutToCreate(): void
{
$this->FireEvent(EVENT_DB_ABOUT_TO_CREATE);
$this->FireEvent(EVENT_DB_CHECK_TO_WRITE_FAILED, ['check_issues' => $aIssues]);
}
/**
@@ -5714,42 +5696,6 @@ JS
/// UPDATE
///
/**
* @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 $aIssues): void
{
$this->FireEvent(EVENT_DB_CHECK_TO_UPDATE_FAILED, ['check_issues' => $aIssues]);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventAboutToUpdate(): void
{
$this->FireEvent(EVENT_DB_ABOUT_TO_UPDATE);
}
/**
* @inheritDoc
* @since 3.1.0
@@ -5781,15 +5727,6 @@ JS
$this->FireEvent(EVENT_DB_CHECK_TO_DELETE_FAILED, ['check_issues' => $aIssues]);
}
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventAboutToDelete(): void
{
$this->FireEvent(EVENT_DB_ABOUT_TO_DELETE);
}
/**
* @inheritDoc
* @since 3.1.0

View File

@@ -186,25 +186,8 @@
</menu>
</menus>
<events>
<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>
<replaces>DBObject::OnInsert</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_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>
<event id="EVENT_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>
@@ -220,17 +203,12 @@
</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>
<event id="EVENT_DB_CHECK_TO_WRITE_FAILED" _delta="define">
<description>A check has failed, it is not possible to write the object in DB</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>
@@ -241,23 +219,6 @@
</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>
<replaces>DBObject::OnInsert</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_DONE" _delta="define">
<description>An object has been created into the database. The modifications can be propagated to other objects.</description>
<sources>
@@ -275,78 +236,6 @@
</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>
</sources>
<replaces>DBObject::OnUpdate, DBObject::DoComputeValues</replaces>
<event_data>
<event_datum id="object">
<description>The object updated</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" _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>
</sources>
<replaces>DBObject::OnUpdate</replaces>
<event_data>
<event_datum id="object">
<description>The object updated</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_DONE" _delta="define">
<description>An object has been updated into the database and reloaded.</description>
<sources>
@@ -402,23 +291,6 @@
</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>
</sources>
<replaces>DBObject::OnDelete</replaces>
<event_data>
<event_datum id="object">
<description>The object deleted</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_DELETE_DONE" _delta="define">
<description>An object has been deleted into the database</description>
<sources>

View File

@@ -2361,11 +2361,7 @@ abstract class DBObject implements iDisplay
// Ultimate check - ensure DB integrity
$this->SetReadOnly('No modification allowed during CheckToCreate');
if ($this->IsNew()) {
$this->EventCheckToCreate();
} else {
$this->EventCheckToUpdate();
}
$this->EventCheckToWrite();
$this->SetReadWrite();
$this->DoCheckToWrite();
@@ -2377,11 +2373,7 @@ abstract class DBObject implements iDisplay
else
{
$this->m_bCheckStatus = false;
if ($this->IsNew()) {
$this->EventCheckToCreateFailed($this->m_aCheckIssues);
} else {
$this->EventCheckToUpdateFailed($this->m_aCheckIssues);
}
$this->EventCheckToWriteFailed($this->m_aCheckIssues);
}
}
return array($this->m_bCheckStatus, $this->m_aCheckIssues, $this->m_bSecurityIssue);
@@ -2978,7 +2970,6 @@ abstract class DBObject implements iDisplay
// Ensure the update of the values (we are accessing the data directly)
$this->DoComputeValues();
$this->EventCreateRequested();
$this->OnInsert();
if ($this->m_iKey < 0) {
@@ -2999,10 +2990,6 @@ abstract class DBObject implements iDisplay
}
$this->ComputeStopWatchesDeadline(true);
$this->SetReadOnly('No modification allowed during The Event :'.EVENT_DB_ABOUT_TO_CREATE);
$this->EventAboutToCreate();
$this->SetReadWrite();
$iTransactionRetry = 1;
$bIsTransactionEnabled = MetaModel::GetConfig()->Get('db_core_transactions_enabled');
if ($bIsTransactionEnabled) {
@@ -3181,7 +3168,6 @@ abstract class DBObject implements iDisplay
{
$this->DoComputeValues();
$this->ComputeStopWatchesDeadline(false);
$this->EventUpdateRequested();
$this->OnUpdate();
// Freeze the changes at this point
@@ -3233,9 +3219,6 @@ 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_DB_ABOUT_TO_UPDATE);
$this->EventAboutToUpdate();
$this->SetReadWrite();
while ($iTransactionRetry > 0)
{
@@ -3614,7 +3597,6 @@ abstract class DBObject implements iDisplay
return;
}
$this->EventAboutToDelete();
$this->OnDelete();
// Activate any existing trigger
@@ -5913,7 +5895,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventCreateRequested(): void
protected function EventCheckToWrite(): void
{
}
@@ -5921,23 +5903,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
protected function EventCheckToCreate(): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventCheckToCreateFailed(array $aIssues): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventAboutToCreate(): void
protected function EventCheckToWriteFailed(array $aIssues): void
{
}
@@ -5953,38 +5919,6 @@ abstract class DBObject implements iDisplay
/// UPDATE
///
/**
* @return void
* @since 3.1.0
*/
protected function EventUpdateRequested(): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventCheckToUpdate(): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventCheckToUpdateFailed(array $aIssues): void
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventAboutToUpdate(): void
{
}
/**
* @return void
* @since 3.1.0
@@ -6013,14 +5947,6 @@ abstract class DBObject implements iDisplay
{
}
/**
* @return void
* @since 3.1.0
*/
protected function EventAboutToDelete(): void
{
}
/**
* @return void
* @since 3.1.0