[CORE][GSFile] Change actor_id paramenter of validateAndStoreFileAsAttachment to optional and reorder them and their usages

This commit is contained in:
Hugo Sales 2021-08-03 10:11:48 +00:00
parent 7bd88bd101
commit 88dd9e542f
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 14 additions and 6 deletions

View File

@ -102,7 +102,13 @@ class Avatar extends Controller
} else { } else {
throw new ClientException('Invalid form'); throw new ClientException('Invalid form');
} }
$attachment = GSFile::validateAndStoreFileAsAttachment($file, dest_dir: Common::config('avatar', 'dir'), is_local: true, actor_id: $gsactor_id); $attachment = GSFile::validateAndStoreFileAsAttachment(
$file,
dest_dir: Common::config('avatar', 'dir'),
actor_id: $gsactor_id,
title: _m("Avatar for Actor {$gsactor_id}"),
is_local: true
);
// Must get old id before inserting another one // Must get old id before inserting another one
$old_attachment = null; $old_attachment = null;
$avatar = DB::find('avatar', ['gsactor_id' => $gsactor_id]); $avatar = DB::find('avatar', ['gsactor_id' => $gsactor_id]);

View File

@ -116,9 +116,11 @@ END;
$processed_attachments = []; $processed_attachments = [];
foreach ($attachments as $f) { // where $f is a Symfony\Component\HttpFoundation\File\UploadedFile foreach ($attachments as $f) { // where $f is a Symfony\Component\HttpFoundation\File\UploadedFile
$processed_attachments[] = GSFile::validateAndStoreFileAsAttachment( $processed_attachments[] = GSFile::validateAndStoreFileAsAttachment(
$f, Common::config('attachments', 'dir'), $f,
Security::sanitize($f->getClientOriginalName()), dest_dir: Common::config('attachments', 'dir'),
is_local: true, actor_id: $actor_id actor_id: $actor_id,
title: Security::sanitize($f->getClientOriginalName()),
is_local: true
); );
} }

View File

@ -65,9 +65,9 @@ class GSFile
*/ */
public static function validateAndStoreFileAsAttachment(SplFileInfo $file, public static function validateAndStoreFileAsAttachment(SplFileInfo $file,
string $dest_dir, string $dest_dir,
int $actor_id,
?string $title = null, ?string $title = null,
bool $is_local = true, bool $is_local = true): Attachment
int $actor_id = null): Attachment
{ {
$hash = null; $hash = null;
Event::handle('HashFile', [$file->getPathname(), &$hash]); Event::handle('HashFile', [$file->getPathname(), &$hash]);