From eca51ca6acea01449af94e5f1a09d57be1461d1c Mon Sep 17 00:00:00 2001 From: Carmine Di Gruttola Date: Mon, 28 Aug 2023 09:53:35 +0200 Subject: [PATCH 1/3] Fix in case of update after adding new language --- .../DataHandler/ImageSliderFormDataHandler.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Form/DataHandler/ImageSliderFormDataHandler.php b/src/Form/DataHandler/ImageSliderFormDataHandler.php index ef64367..fd8977b 100644 --- a/src/Form/DataHandler/ImageSliderFormDataHandler.php +++ b/src/Form/DataHandler/ImageSliderFormDataHandler.php @@ -126,8 +126,12 @@ public function update($id, array $data): int $langId = (int) $language['id_lang']; $imageSliderLang = $imageSlide->getImageSliderLangByLangId($langId); + $newImageSliderLang = false; if (null === $imageSliderLang) { - continue; + $imageSliderLang = new ImageSliderLang(); + $lang = $this->langRepository->findOneById($langId); + $imageSliderLang->setLang($lang); + $newImageSliderLang = true; } $imageSliderLang @@ -137,14 +141,22 @@ public function update($id, array $data): int ->setDescription($data['description'][$langId] ?? ''); if (!empty($data['image'][$langId])) { - $this->eraseFile($imageSliderLang->getImage()); + if (!$newImageSliderLang) { + $this->eraseFile($imageSliderLang->getImage()); + } $imageSliderLang->setImage($this->uploadFile($data['image'][$langId])); } if (!empty($data['image_mobile'][$langId])) { - $this->eraseFile($imageSliderLang->getImageMobile()); + if (!$newImageSliderLang) { + $this->eraseFile($imageSliderLang->getImageMobile()); + } $imageSliderLang->setImageMobile($this->uploadFile($data['image_mobile'][$langId])); } + + if ($newImageSliderLang) { + $imageSlide->addImageSliderLang($imageSliderLang); + } } $this->entityManager->flush(); From 2afc8a4e8ddcbca01ed4379cb76cc3ebd8ee3aa7 Mon Sep 17 00:00:00 2001 From: Carmine Di Gruttola Date: Tue, 12 Sep 2023 10:14:59 +0200 Subject: [PATCH 2/3] fixer --- src/Form/DataHandler/ImageSliderFormDataHandler.php | 2 +- src/Installer/ImageSliderInstaller.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Form/DataHandler/ImageSliderFormDataHandler.php b/src/Form/DataHandler/ImageSliderFormDataHandler.php index fd8977b..4a6a83e 100644 --- a/src/Form/DataHandler/ImageSliderFormDataHandler.php +++ b/src/Form/DataHandler/ImageSliderFormDataHandler.php @@ -156,7 +156,7 @@ public function update($id, array $data): int if ($newImageSliderLang) { $imageSlide->addImageSliderLang($imageSliderLang); - } + } } $this->entityManager->flush(); diff --git a/src/Installer/ImageSliderInstaller.php b/src/Installer/ImageSliderInstaller.php index 5d5756c..41395fc 100644 --- a/src/Installer/ImageSliderInstaller.php +++ b/src/Installer/ImageSliderInstaller.php @@ -82,9 +82,9 @@ public function createTables(): bool ->setData($databaseData) ->buildQuery(); - return $createTableAction->execute() && - $addColumnsAction->execute() && - $modifyColumnsAction->execute(); + return $createTableAction->execute() + && $addColumnsAction->execute() + && $modifyColumnsAction->execute(); } /** From 2b6034f66051f2352cf48e9d0550b307de69188c Mon Sep 17 00:00:00 2001 From: Carmine Di Gruttola Date: Tue, 12 Sep 2023 10:30:46 +0200 Subject: [PATCH 3/3] fixer --- src/Entity/ImageSliderLang.php | 8 ++++---- src/Form/DataHandler/ImageSliderFormDataHandler.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Entity/ImageSliderLang.php b/src/Entity/ImageSliderLang.php index 5c9ba5e..6332a3b 100644 --- a/src/Entity/ImageSliderLang.php +++ b/src/Entity/ImageSliderLang.php @@ -179,9 +179,9 @@ public function setDescription(string $description): ImageSliderLang } /** - * @return string + * @return string|null */ - public function getImage(): string + public function getImage(): ?string { return $this->image; } @@ -199,9 +199,9 @@ public function setImage(string $image): ImageSliderLang } /** - * @return string + * @return string|null */ - public function getImageMobile(): string + public function getImageMobile(): ?string { return $this->imageMobile; } diff --git a/src/Form/DataHandler/ImageSliderFormDataHandler.php b/src/Form/DataHandler/ImageSliderFormDataHandler.php index 4a6a83e..273c22a 100644 --- a/src/Form/DataHandler/ImageSliderFormDataHandler.php +++ b/src/Form/DataHandler/ImageSliderFormDataHandler.php @@ -141,14 +141,14 @@ public function update($id, array $data): int ->setDescription($data['description'][$langId] ?? ''); if (!empty($data['image'][$langId])) { - if (!$newImageSliderLang) { + if ($imageSliderLang->getImage() !== null) { $this->eraseFile($imageSliderLang->getImage()); } $imageSliderLang->setImage($this->uploadFile($data['image'][$langId])); } if (!empty($data['image_mobile'][$langId])) { - if (!$newImageSliderLang) { + if ($imageSliderLang->getImage() !== null) { $this->eraseFile($imageSliderLang->getImageMobile()); } $imageSliderLang->setImageMobile($this->uploadFile($data['image_mobile'][$langId]));