Skip to content

Commit b2d803a

Browse files
committed
Gracefully handle registering or booting plugins when migrations haven't been run yet.
Related: 8c0d2f4, octobercms/october#3208, #1317, #1273.
1 parent 8a2c607 commit b2d803a

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

modules/system/classes/PluginManager.php

+36-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
<?php namespace System\Classes;
2-
3-
use Db;
4-
use App;
5-
use Str;
6-
use Log;
7-
use File;
8-
use Lang;
9-
use View;
10-
use Cache;
11-
use Config;
12-
use Schema;
13-
use SystemException;
1+
<?php
2+
3+
namespace System\Classes;
4+
5+
use Backend\Classes\NavigationManager;
146
use FilesystemIterator;
15-
use RecursiveIteratorIterator;
7+
use Illuminate\Database\QueryException;
8+
use Illuminate\Support\Facades\App;
9+
use Illuminate\Support\Facades\Cache;
10+
use Illuminate\Support\Facades\DB;
11+
use Illuminate\Support\Facades\Lang;
12+
use Illuminate\Support\Facades\Log;
13+
use Illuminate\Support\Facades\View;
1614
use RecursiveDirectoryIterator;
15+
use RecursiveIteratorIterator;
1716
use System\Models\PluginVersion;
17+
use SystemException;
1818
use Winter\Storm\Foundation\Application;
1919
use Winter\Storm\Support\ClassLoader;
20-
use Backend\Classes\NavigationManager;
20+
use Winter\Storm\Support\Facades\Config;
21+
use Winter\Storm\Support\Facades\File;
22+
use Winter\Storm\Support\Str;
2123

2224
/**
2325
* Plugin manager
@@ -256,8 +258,15 @@ public function registerAll(bool $force = false): void
256258
return;
257259
}
258260

259-
foreach ($this->plugins as $pluginId => $plugin) {
260-
$this->registerPlugin($plugin, $pluginId);
261+
try {
262+
foreach ($this->plugins as $pluginId => $plugin) {
263+
$this->registerPlugin($plugin, $pluginId);
264+
}
265+
} catch (QueryException $ex) {
266+
// SQLSTATE[42S02]: Base table or view not found - migrations haven't run yet
267+
if ($ex->getCode() === '42S02') {
268+
Log::error("$pluginId cannot be registered, missing database content. Try running migrations. Error: " . $ex->getMessage());
269+
}
261270
}
262271

263272
// Ensure that route attributes are properly loaded
@@ -372,8 +381,15 @@ public function bootAll(bool $force = false): void
372381
return;
373382
}
374383

375-
foreach ($this->plugins as $plugin) {
376-
$this->bootPlugin($plugin);
384+
try {
385+
foreach ($this->plugins as $pluginId => $plugin) {
386+
$this->bootPlugin($plugin);
387+
}
388+
} catch (QueryException $ex) {
389+
// SQLSTATE[42S02]: Base table or view not found - migrations haven't run yet
390+
if ($ex->getCode() === '42S02') {
391+
Log::error("$pluginId cannot be booted, missing database content. Try running migrations. Error: " . $ex->getMessage());
392+
}
377393
}
378394

379395
$this->booted = true;
@@ -664,7 +680,7 @@ protected function loadDisabled(): void
664680
if (
665681
$this->app->hasDatabaseTable('system_plugin_versions')
666682
) {
667-
$userDisabled = Db::table('system_plugin_versions')->where('is_disabled', 1)->lists('code') ?? [];
683+
$userDisabled = DB::table('system_plugin_versions')->where('is_disabled', 1)->lists('code') ?? [];
668684
foreach ($userDisabled as $code) {
669685
$this->flagPlugin($code, static::DISABLED_BY_USER);
670686
}

0 commit comments

Comments
 (0)