Skip to content

Commit

Permalink
Update command subscriber to fire system events
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Aug 4, 2016
1 parent 6b6eeb9 commit e622730
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
22 changes: 22 additions & 0 deletions app/Bus/Events/System/SystemWasResetEvent.php
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
final class SystemWasResetEvent implements SystemEventInterface
{
//
}
3 changes: 3 additions & 0 deletions app/Foundation/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
//
],
Expand Down
61 changes: 56 additions & 5 deletions app/Subscribers/CommandSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,19 +66,67 @@ public function __construct(Cache $cache, Repository $config)
*/
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...');

Expand Down

0 comments on commit e622730

Please sign in to comment.