Skip to content

Commit

Permalink
#9253 Fix unwanted file deletion when editing announcement
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWr authored and asmecher committed Nov 8, 2023
1 parent 9fa7d30 commit 0f04c23
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions classes/announcement/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ public function add(Announcement $announcement): int
return $id;
}

/** @copydoc DAO::update() */
/**
* Update an object in the database
*
* Deletes the old image if it has been removed, or a new image has
* been uploaded.
*/
public function edit(Announcement $announcement, array $params)
{
$newAnnouncement = clone $announcement;
Expand All @@ -156,12 +161,14 @@ public function edit(Announcement $announcement, array $params)

$this->dao->update($newAnnouncement);

if ($announcement->getImage()) {
$image = $newAnnouncement->getImage();
$hasNewImage = $image && $image['temporaryFileId'];

if ((!$image || $hasNewImage) && $announcement->getImage()) {
$this->deleteImage($announcement);
}

$image = $newAnnouncement->getImage();
if ($image && $image['temporaryFileId']) {
if ($hasNewImage) {
$this->handleImageUpload($newAnnouncement);
}
}
Expand Down

0 comments on commit 0f04c23

Please sign in to comment.