From 3b532532d1ff326bad8b908c3b79dd552c9fde97 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 23 Nov 2013 17:27:56 +0100 Subject: [PATCH] Post edit: post content can now be replaced --- src/Controllers/PostController.php | 2 +- src/Models/Model_Post.php | 12 ++++++++++-- src/Views/post-edit.phtml | 12 ++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 25ed9ef2..5f8a416a 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -572,7 +572,7 @@ class PostController private function doEdit($post, $isNew) { /* file contents */ - if (isset($_FILES['file'])) + if (!empty($_FILES['file']['name'])) { if (!$isNew) PrivilegesHelper::confirmWithException(Privilege::EditPostFile, PrivilegesHelper::getIdentitySubPrivilege($post->uploader)); diff --git a/src/Models/Model_Post.php b/src/Models/Model_Post.php index c941147b..38ac1b6e 100644 --- a/src/Models/Model_Post.php +++ b/src/Models/Model_Post.php @@ -267,7 +267,7 @@ class Model_Post extends AbstractModel $this->orig_name = basename($srcPath); $duplicatedPost = R::findOne('post', 'file_hash = ?', [$this->file_hash]); - if ($duplicatedPost !== null) + if ($duplicatedPost !== null and (!$this->id or $this->id != $duplicatedPost->id)) throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id); $dstPath = $this->getFullPath($this->name); @@ -276,6 +276,10 @@ class Model_Post extends AbstractModel move_uploaded_file($srcPath, $dstPath); else rename($srcPath, $dstPath); + + $thumbPath = self::getThumbDefaultPath($this->name); + if (file_exists($thumbPath)) + unlink($thumbPath); } @@ -298,8 +302,12 @@ class Model_Post extends AbstractModel $this->image_width = null; $this->image_height = null; + $thumbPath = self::getThumbDefaultPath($this->name); + if (file_exists($thumbPath)) + unlink($thumbPath); + $duplicatedPost = R::findOne('post', 'orig_name = ?', [$origName]); - if ($duplicatedPost !== null) + if ($duplicatedPost !== null and (!$this->id or $this->id != $duplicatedPost->id)) throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id); return; } diff --git a/src/Views/post-edit.phtml b/src/Views/post-edit.phtml index 3090cdc5..ab9860b5 100644 --- a/src/Views/post-edit.phtml +++ b/src/Views/post-edit.phtml @@ -34,6 +34,18 @@ + context->transport->post->uploader))): ?> +
+ +
+
+ +
+ +
+
+ + context->transport->post->uploader))): ?>