Skip to content

Commit

Permalink
Add ability to ignore default migrations (#50)
Browse files Browse the repository at this point in the history
* Add ability to ignore default migrations
  • Loading branch information
antonkomarev committed Sep 26, 2019
1 parent 13d5895 commit c41fed8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,6 +4,13 @@ All notable changes to `cybercog/laravel-ban` will be documented in this file.

## [Unreleased]

## [4.2.0] - 2019-09-26

### Added

- ([#50]) Added publishable configuration file
- ([#50]) Added ability to ignore default migrations

## [4.1.0] - 2019-09-04

### Added
Expand Down Expand Up @@ -118,7 +125,8 @@ All notable changes to `cybercog/laravel-ban` will be documented in this file.

- Initial release

[Unreleased]: https://github.com/cybercog/laravel-ban/compare/4.1.0...master
[Unreleased]: https://github.com/cybercog/laravel-ban/compare/4.2.0...master
[4.2.0]: https://github.com/cybercog/laravel-ban/compare/4.1.0...4.2.0
[4.1.0]: https://github.com/cybercog/laravel-ban/compare/4.0.0...4.1.0
[4.0.0]: https://github.com/cybercog/laravel-ban/compare/3.5.0...4.0.0
[3.5.0]: https://github.com/cybercog/laravel-ban/compare/3.4.0...3.5.0
Expand All @@ -131,6 +139,7 @@ All notable changes to `cybercog/laravel-ban` will be documented in this file.
[2.0.1]: https://github.com/cybercog/laravel-ban/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/cybercog/laravel-ban/compare/1.0.0...2.0.0

[#50]: https://github.com/cybercog/laravel-ban/pull/50
[#48]: https://github.com/cybercog/laravel-ban/pull/48
[#35]: https://github.com/cybercog/laravel-ban/pull/35
[#30]: https://github.com/cybercog/laravel-ban/pull/30
Expand Down
28 changes: 28 additions & 0 deletions config/ban.php
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of Laravel Ban.
*
* (c) Anton Komarev <anton@komarev.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

return [

/*
|--------------------------------------------------------------------------
| Ban Database Migrations
|--------------------------------------------------------------------------
|
| Determine if default package migrations should be registered.
| Set value to `false` when using customized migrations.
|
*/

'load_default_migrations' => true,

];
44 changes: 41 additions & 3 deletions src/Providers/BanServiceProvider.php
Expand Up @@ -19,6 +19,7 @@
use Cog\Laravel\Ban\Models\Ban;
use Cog\Laravel\Ban\Observers\BanObserver;
use Cog\Laravel\Ban\Services\BanService;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;

class BanServiceProvider extends ServiceProvider
Expand All @@ -43,6 +44,7 @@ public function register(): void
*/
public function boot(): void
{
$this->configure();
$this->registerPublishes();
$this->registerObservers();
}
Expand Down Expand Up @@ -94,13 +96,49 @@ protected function registerObservers(): void
protected function registerPublishes(): void
{
if ($this->app->runningInConsole()) {
$migrationsPath = __DIR__ . '/../../database/migrations';
$this->publishes([
__DIR__ . '/../../config/ban.php' => config_path('ban.php'),
], 'ban-config');

$this->publishes([
$migrationsPath => database_path('migrations'),
__DIR__ . '/../../database/migrations' => database_path('migrations'),
], 'migrations');
}

$this->registerMigrations();
}

$this->loadMigrationsFrom($migrationsPath);
/**
* Register the Ban migrations.
*
* @return void
*/
private function registerMigrations(): void
{
if ($this->app->runningInConsole() && $this->shouldLoadDefaultMigrations()) {
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
}
}

/**
* Merge Ban configuration with the application configuration.
*
* @return void
*/
private function configure(): void
{
if (!$this->app->configurationIsCached()) {
$this->mergeConfigFrom(__DIR__ . '/../../config/ban.php', 'ban');
}
}

/**
* Determine if we should register default migrations.
*
* @return bool
*/
private function shouldLoadDefaultMigrations(): bool
{
return Config::get('ban.load_default_migrations', true);
}
}

0 comments on commit c41fed8

Please sign in to comment.