aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DbQuery.php5
-rw-r--r--src/Handlers/NoteHandler.php10
-rw-r--r--src/Models/Attachment.php2
3 files changed, 16 insertions, 1 deletions
diff --git a/src/DbQuery.php b/src/DbQuery.php
index 6fd32a1..dddb581 100644
--- a/src/DbQuery.php
+++ b/src/DbQuery.php
@@ -194,4 +194,9 @@ class DbQuery
return $out;
});
}
+
+ public function fetchValues(SQLite3 $db): array
+ {
+ return array_map(fn ($row) => $row[0], $this->fetchRows($db));
+ }
} \ No newline at end of file
diff --git a/src/Handlers/NoteHandler.php b/src/Handlers/NoteHandler.php
index 4ce3179..726b773 100644
--- a/src/Handlers/NoteHandler.php
+++ b/src/Handlers/NoteHandler.php
@@ -35,6 +35,16 @@ class NoteHandler implements Handler
$note->setTags($_POST["tag"]);
$note->save($db);
+ $deleteAttachments = $_POST['attachment_delete'] ?? [];
+ $deleteAttachments = array_filter($deleteAttachments, fn ($ok) => (bool)(int)$ok);
+ $deleteAttachments = array_keys($deleteAttachments);
+ $deleteAttachments = Attachment::byIds($db, $deleteAttachments);
+ $deleteAttachments = array_filter($deleteAttachments, fn (Attachment $att) => $att->getNoteId() === $note->getId());
+
+ /** @var Attachment $att */
+ foreach ($deleteAttachments as $att)
+ $att->delete($db, $env->attachmentsPath());
+
if (isset($_FILES['attachments']))
Attachment::createFromUploads($env->db(), $env->attachmentsPath(), $note, $_FILES['attachments']);
}
diff --git a/src/Models/Attachment.php b/src/Models/Attachment.php
index b627d33..bbd8fc4 100644
--- a/src/Models/Attachment.php
+++ b/src/Models/Attachment.php
@@ -70,7 +70,7 @@ class Attachment
LEFT JOIN note_attachments na
ON na.hash = a.hash
WHERE na.id IS NULL
- "))->fetchRows($db) as $hash) {
+ "))->fetchValues($db) as $hash) {
self::deleteFileByHash($attachmentPath, $hash);
}