Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
luceos opened this issue Feb 6, 2025 · 0 comments
Labels

Comments

@luceos
Copy link
Contributor

luceos commented Feb 6, 2025

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
@luceos luceos added the bug label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant