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

This commit is contained in:
Eric Espie
2022-12-23 10:37:08 +01:00
parent 0383fb124b
commit 1cac189077
3 changed files with 14 additions and 81 deletions

View File

@@ -5665,15 +5665,6 @@ JS
/// CREATE
///
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventCreateComputeValues(): void
{
$this->FireEvent(EVENT_DB_CREATE_COMPUTE_VALUES);
}
/**
* @inheritDoc
* @since 3.1.0
@@ -5723,15 +5714,6 @@ JS
/// UPDATE
///
/**
* @inheritDoc
* @since 3.1.0
*/
final protected function EventUpdateComputeValues(): void
{
$this->FireEvent(EVENT_DB_UPDATE_COMPUTE_VALUES);
}
/**
* @inheritDoc
* @since 3.1.0

View File

@@ -186,23 +186,6 @@
</menu>
</menus>
<events>
<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>
@@ -292,23 +275,6 @@
</event_datum>
</event_data>
</event>
<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>

View File

@@ -2357,6 +2357,15 @@ abstract class DBObject implements iDisplay
$this->DoComputeValues();
}
// Ultimate check - ensure DB integrity
$this->SetReadOnly('No modification allowed during CheckToCreate');
if ($this->IsNew()) {
$this->EventCheckToCreate();
} else {
$this->EventCheckToUpdate();
}
$this->SetReadWrite();
$this->DoCheckToWrite();
$oKPI->ComputeStats('CheckToWrite', get_class($this));
if (count($this->m_aCheckIssues) == 0)
@@ -2366,6 +2375,11 @@ abstract class DBObject implements iDisplay
else
{
$this->m_bCheckStatus = false;
if ($this->IsNew()) {
$this->EventCheckToCreateFailed(['check_issues' => $this->m_aCheckIssues]);
} else {
$this->EventCheckToUpdateFailed(['check_issues' => $this->m_aCheckIssues]);
}
}
}
return array($this->m_bCheckStatus, $this->m_aCheckIssues, $this->m_bSecurityIssue);
@@ -2965,7 +2979,6 @@ 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->EventCreateRequested();
$this->OnInsert();
@@ -2982,14 +2995,8 @@ 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);
@@ -3174,7 +3181,6 @@ abstract class DBObject implements iDisplay
try
{
$this->EventUpdateComputeValues();
$this->DoComputeValues();
$this->ComputeStopWatchesDeadline(false);
$this->EventUpdateRequested();
@@ -3192,14 +3198,9 @@ abstract class DBObject implements iDisplay
return $this->m_iKey;
}
// Ultimate check - ensure DB integrity
$this->SetReadOnly('No modification allowed during CheckToWrite');
$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()]);
}
@@ -5908,14 +5909,6 @@ abstract class DBObject implements iDisplay
/// CREATE
///
/**
* @return void
* @since 3.1.0
*/
protected function EventCreateComputeValues(): void
{
}
/**
* @return void
* @since 3.1.0
@@ -5960,14 +5953,6 @@ abstract class DBObject implements iDisplay
/// UPDATE
///
/**
* @return void
* @since 3.1.0
*/
protected function EventUpdateComputeValues(): void
{
}
/**
* @return void
* @since 3.1.0