diff --git a/extensions/package-manager/src/Command/MinorFlarumUpdateHandler.php b/extensions/package-manager/src/Command/MinorFlarumUpdateHandler.php index 26224beb5..5a15709be 100755 --- a/extensions/package-manager/src/Command/MinorFlarumUpdateHandler.php +++ b/extensions/package-manager/src/Command/MinorFlarumUpdateHandler.php @@ -7,6 +7,8 @@ namespace SychO\PackageManager\Command; use Composer\Console\Application; +use Illuminate\Contracts\Events\Dispatcher; +use SychO\PackageManager\Event\FlarumUpdated; use SychO\PackageManager\Exception\ComposerUpdateFailedException; use SychO\PackageManager\LastUpdateCheck; use Symfony\Component\Console\Input\ArrayInput; @@ -24,14 +26,21 @@ class MinorFlarumUpdateHandler */ protected $lastUpdateCheck; + /** + * @var Dispatcher + */ + protected $events; + /** * @param Application $composer * @param LastUpdateCheck $lastUpdateCheck + * @param Dispatcher $events */ - public function __construct(Application $composer, LastUpdateCheck $lastUpdateCheck) + public function __construct(Application $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events) { $this->composer = $composer; $this->lastUpdateCheck = $lastUpdateCheck; + $this->events = $events; } /** @@ -60,6 +69,10 @@ class MinorFlarumUpdateHandler $this->lastUpdateCheck->forget('flarum/*', true); + $this->events->dispatch( + new FlarumUpdated() + ); + return true; } } diff --git a/extensions/package-manager/src/Command/RemoveExtensionHandler.php b/extensions/package-manager/src/Command/RemoveExtensionHandler.php index 27f094c38..e7eecf0c1 100755 --- a/extensions/package-manager/src/Command/RemoveExtensionHandler.php +++ b/extensions/package-manager/src/Command/RemoveExtensionHandler.php @@ -1,9 +1,15 @@ composer = $composer; $this->extensions = $extensions; + $this->events = $events; } /** @@ -46,5 +58,9 @@ class RemoveExtensionHandler ]); $this->composer->run($input, $output); + + $this->events->dispatch( + new Removed($extension) + ); } } diff --git a/extensions/package-manager/src/Command/RequireExtensionHandler.php b/extensions/package-manager/src/Command/RequireExtensionHandler.php index 5d429f907..7bd403827 100755 --- a/extensions/package-manager/src/Command/RequireExtensionHandler.php +++ b/extensions/package-manager/src/Command/RequireExtensionHandler.php @@ -1,10 +1,16 @@ composer = $composer; $this->extensions = $extensions; $this->validator = $validator; + $this->events = $events; } /** @@ -63,6 +75,10 @@ class RequireExtensionHandler throw new ComposerRequireFailedException($command->package, $output->fetch()); } + $this->events->dispatch( + new Installed($extensionId) + ); + return ['id' => $extensionId]; } } diff --git a/extensions/package-manager/src/Command/UpdateExtensionHandler.php b/extensions/package-manager/src/Command/UpdateExtensionHandler.php index a07413514..a464d882a 100755 --- a/extensions/package-manager/src/Command/UpdateExtensionHandler.php +++ b/extensions/package-manager/src/Command/UpdateExtensionHandler.php @@ -9,7 +9,9 @@ namespace SychO\PackageManager\Command; use Composer\Console\Application; use Flarum\Extension\ExtensionManager; use Flarum\Settings\SettingsRepositoryInterface; +use Illuminate\Contracts\Events\Dispatcher; use SychO\PackageManager\Exception\ComposerUpdateFailedException; +use SychO\PackageManager\Extension\Event\Updated; use SychO\PackageManager\UpdateExtensionValidator; use SychO\PackageManager\LastUpdateCheck; use Symfony\Component\Console\Input\ArrayInput; @@ -37,12 +39,18 @@ class UpdateExtensionHandler */ protected $lastUpdateCheck; - public function __construct(Application $composer, ExtensionManager $extensions, UpdateExtensionValidator $validator, LastUpdateCheck $lastUpdateCheck) + /** + * @var Dispatcher + */ + protected $events; + + public function __construct(Application $composer, ExtensionManager $extensions, UpdateExtensionValidator $validator, LastUpdateCheck $lastUpdateCheck, Dispatcher $events) { $this->composer = $composer; $this->extensions = $extensions; $this->validator = $validator; $this->lastUpdateCheck = $lastUpdateCheck; + $this->events = $events; } /** @@ -75,6 +83,10 @@ class UpdateExtensionHandler $this->lastUpdateCheck->forget($extension->name); + $this->events->dispatch( + new Updated($extension) + ); + return true; } } diff --git a/extensions/package-manager/src/Event/FlarumUpdated.php b/extensions/package-manager/src/Event/FlarumUpdated.php new file mode 100644 index 000000000..428f59c58 --- /dev/null +++ b/extensions/package-manager/src/Event/FlarumUpdated.php @@ -0,0 +1,8 @@ +extension = $extension; + $this->extensionId = $extensionId; } } diff --git a/extensions/package-manager/src/Extension/Event/Removed.php b/extensions/package-manager/src/Extension/Event/Removed.php index 758e0a3be..f04a54756 100755 --- a/extensions/package-manager/src/Extension/Event/Removed.php +++ b/extensions/package-manager/src/Extension/Event/Removed.php @@ -1,5 +1,9 @@ clearCache = $clearCache; + $this->publishAssets = $publishAssets; + $this->migrate = $migrate; + } + + /** + * @throws \Exception + */ + public function handle($event) + { + $this->clearCache->run(new ArrayInput([]), new NullOutput()); + $this->migrate->run(new ArrayInput([]), new NullOutput()); + $this->publishAssets->run(new ArrayInput([]), new NullOutput()); + } +} diff --git a/extensions/package-manager/src/PackageManagerServiceProvider.php b/extensions/package-manager/src/PackageManagerServiceProvider.php index 12eb77b5b..4d6ab640b 100755 --- a/extensions/package-manager/src/PackageManagerServiceProvider.php +++ b/extensions/package-manager/src/PackageManagerServiceProvider.php @@ -1,12 +1,25 @@ container->alias(Application::class, 'flarum.composer'); } + + public function boot(Container $container) + { + /** @var Dispatcher $events */ + $events = $container->make('events'); + + $events->listen( + [Updated::class], + function (Updated $event) use ($container) { + $recompile = new RecompileFrontendAssets( + $container->make('flarum.assets.forum'), + $container->make(LocaleManager::class) + ); + $recompile->flush(); + + $container->make(ExtensionManager::class)->migrate($event->extension); + $event->extension->copyAssetsTo($container->make('filesystem')->disk('flarum-assets')); + } + ); + + $events->listen(FlarumUpdated::class, PostUpdateListener::class); + } }