Skip to content

Util saves upload method using class name instead of adapter registration key #431

@luceos

Description

@luceos

The Util saves the adapter with column upload_method as the shortened FQCN in the database, but registration of adapters is done using a custom string.

As such when instantiation occurs, Manager cannot instantiate the given adapter because it doesn't match:

    public function setMethod(?UploadAdapter $adapter = null): string
    {
        return $adapter ? Str::lower(Str::afterLast($adapter::class, '\\')) : 'private-shared';
    }

and

    public function instantiate(string $adapter): UploadAdapter
    {
        $configured = $this->adapters()
            // Drops adapters that cannot be instantiated due to missing packages.
            ->filter(function ($available) {
                return $available;
            })
            ->get($adapter);

        if (!$configured) {
            throw new ValidationException(['upload' => "No adapter configured for $adapter"]);
        }

        $method = Str::camel($adapter);

        $driver = $this->events->until(new Instantiate($adapter, $this->util));

        if (!$driver && !method_exists($this, $method)) {
            throw new ValidationException(['upload' => "Cannot instantiate adapter $adapter"]);
        }

        return $driver ?? $this->{$method}($this->util);
    }

with the example:

BlomstraObjectStorage being saved as upload_method blomstraobjectstorage whereas the adapter is in fact registered with the Manager as blomstra.

flarum.ERROR: Flarum\Foundation\ValidationException: No adapter configured for blomstraobjectstorage  in /var/www/vendor/fof/upload/src/Adapters/Manager.php:70

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugkeepIssues that should not be closed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions