diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 5367f10ff6..5548b4b4d5 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -5108,8 +5108,8 @@ abstract class DBObject implements iDisplay protected function GetReferencingObjectsForDeletion($bAllowAllData = false) { $aDependentObjects = []; - $aRererencingMe = MetaModel::EnumReferencingClasses(get_class($this)); - foreach ($aRererencingMe as $sRemoteClass => $aExtKeys) { + $aReferencingMe = MetaModel::EnumReferencingClasses(get_class($this)); + foreach ($aReferencingMe as $sRemoteClass => $aExtKeys) { /** @var \AttributeExternalKey $oExtKeyAttDef */ foreach ($aExtKeys as $sExtKeyAttCode => $oExtKeyAttDef) { // skip if external key doesn't require the deletion cascading diff --git a/datamodels/2.x/combodo-data-feature-removal/src/Service/DeletionPlanService.php b/datamodels/2.x/combodo-data-feature-removal/src/Service/DeletionPlanService.php index 5aa49e43cb..287e70da0e 100644 --- a/datamodels/2.x/combodo-data-feature-removal/src/Service/DeletionPlanService.php +++ b/datamodels/2.x/combodo-data-feature-removal/src/Service/DeletionPlanService.php @@ -32,10 +32,12 @@ class DeletionPlanService } /** - * @param array $aClasses + * @param array|null $aClasses * * @return array<\Combodo\iTop\DataFeatureRemoval\Entity\DeletionPlanSummaryEntity> * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MySQLException */ public function GetDeletionPlanSummary(?array $aClasses): array { @@ -44,13 +46,7 @@ class DeletionPlanService return $aSummary; } - $oDeletionPlan = new DeletionPlan(); - foreach ($aClasses as $sClass) { - $aObjects = $this->GetAllObjects($sClass); - foreach ($aObjects as $oObject) { - $oObject->CheckToDelete($oDeletionPlan); - } - } + $oDeletionPlan = $this->GetDeletionPlan($aClasses); foreach ($oDeletionPlan->ListUpdates() as $sClass => $aUpdates) { $oDeletionPlanSummaryEntity = new DeletionPlanSummaryEntity($sClass); @@ -100,32 +96,8 @@ class DeletionPlanService */ public function ExecuteDeletionPlan(array $aClasses): array { - $oDeletionPlan = new DeletionPlan(); - foreach ($aClasses as $sClass) { - $aObjects = $this->GetAllObjects($sClass); - foreach ($aObjects as $oObject) { - $oObject->CheckToDelete($oDeletionPlan); - } - } + $oDeletionPlan = $this->GetDeletionPlan($aClasses); - return $this->DoDelete($oDeletionPlan); - - } - - /** - * @param DeletionPlan $oDeletionPlan - * - * @return array<\Combodo\iTop\DataFeatureRemoval\Entity\DeletionPlanSummaryEntity> - * @throws \Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalException - * @throws \CoreCannotSaveObjectException - * @throws \CoreException - * @throws \CoreUnexpectedValue - * @throws \MySQLException - * @throws \MySQLHasGoneAwayException - * @throws \OQLException - */ - private function DoDelete(DeletionPlan $oDeletionPlan): array - { if (count($oDeletionPlan->GetIssues()) > 0) { throw new DataFeatureRemovalException("Deletion Plan cannot be executed due to issues"); } @@ -173,4 +145,25 @@ class DeletionPlanService return $aSummary; } + + /** + * @param array $aClasses + * + * @return \DeletionPlan + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MySQLException + */ + public function GetDeletionPlan(array $aClasses): DeletionPlan + { + $oDeletionPlan = new DeletionPlan(); + foreach ($aClasses as $sClass) { + $aObjects = $this->GetAllObjects($sClass); + foreach ($aObjects as $oObject) { + $oObject->CheckToDelete($oDeletionPlan); + } + } + + return $oDeletionPlan; + } }