Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix in case of update after adding new language #36

Merged
merged 4 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Entity/ImageSliderLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
18 changes: 15 additions & 3 deletions src/Form/DataHandler/ImageSliderFormDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ($imageSliderLang->getImage() !== null) {
$this->eraseFile($imageSliderLang->getImage());
}
$imageSliderLang->setImage($this->uploadFile($data['image'][$langId]));
}

if (!empty($data['image_mobile'][$langId])) {
$this->eraseFile($imageSliderLang->getImageMobile());
if ($imageSliderLang->getImage() !== null) {
$this->eraseFile($imageSliderLang->getImageMobile());
}
$imageSliderLang->setImageMobile($this->uploadFile($data['image_mobile'][$langId]));
}

if ($newImageSliderLang) {
$imageSlide->addImageSliderLang($imageSliderLang);
}
}

$this->entityManager->flush();
Expand Down
6 changes: 3 additions & 3 deletions src/Installer/ImageSliderInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down