diff --git a/.travis.yml b/.travis.yml index 76032b2..251bcf5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: -- 7.1 - 7.2 - 7.3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 48a0dc1..68c8884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](CONTRIBUTING.md). +## [v2.1.0] - 2019-06-02 +- Update composer deps +- Drop PHP 7.1 travis test +- Refactor migrations and artisan commands, and tweak service provider publishes functionality + ## [v2.0.0] - 2019-03-03 - Rename environment variable QUEUE_DRIVER to QUEUE_CONNECTION - Require PHP 7.2 & Laravel 5.8 diff --git a/README.md b/README.md index 2f3580e..f600356 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [![Packagist](https://img.shields.io/packagist/v/rinvex/laravel-attributes.svg?label=Packagist&style=flat-square)](https://packagist.org/packages/rinvex/laravel-attributes) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/rinvex/laravel-attributes.svg?label=Scrutinizer&style=flat-square)](https://scrutinizer-ci.com/g/rinvex/laravel-attributes/) -[![Code Climate](https://img.shields.io/codeclimate/github/rinvex/laravel-attributes.svg?label=CodeClimate&style=flat-square)](https://codeclimate.com/github/rinvex/laravel-attributes) [![Travis](https://img.shields.io/travis/rinvex/laravel-attributes.svg?label=TravisCI&style=flat-square)](https://travis-ci.org/rinvex/laravel-attributes) [![StyleCI](https://styleci.io/repos/87620509/shield)](https://styleci.io/repos/87620509) [![License](https://img.shields.io/packagist/l/rinvex/laravel-attributes.svg?label=License&style=flat-square)](https://github.com/rinvex/laravel-attributes/blob/develop/LICENSE) @@ -151,14 +150,14 @@ This class creates the Eloquent relations to the attribute values based on their composer require rinvex/laravel-attributes ``` -2. Execute migrations via the following command: +2. Publish resources (migrations and config files): ```shell - php artisan rinvex:migrate:attributes + php artisan rinvex:publish:attributes ``` -3. **Optional** if you want to change the configurations: +3. Execute migrations via the following command: ```shell - php artisan rinvex:publish:attributes + php artisan rinvex:migrate:attributes ``` 4. Done! diff --git a/composer.json b/composer.json index 103b109..bdda991 100644 --- a/composer.json +++ b/composer.json @@ -55,16 +55,16 @@ "jeremeamia/superclosure": "^2.4.0", "rinvex/laravel-cacheable": "^2.0.0", "rinvex/laravel-support": "^2.0.0", - "spatie/eloquent-sortable": "^3.4.0", + "spatie/eloquent-sortable": "^3.6.0", "spatie/laravel-sluggable": "^2.1.0", - "spatie/laravel-translatable": "^3.1.0", + "spatie/laravel-translatable": "^4.1.0", "watson/validating": "^3.2.0" }, "require-dev": { "codedungeon/phpunit-result-printer": "^0.26.0", "illuminate/container": "~5.8.0", "orchestra/testbench": "^3.6", - "phpunit/phpunit": "^8.0.0" + "phpunit/phpunit": "^8.1.0" }, "autoload": { "classmap": [ diff --git a/database/migrations/2017_01_19_040614_create_attributes_table.php b/database/migrations/01_create_attributes_table.php.stub similarity index 100% rename from database/migrations/2017_01_19_040614_create_attributes_table.php rename to database/migrations/01_create_attributes_table.php.stub diff --git a/database/migrations/2017_03_30_012102_create_attribute_text_values_table.php b/database/migrations/02_create_attribute_text_values_table.php.stub similarity index 100% rename from database/migrations/2017_03_30_012102_create_attribute_text_values_table.php rename to database/migrations/02_create_attribute_text_values_table.php.stub diff --git a/database/migrations/2017_01_19_040617_create_attribute_boolean_values_table.php b/database/migrations/03_create_attribute_boolean_values_table.php.stub similarity index 100% rename from database/migrations/2017_01_19_040617_create_attribute_boolean_values_table.php rename to database/migrations/03_create_attribute_boolean_values_table.php.stub diff --git a/database/migrations/2017_01_19_040620_create_attribute_datetime_values_table.php b/database/migrations/04_create_attribute_datetime_values_table.php.stub similarity index 100% rename from database/migrations/2017_01_19_040620_create_attribute_datetime_values_table.php rename to database/migrations/04_create_attribute_datetime_values_table.php.stub diff --git a/database/migrations/2017_01_19_040622_create_attribute_integer_values_table.php b/database/migrations/05_create_attribute_integer_values_table.php.stub similarity index 100% rename from database/migrations/2017_01_19_040622_create_attribute_integer_values_table.php rename to database/migrations/05_create_attribute_integer_values_table.php.stub diff --git a/database/migrations/2017_01_19_040703_create_attribute_varchar_values_table.php b/database/migrations/06_create_attribute_varchar_values_table.php.stub similarity index 100% rename from database/migrations/2017_01_19_040703_create_attribute_varchar_values_table.php rename to database/migrations/06_create_attribute_varchar_values_table.php.stub diff --git a/database/migrations/2017_01_21_075238_create_attribute_entity_table.php b/database/migrations/07_create_attribute_entity_table.php.stub similarity index 100% rename from database/migrations/2017_01_21_075238_create_attribute_entity_table.php rename to database/migrations/07_create_attribute_entity_table.php.stub diff --git a/src/Console/Commands/MigrateCommand.php b/src/Console/Commands/MigrateCommand.php index 2949738..2530fcd 100644 --- a/src/Console/Commands/MigrateCommand.php +++ b/src/Console/Commands/MigrateCommand.php @@ -29,7 +29,18 @@ class MigrateCommand extends Command */ public function handle(): void { - $this->warn($this->description); - $this->call('migrate', ['--step' => true, '--path' => 'vendor/rinvex/laravel-attributes/database/migrations', '--force' => $this->option('force')]); + $this->alert($this->description); + + if (file_exists($path = 'database/migrations/rinvex/laravel-attributes')) { + $this->call('migrate', [ + '--step' => true, + '--path' => $path, + '--force' => $this->option('force'), + ]); + } else { + $this->warn('No migrations found! Consider publish them first: php artisan rinvex:publish:attributes'); + } + + $this->line(''); } } diff --git a/src/Console/Commands/PublishCommand.php b/src/Console/Commands/PublishCommand.php index bc6b70c..c865b43 100644 --- a/src/Console/Commands/PublishCommand.php +++ b/src/Console/Commands/PublishCommand.php @@ -13,7 +13,7 @@ class PublishCommand extends Command * * @var string */ - protected $signature = 'rinvex:publish:attributes {--force : Overwrite any existing files.}'; + protected $signature = 'rinvex:publish:attributes {--force : Overwrite any existing files.} {--R|resource=all}'; /** * The console command description. @@ -29,7 +29,21 @@ class PublishCommand extends Command */ public function handle(): void { - $this->warn($this->description); - $this->call('vendor:publish', ['--tag' => 'rinvex-attributes-config', '--force' => $this->option('force')]); + $this->alert($this->description); + + switch ($this->option('resource')) { + case 'config': + $this->call('vendor:publish', ['--tag' => 'rinvex-attributes-config', '--force' => $this->option('force')]); + break; + case 'migrations': + $this->call('vendor:publish', ['--tag' => 'rinvex-attributes-migrations', '--force' => $this->option('force')]); + break; + default: + $this->call('vendor:publish', ['--tag' => 'rinvex-attributes-config', '--force' => $this->option('force')]); + $this->call('vendor:publish', ['--tag' => 'rinvex-attributes-migrations', '--force' => $this->option('force')]); + break; + } + + $this->line(''); } } diff --git a/src/Console/Commands/RollbackCommand.php b/src/Console/Commands/RollbackCommand.php index 78bdc48..74e362d 100644 --- a/src/Console/Commands/RollbackCommand.php +++ b/src/Console/Commands/RollbackCommand.php @@ -29,7 +29,18 @@ class RollbackCommand extends Command */ public function handle(): void { - $this->warn($this->description); - $this->call('migrate:reset', ['--path' => 'vendor/rinvex/laravel-attributes/database/migrations', '--force' => $this->option('force')]); + $this->alert($this->description); + + if (file_exists($path = 'database/migrations/rinvex/laravel-attributes')) { + $this->call('migrate:reset', [ + '--step' => true, + '--path' => $path, + '--force' => $this->option('force'), + ]); + } else { + $this->warn('No migrations found! Consider publish them first: php artisan rinvex:publish:attributes'); + } + + $this->line(''); } } diff --git a/src/Providers/AttributesServiceProvider.php b/src/Providers/AttributesServiceProvider.php index 4be8507..d90f4f4 100644 --- a/src/Providers/AttributesServiceProvider.php +++ b/src/Providers/AttributesServiceProvider.php @@ -6,6 +6,7 @@ use Illuminate\Support\ServiceProvider; use Rinvex\Attributes\Models\Attribute; +use Rinvex\Support\Traits\ConsoleTools; use Rinvex\Attributes\Models\AttributeEntity; use Rinvex\Attributes\Console\Commands\MigrateCommand; use Rinvex\Attributes\Console\Commands\PublishCommand; @@ -13,6 +14,8 @@ class AttributesServiceProvider extends ServiceProvider { + use ConsoleTools; + /** * The commands to be registered. * @@ -53,36 +56,8 @@ public function register() */ public function boot() { - // Load migrations - ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); - // Publish Resources - ! $this->app->runningInConsole() || $this->publishResources(); - } - - /** - * Publish resources. - * - * @return void - */ - protected function publishResources(): void - { - $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.attributes.php')], 'rinvex-attributes-config'); - $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'rinvex-attributes-migrations'); - } - - /** - * Register console commands. - * - * @return void - */ - protected function registerCommands(): void - { - // Register artisan commands - foreach ($this->commands as $key => $value) { - $this->app->singleton($value, $key); - } - - $this->commands(array_values($this->commands)); + ! $this->app->runningInConsole() || $this->publishesConfig('rinvex/laravel-attributes'); + ! $this->app->runningInConsole() || $this->publishesMigrations('rinvex/laravel-attributes'); } }