|
5 | 5 | use Exception; |
6 | 6 | use Illuminate\Support\Facades\Blade; |
7 | 7 | use Illuminate\Support\Facades\Config; |
8 | | -use Illuminate\Support\Facades\Schema; |
9 | 8 | use Illuminate\Support\ServiceProvider; |
10 | | -use Squareetlabs\LaravelSimplePermissions\Exceptions\AuditTableMissingException; |
11 | 9 | use Squareetlabs\LaravelSimplePermissions\Support\Services\SimplePermissionsService; |
12 | 10 | use Squareetlabs\LaravelSimplePermissions\Middleware\Ability as AbilityMiddleware; |
13 | 11 | use Squareetlabs\LaravelSimplePermissions\Middleware\Permission as PermissionMiddleware; |
@@ -61,6 +59,7 @@ protected function configurePublishing(): void |
61 | 59 | __DIR__ . '/../database/migrations/create_groups_table.php' => database_path('migrations/2019_12_14_000008_create_groups_table.php'), |
62 | 60 | __DIR__ . '/../database/migrations/create_group_user_table.php' => database_path('migrations/2019_12_14_000009_create_group_user_table.php'), |
63 | 61 | __DIR__ . '/../database/migrations/create_entity_permission_table.php' => database_path('migrations/2019_12_14_000010_create_entity_permission_table.php'), |
| 62 | + __DIR__ . '/../database/migrations/create_audit_logs_table.php' => database_path('migrations/2019_12_14_000011_create_audit_logs_table.php'), |
64 | 63 | ]; |
65 | 64 |
|
66 | 65 | $migrations[__DIR__ . '/../database/migrations/add_performance_indexes.php'] = database_path('migrations/2019_12_14_000014_add_performance_indexes.php'); |
@@ -156,38 +155,16 @@ protected function registerBladeDirectives(): void |
156 | 155 | /** |
157 | 156 | * Validate audit configuration. |
158 | 157 | * |
| 158 | + * Note: We don't validate the table existence here to avoid blocking migrations. |
| 159 | + * The AuditService will check if the table exists before attempting to log, |
| 160 | + * and will silently skip logging if the table doesn't exist (e.g., during migrations). |
| 161 | + * |
159 | 162 | * @return void |
160 | | - * @throws AuditTableMissingException |
161 | 163 | */ |
162 | 164 | protected function validateAuditConfiguration(): void |
163 | 165 | { |
164 | | - if (!Config::get('simple-permissions.audit.enabled')) { |
165 | | - return; |
166 | | - } |
167 | | - |
168 | | - // No validar durante migraciones o instalación |
169 | | - // La validación real se hace en AuditService cuando se intenta usar |
170 | | - if ($this->app->runningInConsole()) { |
171 | | - $command = $this->app->runningUnitTests() ? null : ($_SERVER['argv'][1] ?? null); |
172 | | - |
173 | | - // Saltar validación durante migraciones |
174 | | - if (in_array($command, ['migrate', 'migrate:fresh', 'migrate:refresh', 'migrate:reset', 'migrate:rollback', 'migrate:status'])) { |
175 | | - return; |
176 | | - } |
177 | | - } |
178 | | - |
179 | | - // Validar que la tabla existe si la auditoría está habilitada |
180 | | - try { |
181 | | - if (!Schema::hasTable('audit_logs')) { |
182 | | - throw new AuditTableMissingException(); |
183 | | - } |
184 | | - } catch (\Exception $e) { |
185 | | - // Si hay un error de conexión a la BD, no validar aún |
186 | | - // (puede ser que la BD aún no esté configurada) |
187 | | - if (str_contains($e->getMessage(), 'Connection') || str_contains($e->getMessage(), 'SQLSTATE')) { |
188 | | - return; |
189 | | - } |
190 | | - throw $e; |
191 | | - } |
| 166 | + // Validation is done at runtime in AuditService when attempting to log |
| 167 | + // This prevents blocking migrations or installation when audit is enabled |
| 168 | + // but the table hasn't been created yet |
192 | 169 | } |
193 | 170 | } |
0 commit comments