A free open source IT asset/license management system
Revert multi-image exception (for now)
snipe49c57fd4b318
diff --git a/app/Console/Commands/RestoreFromBackup.php b/app/Console/Commands/RestoreFromBackup.phpindex 3ea454b419..4406d73de5 100644--- a/app/Console/Commands/RestoreFromBackup.php+++ b/app/Console/Commands/RestoreFromBackup.php@@ -588,7 +588,6 @@ class RestoreFromBackup extends Command}fclose($migrated_file);fclose($fp);- // $this->info("Wrote $ugly_file_name to $pretty_file_name");}if ($bar) {$bar->advance();diff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex ca674cb6db..d2b26d6a5b 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -69,7 +69,7 @@ class Asset extends Depreciableuse Acceptable;- public static function fileStorage(string $field = 'image'): FileStorage+ public static function fileStorage(): FileStorage{return FileStorage::Assets;}diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.phpindex a5cc7f4f6d..7c05480916 100755--- a/app/Models/AssetModel.php+++ b/app/Models/AssetModel.php@@ -34,7 +34,7 @@ class AssetModel extends SnipeModeluse SoftDeletes;use TwoColumnUniqueUndeletedTrait;- public static function fileStorage(string $field = 'image'): FileStorage+ public static function fileStorage(): FileStorage{return FileStorage::Models;}diff --git a/app/Models/Traits/HasImageUpload.php b/app/Models/Traits/HasImageUpload.phpindex 4772e72f0c..130cb58ec0 100644--- a/app/Models/Traits/HasImageUpload.php+++ b/app/Models/Traits/HasImageUpload.php@@ -10,13 +10,13 @@ use LogicException;* resolve their public upload directory via the FileStorage enum,* so call sites never pass raw string keys around.*- * Single-image models declare their one storage once:+ * The using model declares its storage once:** class User extends SnipeModel* {* use HasImageUpload;*- * public static function fileStorage(string $field = 'image'): FileStorage+ * public static function fileStorage(): FileStorage* {* return FileStorage::Avatars;* }@@ -25,44 +25,35 @@ use LogicException;* $user->imageUploadPath(); // 'avatars/'* $asset->imageUploadPath(); // 'assets/'*- * Multi-image models (Settings has logo, email_logo, favicon,- * default_avatar, etc.) switch on the field name:+ * This trait is for the common "one image per model" case.+ * Settings is an intentional outlier because its images (logo,+ * email_logo, favicon, default_avatar, etc.) live at different+ * paths including the root of `public/uploads/`, which does not fit+ * a single-dir resolver. Settings resolves its own paths explicitly+ * via SettingsController rather than using this trait.*- * public static function fileStorage(string $field = 'image'): FileStorage- * {- * return match ($field) {- * 'default_avatar' => FileStorage::Avatars,- * default => throw new LogicException("No storage mapping for {$field}"),- * };- * }- *- * This is separate from `HasUploads`, which handles the Files-tab- * attachment relationship (not model-owned image fields).+ * This is also separate from `HasUploads`, which handles the+ * Files-tab attachment relationship (not model-owned image fields).*/trait HasImageUpload{/**- * Return the FileStorage case for this model's image upload at- * the given field. Defaults to the `image` field, which covers- * the common single-image case. Multi-image models switch on- * `$field` to resolve the right case per field.- *+ * Return the FileStorage case for this model's image upload.* Must be in the public scope (`hasPublicScope() === true`).*/- abstract public static function fileStorage(string $field = 'image'): FileStorage;+ abstract public static function fileStorage(): FileStorage;/**- * Public upload directory for a specific image field on this- * model, with trailing slash, suitable for appending a filename.- * Defaults to the `image` field.+ * Public upload directory for this model's image, with trailing+ * slash, suitable for appending a filename.*/- public function imageUploadPath(string $field = 'image'): string+ public function imageUploadPath(): string{- $resource = static::fileStorage($field);+ $resource = static::fileStorage();$path = $resource->publicPath();if ($path === null) {throw new LogicException(- static::class.' uses HasImageUpload but '.$resource->value.' has no public scope for field '.$field+ static::class.' uses HasImageUpload but '.$resource->value.' has no public scope');}diff --git a/app/Models/User.php b/app/Models/User.phpindex 6d3816c3cf..79a4216a7f 100644--- a/app/Models/User.php+++ b/app/Models/User.php@@ -44,7 +44,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCouse HasImageUpload;use HasUploads;- public static function fileStorage(string $field = 'image'): FileStorage+ public static function fileStorage(): FileStorage{return FileStorage::Avatars;}