mirror of
https://github.com/flarum/core.git
synced 2025-10-11 23:14:29 +02:00
Simplify uploads, inject filesystem instances
This avoids injecting the Application god class and assembling default file locations in multiple places. In addition, we no longer use the `MountManager` for these uploads. It only added complexity (by moving tmp files around) and will not be available in the next major release of Flysystem. Note: Passing PSR upload streams to Intervention Image requires an explicit upgrade of the library. (Very likely, users have already updated to the newer versions, as the old constraint allowed it, but we should be explicit for correctness' sake.)
This commit is contained in:
@@ -9,12 +9,10 @@
|
||||
|
||||
namespace Flarum\Api\Controller;
|
||||
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
use Laminas\Diactoros\Response\EmptyResponse;
|
||||
use League\Flysystem\Adapter\Local;
|
||||
use League\Flysystem\Filesystem;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class DeleteLogoController extends AbstractDeleteController
|
||||
@@ -27,17 +25,18 @@ class DeleteLogoController extends AbstractDeleteController
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @var Application
|
||||
* @var FilesystemInterface
|
||||
*/
|
||||
protected $app;
|
||||
protected $uploadDir;
|
||||
|
||||
/**
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
* @param FilesystemInterface $uploadDir
|
||||
*/
|
||||
public function __construct(SettingsRepositoryInterface $settings, Application $app)
|
||||
public function __construct(SettingsRepositoryInterface $settings, FilesystemInterface $uploadDir)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->app = $app;
|
||||
$this->uploadDir = $uploadDir;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,10 +50,8 @@ class DeleteLogoController extends AbstractDeleteController
|
||||
|
||||
$this->settings->set('logo_path', null);
|
||||
|
||||
$uploadDir = new Filesystem(new Local($this->app->publicPath().'/assets'));
|
||||
|
||||
if ($uploadDir->has($path)) {
|
||||
$uploadDir->delete($path);
|
||||
if ($this->uploadDir->has($path)) {
|
||||
$this->uploadDir->delete($path);
|
||||
}
|
||||
|
||||
return new EmptyResponse(204);
|
||||
|
Reference in New Issue
Block a user