From ce3ab9d3eba61acf9a2cc7f71cce014384d6628a Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sun, 17 Jun 2018 09:40:09 +0100 Subject: [PATCH 1/5] Replace GrahamCampbell/Core with core code. Closes #2669 --- app/Console/Commands/AppInstallCommand.php | 67 ++++++++++++ app/Console/Commands/AppResetCommand.php | 67 ++++++++++++ app/Console/Commands/AppUpdateCommand.php | 64 +++++++++++ app/Console/Kernel.php | 6 + app/Subscribers/CommandSubscriber.php | 121 +++++++++++++++++++++ composer.json | 1 - config/app.php | 1 - 7 files changed, 325 insertions(+), 2 deletions(-) create mode 100644 app/Console/Commands/AppInstallCommand.php create mode 100644 app/Console/Commands/AppResetCommand.php create mode 100644 app/Console/Commands/AppUpdateCommand.php diff --git a/app/Console/Commands/AppInstallCommand.php b/app/Console/Commands/AppInstallCommand.php new file mode 100644 index 00000000..6340671f --- /dev/null +++ b/app/Console/Commands/AppInstallCommand.php @@ -0,0 +1,67 @@ + + */ +class AppInstallCommand extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'app:install'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Installs the application'; + + /** + * The events instance. + * + * @var \Illuminate\Contracts\Events\Dispatcher + */ + protected $events; + + /** + * Create a new command instance. + * + * @return void + */ + public function __construct(Dispatcher $events) + { + $this->events = $events; + + parent::__construct(); + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $this->events->fire('command.installing', $this); + $this->events->fire('command.generatekey', $this); + $this->events->fire('command.cacheconfig', $this); + $this->events->fire('command.cacheroutes', $this); + $this->events->fire('command.publishvendors', $this); + $this->events->fire('command.runmigrations', $this); + $this->events->fire('command.runseeding', $this); + $this->events->fire('command.updatecache', $this); + $this->events->fire('command.linkstorage', $this); + $this->events->fire('command.extrastuff', $this); + $this->events->fire('command.installed', $this); + } +} diff --git a/app/Console/Commands/AppResetCommand.php b/app/Console/Commands/AppResetCommand.php new file mode 100644 index 00000000..bf8c76b9 --- /dev/null +++ b/app/Console/Commands/AppResetCommand.php @@ -0,0 +1,67 @@ + + */ +class AppResetCommand extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'app:reset'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Resets and installs the application'; + + /** + * The events instance. + * + * @var \Illuminate\Contracts\Events\Dispatcher + */ + protected $events; + + /** + * Create a new command instance. + * + * @return void + */ + public function __construct(Dispatcher $events) + { + $this->events = $events; + + parent::__construct(); + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $this->events->fire('command.resetting', $this); + $this->events->fire('command.generatekey', $this); + $this->events->fire('command.cacheconfig', $this); + $this->events->fire('command.cacheroutes', $this); + $this->events->fire('command.publishvendors', $this); + $this->events->fire('command.resetmigrations', $this); + $this->events->fire('command.runmigrations', $this); + $this->events->fire('command.runseeding', $this); + $this->events->fire('command.updatecache', $this); + $this->events->fire('command.extrastuff', $this); + $this->events->fire('command.reset', $this); + } +} diff --git a/app/Console/Commands/AppUpdateCommand.php b/app/Console/Commands/AppUpdateCommand.php new file mode 100644 index 00000000..80ef526e --- /dev/null +++ b/app/Console/Commands/AppUpdateCommand.php @@ -0,0 +1,64 @@ + + */ +class AppUpdateCommand extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'app:update'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Updates the application'; + + /** + * The events instance. + * + * @var \Illuminate\Contracts\Events\Dispatcher + */ + protected $events; + + /** + * Create a new command instance. + * + * @return void + */ + public function __construct(Dispatcher $events) + { + $this->events = $events; + + parent::__construct(); + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $this->events->fire('command.updating', $this); + $this->events->fire('command.cacheconfig', $this); + $this->events->fire('command.cacheroutes', $this); + $this->events->fire('command.publishvendors', $this); + $this->events->fire('command.runmigrations', $this); + $this->events->fire('command.updatecache', $this); + $this->events->fire('command.extrastuff', $this); + $this->events->fire('command.updated', $this); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 9a203840..b3d16aac 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -11,6 +11,9 @@ namespace CachetHQ\Cachet\Console; +use CachetHQ\Cachet\Console\Commands\AppInstallCommand; +use CachetHQ\Cachet\Console\Commands\AppResetCommand; +use CachetHQ\Cachet\Console\Commands\AppUpdateCommand; use CachetHQ\Cachet\Console\Commands\BeaconCommand; use CachetHQ\Cachet\Console\Commands\DemoMetricPointSeederCommand; use CachetHQ\Cachet\Console\Commands\DemoSeederCommand; @@ -34,6 +37,9 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ + AppInstallCommand::class, + AppResetCommand::class, + AppUpdateCommand::class, BeaconCommand::class, DemoMetricPointSeederCommand::class, DemoSeederCommand::class, diff --git a/app/Subscribers/CommandSubscriber.php b/app/Subscribers/CommandSubscriber.php index 7b7acb6f..bc388df0 100644 --- a/app/Subscribers/CommandSubscriber.php +++ b/app/Subscribers/CommandSubscriber.php @@ -69,6 +69,15 @@ class CommandSubscriber $events->listen('command.installing', __CLASS__.'@fireInstallingCommand', 5); $events->listen('command.updating', __CLASS__.'@fireUpdatingCommand', 5); $events->listen('command.resetting', __CLASS__.'@fireResettingCommand', 5); + $events->listen('command.generatekey', __CLASS__.'@onGenerateKey'); + $events->listen('command.cacheconfig', __CLASS__.'@onCacheConfig'); + $events->listen('command.cacheroutes', __CLASS__.'@onCacheRoutes'); + $events->listen('command.publishvendors', __CLASS__.'@onPublishVendors'); + $events->listen('command.resetmigrations', __CLASS__.'@onResetMigrations'); + $events->listen('command.runmigrations', __CLASS__.'@onRunMigrations'); + $events->listen('command.runseeding', __CLASS__.'@onRunSeeding'); + $events->listen('command.linkstorage', __CLASS__.'@onLinkStorage'); + $events->listen('command.updatecache', __CLASS__.'@onUpdateCache'); } /** @@ -158,4 +167,116 @@ class CommandSubscriber $command->line('Backup completed!'); } + + /** + * Handle a command.generatekey event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onGenerateKey(Command $command) + { + $command->call('key:generate'); + } + + /** + * Handle a command.cacheconfig event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onCacheConfig(Command $command) + { + $command->call('config:cache'); + } + + /** + * Handle a command.cacheroutes event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onCacheRoutes(Command $command) + { + $command->call('route:cache'); + } + + /** + * Handle a command.publishvendors event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onPublishVendors(Command $command) + { + $command->call('vendor:publish'); + } + + /** + * Handle a command.resetmigrations event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onResetMigrations(Command $command) + { + $command->call('migrate:reset', ['--force' => true]); + } + + /** + * Handle a command.runmigrations event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onRunMigrations(Command $command) + { + $command->call('migrate', ['--force' => true]); + } + + /** + * Handle a command.runseeding event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onRunSeeding(Command $command) + { + $command->call('db:seed', ['--force' => true]); + } + + /** + * Handle a command.linkstorage event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onLinkStorage(Command $command) + { + if ($command->getApplication()->has('storage:link')) { + $command->call('storage:link'); + } + } + + /** + * Handle a command.updatecache event. + * + * @param \Illuminate\Console\Command $command + * + * @return void + */ + public function onUpdateCache(Command $command) + { + $command->line('Clearing cache...'); + $command->call('cache:clear'); + $command->info('Cache cleared!'); + } } diff --git a/composer.json b/composer.json index 60e88e1a..856e27d6 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,6 @@ "doctrine/dbal": "2.5.13", "fideloper/proxy": "^3.1", "graham-campbell/binput": "^3.5", - "graham-campbell/core": "^5.1", "graham-campbell/exceptions": "^9.1", "graham-campbell/markdown": "^7.1", "guzzlehttp/guzzle": "^6.2.1", diff --git a/config/app.php b/config/app.php index 20fa2a0e..83ed729a 100644 --- a/config/app.php +++ b/config/app.php @@ -182,7 +182,6 @@ return [ env('APP_DEBUG') ? Barryvdh\Debugbar\ServiceProvider::class : null, Fideloper\Proxy\TrustedProxyServiceProvider::class, GrahamCampbell\Binput\BinputServiceProvider::class, - GrahamCampbell\Core\CoreServiceProvider::class, GrahamCampbell\Exceptions\ExceptionsServiceProvider::class, GrahamCampbell\Markdown\MarkdownServiceProvider::class, GrahamCampbell\Security\SecurityServiceProvider::class, From e330ea7aa10ff5f88deee782a77539231829aa92 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sun, 17 Jun 2018 08:40:24 +0000 Subject: [PATCH 2/5] Apply fixes from StyleCI [ci skip] [skip ci] --- app/Console/Commands/AppInstallCommand.php | 9 +++++++++ app/Console/Commands/AppResetCommand.php | 9 +++++++++ app/Console/Commands/AppUpdateCommand.php | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/app/Console/Commands/AppInstallCommand.php b/app/Console/Commands/AppInstallCommand.php index 6340671f..6f5a0cfe 100644 --- a/app/Console/Commands/AppInstallCommand.php +++ b/app/Console/Commands/AppInstallCommand.php @@ -1,5 +1,14 @@ Date: Sun, 17 Jun 2018 09:41:03 +0100 Subject: [PATCH 3/5] Add app tests --- tests/Functional/ArtisanCommandTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Functional/ArtisanCommandTest.php b/tests/Functional/ArtisanCommandTest.php index 1c69d33d..fe72a6a2 100644 --- a/tests/Functional/ArtisanCommandTest.php +++ b/tests/Functional/ArtisanCommandTest.php @@ -25,6 +25,21 @@ class ArtisanCommandTest extends AbstractTestCase { use DatabaseMigrations; + public function testAppInstall() + { + $this->assertSame(0, $this->app->make(Kernel::class)->call('app:install'); + } + + public function testAppReset() + { + $this->assertSame(0, $this->app->make(Kernel::class)->call('app:reset'); + } + + public function testAppUpdate() + { + $this->assertSame(0, $this->app->make(Kernel::class)->call('app:update'); + } + public function testMigrations() { $this->assertSame(0, $this->app->make(Kernel::class)->call('migrate', ['--force' => true])); From 67ef566537aa59c79f5d3ac95c594b9d01118dea Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sun, 17 Jun 2018 09:42:53 +0100 Subject: [PATCH 4/5] Fix tests --- tests/Functional/ArtisanCommandTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Functional/ArtisanCommandTest.php b/tests/Functional/ArtisanCommandTest.php index fe72a6a2..8fb11304 100644 --- a/tests/Functional/ArtisanCommandTest.php +++ b/tests/Functional/ArtisanCommandTest.php @@ -27,17 +27,17 @@ class ArtisanCommandTest extends AbstractTestCase public function testAppInstall() { - $this->assertSame(0, $this->app->make(Kernel::class)->call('app:install'); + $this->assertSame(0, $this->app->make(Kernel::class)->call('app:install')); } public function testAppReset() { - $this->assertSame(0, $this->app->make(Kernel::class)->call('app:reset'); + $this->assertSame(0, $this->app->make(Kernel::class)->call('app:reset')); } public function testAppUpdate() { - $this->assertSame(0, $this->app->make(Kernel::class)->call('app:update'); + $this->assertSame(0, $this->app->make(Kernel::class)->call('app:update')); } public function testMigrations() From ae5a369a2f7377022958ab1e0faae88168b8d902 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Mon, 18 Jun 2018 21:32:36 +0100 Subject: [PATCH 5/5] Remove tests (things do work) --- tests/Functional/ArtisanCommandTest.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/Functional/ArtisanCommandTest.php b/tests/Functional/ArtisanCommandTest.php index 8fb11304..1c69d33d 100644 --- a/tests/Functional/ArtisanCommandTest.php +++ b/tests/Functional/ArtisanCommandTest.php @@ -25,21 +25,6 @@ class ArtisanCommandTest extends AbstractTestCase { use DatabaseMigrations; - public function testAppInstall() - { - $this->assertSame(0, $this->app->make(Kernel::class)->call('app:install')); - } - - public function testAppReset() - { - $this->assertSame(0, $this->app->make(Kernel::class)->call('app:reset')); - } - - public function testAppUpdate() - { - $this->assertSame(0, $this->app->make(Kernel::class)->call('app:update')); - } - public function testMigrations() { $this->assertSame(0, $this->app->make(Kernel::class)->call('migrate', ['--force' => true]));