From e6227301fd1984dfc847a85c2d381d6baa46a7df Mon Sep 17 00:00:00 2001 From: James Brooks Date: Wed, 3 Aug 2016 12:34:43 +0100 Subject: [PATCH] Update command subscriber to fire system events --- app/Bus/Events/System/SystemWasResetEvent.php | 22 +++++++ .../Providers/EventServiceProvider.php | 3 + app/Subscribers/CommandSubscriber.php | 61 +++++++++++++++++-- 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 app/Bus/Events/System/SystemWasResetEvent.php diff --git a/app/Bus/Events/System/SystemWasResetEvent.php b/app/Bus/Events/System/SystemWasResetEvent.php new file mode 100644 index 00000000..a2146c88 --- /dev/null +++ b/app/Bus/Events/System/SystemWasResetEvent.php @@ -0,0 +1,22 @@ + + */ +final class SystemWasResetEvent implements SystemEventInterface +{ + // +} diff --git a/app/Foundation/Providers/EventServiceProvider.php b/app/Foundation/Providers/EventServiceProvider.php index c06a1a4a..9b15570f 100644 --- a/app/Foundation/Providers/EventServiceProvider.php +++ b/app/Foundation/Providers/EventServiceProvider.php @@ -93,6 +93,9 @@ class EventServiceProvider extends ServiceProvider 'CachetHQ\Cachet\Bus\Events\System\SystemWasInstalledEvent' => [ // ], + 'CachetHQ\Cachet\Bus\Events\System\SystemWasResetEvent' => [ + // + ], 'CachetHQ\Cachet\Bus\Events\System\SystemWasUpdatedEvent' => [ // ], diff --git a/app/Subscribers/CommandSubscriber.php b/app/Subscribers/CommandSubscriber.php index accddefe..2aaa320d 100644 --- a/app/Subscribers/CommandSubscriber.php +++ b/app/Subscribers/CommandSubscriber.php @@ -11,6 +11,9 @@ namespace CachetHQ\Cachet\Subscribers; +use CachetHQ\Cachet\Bus\Events\System\SystemWasInstalledEvent; +use CachetHQ\Cachet\Bus\Events\System\SystemWasResetEvent; +use CachetHQ\Cachet\Bus\Events\System\SystemWasUpdatedEvent; use CachetHQ\Cachet\Settings\Cache; use Carbon\Carbon; use Exception; @@ -63,19 +66,67 @@ class CommandSubscriber */ public function subscribe(Dispatcher $events) { - $events->listen('command.installing', __CLASS__.'@fire', 5); - $events->listen('command.updating', __CLASS__.'@fire', 5); - $events->listen('command.resetting', __CLASS__.'@fire', 5); + $events->listen('command.installing', __CLASS__.'@fireInstallingCommand', 5); + $events->listen('command.updating', __CLASS__.'@fireUpdatingCommand', 5); + $events->listen('command.resetting', __CLASS__.'@fireResettingCommand', 5); } /** - * Clear the settings cache, and backup the databases. + * Fire the installing command. * * @param \Illuminate\Console\Command $command * * @return void */ - public function fire(Command $command) + public function fireInstallingCommand(Command $command) + { + $this->handleMainCommand($command); + + event(new SystemWasInstalledEvent()); + + $command->success('System was installed!'); + } + + /** + * Fire the updating command. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function fireUpdatingCommand(Command $command) + { + $this->handleMainCommand($command); + + event(new SystemWasUpdatedEvent()); + + $command->success('System was updated!'); + } + + /** + * Fire the resetting command. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function fireResettingCommand(Command $command) + { + $this->handleMainCommand($command); + + event(new SystemWasResetEvent()); + + $command->success('System was reset!'); + } + + /** + * Handle the main bulk of the command, clear the settings and backup the database. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + protected function handleMainCommand(Command $command) { $command->line('Clearing settings cache...');