Skip to content

Commit

Permalink
IP-202: As a content manager I can select to delete an existing probl…
Browse files Browse the repository at this point in the history
…em, so that I can remove it from the platform
  • Loading branch information
PavlosIsaris committed Nov 18, 2024
1 parent a82143e commit d1c6b25
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemTranslation;
use App\Repository\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemRepository;
use App\Repository\LanguageRepository;
use App\Repository\RepositoryException;
use App\Utils\FileHandler;
use App\ViewModels\CrowdSourcingProject\Problem\CreateEditProblem;
use App\ViewModels\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemsLandingPage;
Expand Down Expand Up @@ -102,6 +103,9 @@ public function storeProblem(array $attributes): int {
return $crowdSourcingProjectProblem->id;
}

/**
* @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');
Expand Down Expand Up @@ -130,7 +134,10 @@ public function deleteProblem(int $id): bool {
$problem = $this->crowdSourcingProjectProblemRepository->find($id);
// if the image is not the default one
// and if it does not start with "/images" (meaning it is a default public image)
if ($problem->img_url !== self::DEFAULT_IMAGE_PATH && !str_starts_with($problem->img_url, '/images')) {
// and if it does not start with "http" (meaning it is an external image)
if ($problem->img_url !== self::DEFAULT_IMAGE_PATH &&
!str_starts_with($problem->img_url, '/images') &&
!str_starts_with($problem->img_url, 'http')) {
FileHandler::deleteUploadedFile($problem->img_url, 'problem_img');
}

Expand Down

0 comments on commit d1c6b25

Please sign in to comment.