|
|
@@ -35,16 +35,16 @@ class ExtensionManager extends Service
|
|
|
/**
|
|
|
* 安装扩展
|
|
|
*/
|
|
|
- public function install(string $moduleName): void
|
|
|
+ public function install(string $extensionID): void
|
|
|
{
|
|
|
- $extensionModel = ExtensionModel::where(['id' => $moduleName])->findOrFail();
|
|
|
+ $extensionModel = ExtensionModel::where(['id' => $extensionID])->findOrFail();
|
|
|
if ($extensionModel->status === ExtensionStatusEnum::INSTALLED) {
|
|
|
- throw new RuntimeException("{$moduleName}扩展已安装");
|
|
|
+ throw new RuntimeException("{$extensionID}扩展已安装");
|
|
|
}
|
|
|
- $this->app->make(Migrate::class, [$this->app, $moduleName])->install();
|
|
|
- $extension = $this->getExtension($moduleName);
|
|
|
+ $this->app->make(Migrate::class, [$this->app, $extensionID])->install();
|
|
|
+ $extension = $this->getExtension($extensionID);
|
|
|
$extension->install();
|
|
|
- $config = $this->getExtensionConfig($moduleName);
|
|
|
+ $config = $this->getExtensionConfig($extensionID);
|
|
|
if (empty($config)) {
|
|
|
$updateData = [];
|
|
|
$formConfig = $extension->getConfig();
|
|
|
@@ -54,21 +54,21 @@ class ExtensionManager extends Service
|
|
|
}
|
|
|
}
|
|
|
if (!empty($updateData)) {
|
|
|
- $this->saveConfig($moduleName, $updateData);
|
|
|
+ $this->saveConfig($extensionID, $updateData);
|
|
|
}
|
|
|
}
|
|
|
$extensionModel->status = ExtensionStatusEnum::INSTALLED;
|
|
|
$extensionModel->save();
|
|
|
}
|
|
|
|
|
|
- public function getExtension(string $moduleName): ExtensionInterface|PaymentExtensionInterface
|
|
|
+ public function getExtension(string $extensionID): ExtensionInterface|PaymentExtensionInterface
|
|
|
{
|
|
|
- return $this->app->get('extension.' . $moduleName);
|
|
|
+ return $this->app->get('extension.' . $extensionID);
|
|
|
}
|
|
|
|
|
|
- public function getExtensionConfig(string $moduleName, string $key = '', bool $onlyValue = true): mixed
|
|
|
+ public function getExtensionConfig(string $extensionID, string $key = '', bool $onlyValue = true): mixed
|
|
|
{
|
|
|
- $extensionConfig = ExtensionConfigModel::where('extension_id', $moduleName)->when($key, function (Query $query) use ($key) {
|
|
|
+ $extensionConfig = ExtensionConfigModel::where('extension_id', $extensionID)->when($key, function (Query $query) use ($key) {
|
|
|
$query->where('key', $key);
|
|
|
})->column(['value', 'type',], 'key', true);
|
|
|
|
|
|
@@ -82,15 +82,15 @@ class ExtensionManager extends Service
|
|
|
return $key != '' ? $extensionConfig[$key] : $extensionConfig;
|
|
|
}
|
|
|
|
|
|
- public function saveConfig(string $moduleName, array $data): bool
|
|
|
+ public function saveConfig(string $extensionID, array $data): bool
|
|
|
{
|
|
|
- $config = array_merge(ExtensionConfig::BASE, $this->getExtension($moduleName)->getConfig());
|
|
|
+ $config = array_merge(ExtensionConfig::BASE, $this->getExtension($extensionID)->getConfig());
|
|
|
$updateData = [];
|
|
|
foreach ($config as $item) {
|
|
|
if (isset($item['field'])) {
|
|
|
if (isset($data[$item['field']])) {
|
|
|
$updateData[] = [
|
|
|
- 'extension_id' => $moduleName,
|
|
|
+ 'extension_id' => $extensionID,
|
|
|
'key' => $item['field'],
|
|
|
'value' => $data[$item['field']],
|
|
|
'type' => $item['type'],
|
|
|
@@ -102,7 +102,7 @@ class ExtensionManager extends Service
|
|
|
foreach ($item['children'] as $childItem) {
|
|
|
if (isset($childItem['field'], $data[$childItem['field']])) {
|
|
|
$updateData[] = [
|
|
|
- 'extension_id' => $moduleName,
|
|
|
+ 'extension_id' => $extensionID,
|
|
|
'key' => $childItem['field'],
|
|
|
'value' => $data[$childItem['field']],
|
|
|
'type' => $childItem['type'],
|
|
|
@@ -113,7 +113,7 @@ class ExtensionManager extends Service
|
|
|
foreach ($childItem['children'] as $grandChildItem) {
|
|
|
if (isset($grandChildItem['field'], $data[$grandChildItem['field']])) {
|
|
|
$updateData[] = [
|
|
|
- 'extension_id' => $moduleName,
|
|
|
+ 'extension_id' => $extensionID,
|
|
|
'key' => $grandChildItem['field'],
|
|
|
'value' => $data[$grandChildItem['field']],
|
|
|
'type' => $grandChildItem['type'],
|
|
|
@@ -145,14 +145,14 @@ class ExtensionManager extends Service
|
|
|
/**
|
|
|
* 卸载扩展
|
|
|
*/
|
|
|
- public function uninstall(string $moduleName): void
|
|
|
+ public function uninstall(string $extensionID): void
|
|
|
{
|
|
|
- $extensionModel = ExtensionModel::where(['id' => $moduleName])->findOrFail();
|
|
|
+ $extensionModel = ExtensionModel::where(['id' => $extensionID])->findOrFail();
|
|
|
if ($extensionModel->status === ExtensionStatusEnum::UNINSTALLED) {
|
|
|
- throw new RuntimeException("{$moduleName}扩展未安装");
|
|
|
+ throw new RuntimeException("{$extensionID}扩展未安装");
|
|
|
}
|
|
|
- $this->app->make(Migrate::class, [$this->app, $moduleName])->uninstall();
|
|
|
- $this->getExtension($moduleName)->uninstall();
|
|
|
+ $this->app->make(Migrate::class, [$this->app, $extensionID])->uninstall();
|
|
|
+ $this->getExtension($extensionID)->uninstall();
|
|
|
$extensionModel->status = ExtensionStatusEnum::UNINSTALLED;
|
|
|
$extensionModel->save();
|
|
|
}
|
|
|
@@ -160,12 +160,12 @@ class ExtensionManager extends Service
|
|
|
/**
|
|
|
* 启用扩展
|
|
|
*/
|
|
|
- public function enable(string $moduleName): void
|
|
|
+ public function enable(string $extensionID): void
|
|
|
{
|
|
|
- $extensionModel = ExtensionModel::where(['id' => $moduleName])->findOrFail();
|
|
|
+ $extensionModel = ExtensionModel::where(['id' => $extensionID])->findOrFail();
|
|
|
match ($extensionModel->status) {
|
|
|
- ExtensionStatusEnum::UNINSTALLED => throw new RuntimeException("{$moduleName}扩展未安装"),
|
|
|
- ExtensionStatusEnum::ENABLED => throw new RuntimeException("{$moduleName}扩展已启用"),
|
|
|
+ ExtensionStatusEnum::UNINSTALLED => throw new RuntimeException("{$extensionID}扩展未安装"),
|
|
|
+ ExtensionStatusEnum::ENABLED => throw new RuntimeException("{$extensionID}扩展已启用"),
|
|
|
default => null,
|
|
|
};
|
|
|
$extensionModel->status = ExtensionStatusEnum::ENABLED;
|
|
|
@@ -175,11 +175,11 @@ class ExtensionManager extends Service
|
|
|
/**
|
|
|
* 禁用扩展
|
|
|
*/
|
|
|
- public function disable(string $moduleName): void
|
|
|
+ public function disable(string $extensionID): void
|
|
|
{
|
|
|
- $extensionModel = ExtensionModel::where(['id' => $moduleName])->findOrFail();
|
|
|
+ $extensionModel = ExtensionModel::where(['id' => $extensionID])->findOrFail();
|
|
|
if ($extensionModel->status != ExtensionStatusEnum::ENABLED) {
|
|
|
- throw new RuntimeException("{$moduleName}扩展未启用");
|
|
|
+ throw new RuntimeException("{$extensionID}扩展未启用");
|
|
|
}
|
|
|
$extensionModel->status = ExtensionStatusEnum::DISABLED;
|
|
|
$extensionModel->save();
|
|
|
@@ -253,10 +253,10 @@ class ExtensionManager extends Service
|
|
|
return $this->extensionList;
|
|
|
}
|
|
|
|
|
|
- public function getExtensionConfigForm(string $moduleName): array
|
|
|
+ public function getExtensionConfigForm(string $extensionID): array
|
|
|
{
|
|
|
- $config = array_merge(ExtensionConfig::BASE, array_values($this->getExtension($moduleName)->getConfig()));
|
|
|
- $extensionConfig = ExtensionConfigModel::where('extension_id', $moduleName)->column(['value', 'type',], 'key', true);
|
|
|
+ $config = array_merge(ExtensionConfig::BASE, array_values($this->getExtension($extensionID)->getConfig()));
|
|
|
+ $extensionConfig = ExtensionConfigModel::where('extension_id', $extensionID)->column(['value', 'type',], 'key', true);
|
|
|
foreach ($config as $key => &$item) {
|
|
|
if (isset($item['field'])) {
|
|
|
if (isset($extensionConfig[$item['field']])) {
|
|
|
@@ -279,7 +279,7 @@ class ExtensionManager extends Service
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Event::trigger('after_read_extension_config', [$config, $moduleName]);
|
|
|
+ Event::trigger('after_read_extension_config', [$config, $extensionID]);
|
|
|
|
|
|
return $config;
|
|
|
}
|
|
|
@@ -288,4 +288,9 @@ class ExtensionManager extends Service
|
|
|
{
|
|
|
return app(Migrate::class, [$this->app, $id])->getMigrationList();
|
|
|
}
|
|
|
+
|
|
|
+ public function refresh(string $id)
|
|
|
+ {
|
|
|
+ // 更新版本信息 todo
|
|
|
+ }
|
|
|
}
|