diff --git a/src/Core/GSFile.php b/src/Core/GSFile.php index 5bf3b597d9..0ea71748a9 100644 --- a/src/Core/GSFile.php +++ b/src/Core/GSFile.php @@ -47,7 +47,7 @@ class GSFile // The following properly gets the mimetype with `file` or other // available methods, so should be safe $mimetype = $sfile->getMimeType(); - Event::handle('AttachmentValidation', [&$sfile, &$mimetype]); + Event::handle('AttachmentValidation', [&$sfile, &$mimetype, &$title]); $attachment = Attachment::create([ 'file_hash' => $hash, 'gsactor_id' => $actor_id, @@ -55,6 +55,7 @@ class GSFile 'title' => $title ?: _m('Untitled attachment'), 'filename' => $hash, 'is_local' => $is_local, + 'size' => $sfile->getSize(), ]); $sfile->move($dest_dir, $hash); DB::persist($attachment); diff --git a/src/Entity/Attachment.php b/src/Entity/Attachment.php index 10520e6d7c..ca943b6d11 100644 --- a/src/Entity/Attachment.php +++ b/src/Entity/Attachment.php @@ -54,6 +54,7 @@ class Attachment extends Entity private ?bool $is_local; private ?int $source; private ?int $scope; + private ?int $size; private \DateTimeInterface $modified; public function setId(int $id): self @@ -177,6 +178,17 @@ class Attachment extends Entity return $this->scope; } + public function setSize(?int $size): self + { + $this->size = $size; + return $this; + } + + public function getSize(): ?int + { + return $this->size; + } + public function setModified(DateTimeInterface $modified): self { $this->modified = $modified; @@ -259,6 +271,7 @@ class Attachment extends Entity 'is_local' => ['type' => 'bool', 'description' => 'whether the file is stored locally'], 'source' => ['type' => 'int', 'default' => null, 'description' => 'Source of the Attachment (upload, TFN, embed)'], 'scope' => ['type' => 'int', 'default' => null, 'description' => 'visibility scope for this attachment'], + 'size' => ['type' => 'int', 'description' => 'size of resource when available'], 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], 'primary key' => ['id'],