Update command subscriber to fire system events

This commit is contained in:
James Brooks
2016-08-03 12:34:43 +01:00
parent 6b6eeb9a3e
commit e6227301fd
3 changed files with 81 additions and 5 deletions
@@ -0,0 +1,22 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Bus\Events\System;
/**
* This is the system was reset event class.
*
* @author James Brooks <james@alt-three.com>
*/
final class SystemWasResetEvent implements SystemEventInterface
{
//
}
@@ -93,6 +93,9 @@ class EventServiceProvider extends ServiceProvider
'CachetHQ\Cachet\Bus\Events\System\SystemWasInstalledEvent' => [ 'CachetHQ\Cachet\Bus\Events\System\SystemWasInstalledEvent' => [
// //
], ],
'CachetHQ\Cachet\Bus\Events\System\SystemWasResetEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\System\SystemWasUpdatedEvent' => [ 'CachetHQ\Cachet\Bus\Events\System\SystemWasUpdatedEvent' => [
// //
], ],
+56 -5
View File
@@ -11,6 +11,9 @@
namespace CachetHQ\Cachet\Subscribers; 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 CachetHQ\Cachet\Settings\Cache;
use Carbon\Carbon; use Carbon\Carbon;
use Exception; use Exception;
@@ -63,19 +66,67 @@ class CommandSubscriber
*/ */
public function subscribe(Dispatcher $events) public function subscribe(Dispatcher $events)
{ {
$events->listen('command.installing', __CLASS__.'@fire', 5); $events->listen('command.installing', __CLASS__.'@fireInstallingCommand', 5);
$events->listen('command.updating', __CLASS__.'@fire', 5); $events->listen('command.updating', __CLASS__.'@fireUpdatingCommand', 5);
$events->listen('command.resetting', __CLASS__.'@fire', 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 * @param \Illuminate\Console\Command $command
* *
* @return void * @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...'); $command->line('Clearing settings cache...');