diff --git a/app/Subscribers/CommandSubscriber.php b/app/Subscribers/CommandSubscriber.php index 6e46c0325..fdd38ea1e 100644 --- a/app/Subscribers/CommandSubscriber.php +++ b/app/Subscribers/CommandSubscriber.php @@ -12,6 +12,7 @@ namespace CachetHQ\Cachet\Subscribers; use Carbon\Carbon; +use Exception; use Illuminate\Console\Command; use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Events\Dispatcher; @@ -20,6 +21,7 @@ use Illuminate\Contracts\Events\Dispatcher; * This is the command subscriber class. * * @author James Brooks + * @author Graham Campbell */ class CommandSubscriber { @@ -51,45 +53,9 @@ class CommandSubscriber */ public function subscribe(Dispatcher $events) { - $events->listen('command.installing', __CLASS__.'@onInstalling', 5); - $events->listen('command.updating', __CLASS__.'@onUpdating', 5); - $events->listen('command.resetting', __CLASS__.'@onResetting', 5); - } - - /** - * Handle a command.installing event. - * - * @param \Illuminate\Console\Command $command - * - * @return void - */ - public function onInstalling(Command $command) - { - $this->backupDatabases($command); - } - - /** - * Handle a command.updating event. - * - * @param \Illuminate\Console\Command $command - * - * @return void - */ - public function onUpdating(Command $command) - { - $this->backupDatabases($command); - } - - /** - * Handle a command.resetting event. - * - * @param \Illuminate\Console\Command $command - * - * @return void - */ - public function onResetting(Command $command) - { - $this->backupDatabases($command); + $events->listen('command.installing', __CLASS__.'@fire', 5); + $events->listen('command.updating', __CLASS__.'@fire', 5); + $events->listen('command.resetting', __CLASS__.'@fire', 5); } /** @@ -99,19 +65,23 @@ class CommandSubscriber * * @return void */ - protected function backupDatabases(Command $command) + public function fire(Command $command) { $command->line('Backing up database...'); - $date = Carbon::now()->format('Y-m-d H.i.s'); + try { + $command->call('db:backup', [ + '--compression' => 'gzip', + '--database' => $this->config->get('database.default'), + '--destination' => 'local', + '--destinationPath' => Carbon::now()->format('Y-m-d H.i.s'), + '--no-interaction' => true, + ]); + } catch (Exception $e) { + $command->error($e->getMessage()); + $command->line('Backup skipped!'); + } - $command->call('db:backup', [ - '--database' => $this->config->get('database.default'), - '--destination' => 'local', - '--destinationPath' => $date, - '--compression' => 'gzip', - ]); - - $command->line('Backup completed...'); + $command->line('Backup completed!'); } }