mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-28 06:47:24 +08:00
fix(plugin): improve plugin install and uninstall migration handling
This commit is contained in:
@@ -106,6 +106,8 @@ class PluginController extends Controller
|
|||||||
'config' => $pluginConfig,
|
'config' => $pluginConfig,
|
||||||
'readme' => $readmeContent,
|
'readme' => $readmeContent,
|
||||||
'need_upgrade' => $needUpgrade,
|
'need_upgrade' => $needUpgrade,
|
||||||
|
'admin_menus' => $config['admin_menus'] ?? null,
|
||||||
|
'admin_crud' => $config['admin_crud'] ?? null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use Illuminate\Support\Facades\DB;
|
|||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\Facades\View;
|
use Illuminate\Support\Facades\View;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
@@ -219,6 +218,20 @@ class PluginManager
|
|||||||
return $defaultValues;
|
return $defaultValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 Migrator 实例并确保迁移仓库存在
|
||||||
|
*/
|
||||||
|
protected function getMigrator(): \Illuminate\Database\Migrations\Migrator
|
||||||
|
{
|
||||||
|
$migrator = app('migrator');
|
||||||
|
|
||||||
|
if (!$migrator->repositoryExists()) {
|
||||||
|
$migrator->getRepository()->createRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $migrator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运行插件数据库迁移
|
* 运行插件数据库迁移
|
||||||
*/
|
*/
|
||||||
@@ -227,10 +240,8 @@ class PluginManager
|
|||||||
$migrationsPath = $this->getPluginPath($pluginCode) . '/database/migrations';
|
$migrationsPath = $this->getPluginPath($pluginCode) . '/database/migrations';
|
||||||
|
|
||||||
if (File::exists($migrationsPath)) {
|
if (File::exists($migrationsPath)) {
|
||||||
Artisan::call('migrate', [
|
$migrator = $this->getMigrator();
|
||||||
'--path' => "plugins/" . Str::studly($pluginCode) . "/database/migrations",
|
$migrator->run([$migrationsPath]);
|
||||||
'--force' => true
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,10 +253,8 @@ class PluginManager
|
|||||||
$migrationsPath = $this->getPluginPath($pluginCode) . '/database/migrations';
|
$migrationsPath = $this->getPluginPath($pluginCode) . '/database/migrations';
|
||||||
|
|
||||||
if (File::exists($migrationsPath)) {
|
if (File::exists($migrationsPath)) {
|
||||||
Artisan::call('migrate:rollback', [
|
$migrator = $this->getMigrator();
|
||||||
'--path' => "plugins/" . Str::studly($pluginCode) . "/database/migrations",
|
$migrator->rollback([$migrationsPath]);
|
||||||
'--force' => true
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user