From c35c5176abc998e3c6420a56fc0867a34c8419e0 Mon Sep 17 00:00:00 2001 From: Kostas Papandreou Date: Tue, 17 Dec 2024 17:18:51 +0200 Subject: [PATCH] IP-327: fix bug when a content-manager changes status of problem --- .../Problem/ProblemManager.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/BusinessLogicLayer/Problem/ProblemManager.php b/app/BusinessLogicLayer/Problem/ProblemManager.php index 0599f3d1..2a5b3311 100644 --- a/app/BusinessLogicLayer/Problem/ProblemManager.php +++ b/app/BusinessLogicLayer/Problem/ProblemManager.php @@ -76,22 +76,23 @@ public function getCreateEditProblemViewModel(?int $id = null): CreateEditProble } public function storeProblem(array $attributes): int { - if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) { - $imgPath = FileHandler::uploadAndGetPath($attributes['problem-image'], 'problem_img'); - } - $crowdSourcingProjectProblem = Problem::create([ 'project_id' => $attributes['problem-owner-project'], 'user_creator_id' => Auth::id(), 'slug' => Str::random(16), // temporary - will be changed after record creation 'status_id' => $attributes['problem-status'], - 'img_url' => $imgPath, 'default_language_id' => $attributes['problem-default-language'], ]); $crowdSourcingProjectProblem->slug = Str::slug($attributes['problem-title'] . '-' . $crowdSourcingProjectProblem->id); $crowdSourcingProjectProblem->save(); + if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) { + $imgPath = FileHandler::uploadAndGetPath($attributes['problem-image'], 'problem_img'); + $crowdSourcingProjectProblem->img_url = $imgPath; + $crowdSourcingProjectProblem->save(); + } + $crowdSourcingProjectProblem->defaultTranslation()->create([ 'title' => $attributes['problem-title'], 'description' => $attributes['problem-description'], @@ -104,15 +105,16 @@ public function storeProblem(array $attributes): int { * @throws RepositoryException */ public function updateProblem(int $id, array $attributes) { - if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) { - $imgPath = FileHandler::uploadAndGetPath($attributes['problem-image'], 'problem_img'); - } - $modelAttributes['project_id'] = $attributes['problem-owner-project']; $modelAttributes['slug'] = $attributes['problem-slug']; $modelAttributes['status_id'] = $attributes['problem-status']; - $modelAttributes['img_url'] = $imgPath; $modelAttributes['default_language_id'] = $attributes['problem-default-language']; + + if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) { + $imgPath = FileHandler::uploadAndGetPath($attributes['problem-image'], 'problem_img'); + $modelAttributes['img_url'] = $imgPath; + } + $this->problemRepository->update($modelAttributes, $id); $defaultTranslation = [