From c0305a56391de67f05386cc33a0004ecc54ffb16 Mon Sep 17 00:00:00 2001 From: Ruslan Baidan Date: Fri, 6 Dec 2024 16:43:54 +0100 Subject: [PATCH] Fixed the models removals, by correction of the analysis removal and the query to fetch only active models. --- src/Entity/Model.php | 2 +- src/Service/ModelService.php | 4 +++- src/Table/ModelTable.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Entity/Model.php b/src/Entity/Model.php index 90cf3f6f..662847fe 100755 --- a/src/Entity/Model.php +++ b/src/Entity/Model.php @@ -123,7 +123,7 @@ public function getAnr(): ?Anr return $this->anr; } - public function setAnr(Anr $anr): self + public function setAnr(?Anr $anr): self { $this->anr = $anr; diff --git a/src/Service/ModelService.php b/src/Service/ModelService.php index 6d30dae2..423d2d54 100755 --- a/src/Service/ModelService.php +++ b/src/Service/ModelService.php @@ -148,8 +148,10 @@ public function delete(int $id): void /** @var Model $model */ $model = $this->modelTable->findById($id); $model->setStatus(Model::STATUS_DELETED); + $anr = $model->getAnr(); + $model->setAnr(null); - $this->anrTable->remove($model->getAnr(), false); + $this->anrTable->remove($anr); $this->modelTable->save($model); } diff --git a/src/Table/ModelTable.php b/src/Table/ModelTable.php index 83a8ee09..fb542c28 100755 --- a/src/Table/ModelTable.php +++ b/src/Table/ModelTable.php @@ -56,11 +56,12 @@ public function findGenericsAndSpecificsByIds(array $specificModelsIds = []): ar { $queryBuilder = $this->getRepository()->createQueryBuilder('m') ->where('m.isGeneric = 1') - ->andWhere('m.anr IS NOT NULL'); + ->andWhere('m.status = ' . Model::STATUS_ACTIVE); if (!empty($specificModelsIds)) { $queryBuilder->orWhere($queryBuilder->expr()->andX( $queryBuilder->expr()->eq('m.isGeneric', 0), + $queryBuilder->expr()->eq('m.status', Model::STATUS_ACTIVE), $queryBuilder->expr()->in('m.id', array_map('\intval', $specificModelsIds)) )); }