Skip to content

Commit 7e2bddc

Browse files
author
Mateus Junges
authored
Merge branch 'master' into issue-78
2 parents 0b47453 + 167721f commit 7e2bddc

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
All notable changes to `mateusjunges/laravel-acl` will be documented in this file.
44

5+
56
## [UNRELEASED]
67
- Check wildcard permissions
78
- Tests for new middleware
89

10+
## 1.7.5
11+
- Fix [#93](https://github.com/mateusjunges/laravel-acl/issues/93)
12+
- Add database connection check before register gates
13+
914
## 1.7.4
1015
- Add package tests
1116
- Continuous integration with TravisCI

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<p align="center">
22
<a href="https://packagist.org/packages/mateusjunges/laravel-acl" target="_blank"><img src="https://poser.pugx.org/mateusjunges/laravel-acl/d/total.svg" alt="Total Downloads"></a>
33
<a href="https://packagist.org/packages/mateusjunges/laravel-acl" target="_blank"><img src="https://poser.pugx.org/mateusjunges/laravel-acl/v/stable.svg" alt="Latest Stable Version"></a>
4+
<a href="https://codeclimate.com/github/mateusjunges/laravel-acl"><img src="https://codeclimate.com/github/mateusjunges/laravel-acl.svg"></a>
45
<a href="https://packagist.org/packages/mateusjunges/laravel-acl" target="_blank"><img src="https://poser.pugx.org/mateusjunges/laravel-acl/license.svg" alt="License"></a>
56
<a href="https://github.styleci.io/repos/175907190" target="_blank"><img src="https://github.styleci.io/repos/175907190/shield?style=flat"></a>
67
<a href="https://travis-ci.org/mateusjunges/laravel-acl"><img src="https://img.shields.io/travis/mateusjunges/laravel-acl/master.svg?style=flat" alt="Build Status"></a>

src/ACLAuthServiceProvider.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Junges\ACL;
44

5+
use DB;
56
use Illuminate\Support\Facades\Gate;
67
use Illuminate\Support\Facades\Blade;
78
use Illuminate\Support\Facades\Schema;
@@ -25,13 +26,15 @@ public function boot()
2526
? $permissionModel = app(config('acl.models.permission'))
2627
: $permissionModel = app(\Junges\ACL\Http\Models\Permission::class);
2728

28-
if (config('acl.tables.permissions') !== null) {
29-
if (Schema::hasTable(config('acl.tables.permissions'))) {
30-
$permissionModel->all()->map(function ($permission) {
31-
Gate::define($permission->slug, function ($user) use ($permission) {
32-
return $user->hasPermission($permission) || $user->isAdmin();
29+
if ($this->checkConnectionStatus()) {
30+
if (config('acl.tables.permissions') !== null) {
31+
if (Schema::hasTable(config('acl.tables.permissions'))) {
32+
$permissionModel->all()->map(function ($permission) {
33+
Gate::define($permission->slug, function ($user) use ($permission) {
34+
return $user->hasPermission($permission) || $user->isAdmin();
35+
});
3336
});
34-
});
37+
}
3538
}
3639
}
3740

@@ -137,4 +140,19 @@ private function registerBladeDirectives()
137140
return '<?php } ?>';
138141
});
139142
}
143+
144+
/**
145+
* Check for database connection.
146+
* @return bool
147+
*/
148+
private function checkConnectionStatus()
149+
{
150+
try {
151+
DB::connection()->getPdo();
152+
153+
return true;
154+
} catch (\Exception $exception) {
155+
return false;
156+
}
157+
}
140158
}

src/ACLServiceProvider.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Contracts\Config\Repository;
88
use Illuminate\Contracts\Events\Dispatcher;
99
use Junges\ACL\Console\Commands\CreateGroup;
10-
use Junges\ACL\Http\Observers\GroupObserver;
1110
use Junges\ACL\Console\Commands\ShowPermissions;
1211
use Junges\ACL\Console\Commands\UserPermissions;
1312
use Junges\ACL\Console\Commands\CreatePermission;
@@ -40,9 +39,6 @@ public function boot(Dispatcher $events, Repository $config, Factory $view)
4039

4140
//Load translations
4241
$this->loadTranslations();
43-
44-
//Load observers
45-
$this->loadObservers();
4642
}
4743

4844
/**
@@ -66,6 +62,9 @@ public function publishConfig()
6662
], 'config');
6763
}
6864

65+
/**
66+
* Load package commands.
67+
*/
6968
public function loadCommands()
7069
{
7170
if ($this->app->runningInConsole()) {
@@ -78,6 +77,9 @@ public function loadCommands()
7877
}
7978
}
8079

80+
/**
81+
* Load package migrations.
82+
*/
8183
public function loadMigrations()
8284
{
8385
$customMigrations = config('acl.custom_migrations');
@@ -91,6 +93,9 @@ public function loadMigrations()
9193
], 'migrations');
9294
}
9395

96+
/**
97+
* Load package translations.
98+
*/
9499
public function loadTranslations()
95100
{
96101
$translationsPath = __DIR__.'/resources/lang';
@@ -100,12 +105,6 @@ public function loadTranslations()
100105
], 'translations');
101106
}
102107

103-
public function loadObservers()
104-
{
105-
// $groupModel = app(config('acl.models.group'));
106-
// $groupModel->observe(GroupObserver::class);
107-
}
108-
109108
/**
110109
* Register any application services.
111110
*

0 commit comments

Comments
 (0)