From 2ae7392dead9e42ec28e637ff20a3d45c6e512f4 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 13 Oct 2015 16:52:45 +1030 Subject: [PATCH] Publish core/extension assets Core assets are copied into the root/assets directory on installation. The contents of an "assets" directory within any extension is copied into root/assets/extensions/{name}/ whenever the extension is enabled, and deleted whenever the extension is uninstalled. Still needs to be refactored --- src/Extension/ExtensionManager.php | 20 +++++++++++++++----- src/Install/Console/InstallCommand.php | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index 31c7b4700..b9760d37b 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -14,10 +14,11 @@ use Flarum\Core; use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; use Flarum\Event\ExtensionWasUninstalled; +use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepository; -use Illuminate\Contracts\Container\Container; use Flarum\Database\Migrator; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Filesystem\Filesystem; class ExtensionManager { @@ -32,12 +33,18 @@ class ExtensionManager */ protected $dispatcher; - public function __construct(SettingsRepository $config, Container $app, Migrator $migrator, Dispatcher $dispatcher) + /** + * @var Filesystem + */ + protected $filesystem; + + public function __construct(SettingsRepository $config, Application $app, Migrator $migrator, Dispatcher $dispatcher, Filesystem $filesystem) { $this->config = $config; $this->app = $app; $this->migrator = $migrator; $this->dispatcher = $dispatcher; + $this->filesystem = $filesystem; } public function getInfo() @@ -137,7 +144,10 @@ class ExtensionManager */ protected function publishAssets($extension) { - // TODO: implement + $this->filesystem->copyDirectory( + $this->app->basePath().'/extensions/'.$extension.'/assets', + $this->app->basePath().'/assets/extensions/'.$extension + ); } /** @@ -147,7 +157,7 @@ class ExtensionManager */ protected function unpublishAssets($extension) { - // TODO: implement + $this->filesystem->deleteDirectory($this->app->basePath().'/assets/extensions/'.$extension); } /** @@ -159,7 +169,7 @@ class ExtensionManager */ public function getAsset($extension, $path) { - // TODO: implement + return $this->app->basePath().'/assets/extensions/'.$extension.$path; } public function migrate($extension, $up = true) diff --git a/src/Install/Console/InstallCommand.php b/src/Install/Console/InstallCommand.php index 26f3c3abd..3e7138dfc 100644 --- a/src/Install/Console/InstallCommand.php +++ b/src/Install/Console/InstallCommand.php @@ -17,6 +17,7 @@ use Flarum\Core\User; use Flarum\Core\Group; use Flarum\Core\Permission; use Illuminate\Contracts\Foundation\Application; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Arr; use Illuminate\Validation\Factory; use PDO; @@ -38,11 +39,21 @@ class InstallCommand extends AbstractCommand */ protected $application; - public function __construct(Application $application) + /** + * @var Filesystem + */ + protected $filesystem; + + /** + * @param Application $application + * @param Filesystem $filesystem + */ + public function __construct(Application $application, Filesystem $filesystem) { $this->application = $application; parent::__construct(); + $this->filesystem = $filesystem; } protected function configure() @@ -331,7 +342,10 @@ class InstallCommand extends AbstractCommand protected function publishAssets() { - // TODO + $this->filesystem->copyDirectory( + __DIR__.'/../../../assets', + $this->application->basePath().'/assets' + ); } protected function getConfigFile()