From 0d2ae03e407b3adf7b5ada8d86a06d42ff6db373 Mon Sep 17 00:00:00 2001 From: jstoone Date: Tue, 15 Nov 2016 10:43:21 +0100 Subject: [PATCH 1/2] Updated package name. --- composer.json | 4 ++-- src/Collections/FutureCollection.php | 4 ++-- src/Commands/CommitToFutureCommand.php | 5 +++-- src/Contracts/ModelFuture.php | 2 +- src/FuturePlanner.php | 22 ++++++++++---------- src/Models/Future.php | 6 +++--- src/ServiceProvider.php | 4 ++-- src/Traits/HasFuture.php | 8 +++---- tests/Collections/FutureCollectionTest.php | 8 +++---- tests/Commands/CommitToFutureCommandTest.php | 8 +++---- tests/FuturePlannerTest.php | 16 +++++++------- tests/Models/FutureTest.php | 12 +++++------ tests/TestCase.php | 6 +++--- tests/Traits/HasFutureTest.php | 6 +++--- 14 files changed, 56 insertions(+), 55 deletions(-) diff --git a/composer.json b/composer.json index c8a5dfb..3f253a9 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ }, "autoload": { "psr-4": { - "Dixie\\LaravelModelFuture\\": "src/" + "Dixie\\EloquentModelFuture\\": "src/" } }, "autoload-dev": { "psr-4": { - "Dixie\\LaravelModelFuture\\Tests\\": "tests/" + "Dixie\\EloquentModelFuture\\Tests\\": "tests/" } }, "minimum-stability": "stable" diff --git a/src/Collections/FutureCollection.php b/src/Collections/FutureCollection.php index e05e718..54eb975 100644 --- a/src/Collections/FutureCollection.php +++ b/src/Collections/FutureCollection.php @@ -1,6 +1,6 @@ see($today) ->commit(); }); + } } diff --git a/src/Contracts/ModelFuture.php b/src/Contracts/ModelFuture.php index 249a1b0..37c13c4 100644 --- a/src/Contracts/ModelFuture.php +++ b/src/Contracts/ModelFuture.php @@ -1,6 +1,6 @@ Date: Tue, 15 Nov 2016 10:54:28 +0100 Subject: [PATCH 2/2] Added guards to cli output and command registration. --- src/Commands/CommitToFutureCommand.php | 28 ++++++++++++++++++++++++++ src/ServiceProvider.php | 4 +++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Commands/CommitToFutureCommand.php b/src/Commands/CommitToFutureCommand.php index cca7db5..e167aa9 100644 --- a/src/Commands/CommitToFutureCommand.php +++ b/src/Commands/CommitToFutureCommand.php @@ -46,6 +46,12 @@ public function handle() ->uncommitted() ->get(); + + if($futures->isEmpty()) { + $this->outputMessage('No future plans for today.'); + return; + } + $futures->each(function(Future $future) use ($today) { $modelWithFuture = $future->futureable; @@ -54,5 +60,27 @@ public function handle() ->commit(); }); + $this->outputMessage("{$futures->count()} futures updated."); + } + + + /** + * Write a line to the commandline + * + * @return void + */ + private function outputMessage($message) + { + $laravel = $this->laravel ?: false; + + if( ! $laravel) { + return; + } + + if( ! $laravel->runningInConsole()) { + return; + } + + $this->info($message); } } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 5f4c318..5ee4fb5 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -18,7 +18,9 @@ public function boot() { $this->loadMigrationsFrom(__DIR__.'/../migrations'); - $this->commands(CommitToFutureCommand::class); + if($this-app->runningInConsole()) { + $this->commands(CommitToFutureCommand::class); + } } /**