Explorar o código

fix(extension):修复禁用不存在扩展时的缓存清理问题

- 在禁用扩展前检查扩展是否存在
- 若扩展不存在则删除对应的缓存信息
- 抛出更明确的异常提示信息
- 避免因扩展不存在导致的状态不一致问题
runphp hai 5 meses
pai
achega
7e79ce6747
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  1. 6 1
      src/ExtensionManager.php

+ 6 - 1
src/ExtensionManager.php

@@ -15,6 +15,7 @@ use SixShop\System\Model\ExtensionConfigModel;
 use SixShop\System\Model\ExtensionModel;
 use think\db\Query;
 use think\exception\ValidateException;
+use think\facade\Cache;
 use think\facade\Db;
 use think\facade\Event;
 use think\facade\Log;
@@ -180,7 +181,11 @@ class ExtensionManager extends Service
      */
     public function disable(string $extensionID): void
     {
-        $extensionModel = ExtensionModel::where(['id' => $extensionID])->findOrFail();
+        $extensionModel = ExtensionModel::where(['id' => $extensionID])->findOrEmpty();
+        if ($extensionModel->isEmpty()) {
+            Cache::delete(sprintf(ExtensionModel::EXTENSION_INFO_CACHE_KEY, $extensionID));
+            throw new RuntimeException("{$extensionID}扩展不存在");
+        }
         if ($extensionModel->status != ExtensionStatusEnum::ENABLED) {
             throw new RuntimeException("{$extensionID}扩展未启用");
         }