Ver código fonte

feat(extension): 完成扩展的版本刷新

runphp 7 meses atrás
pai
commit
48567459bc
3 arquivos alterados com 20 adições e 5 exclusões
  1. 1 1
      composer.json
  2. 14 2
      src/ExtensionManager.php
  3. 5 2
      src/Migrate.php

+ 1 - 1
composer.json

@@ -8,7 +8,7 @@
   ],
   "require": {
     "php": ">=8.3",
-    "six-shop/core": ">=0.4 <1.0"
+    "six-shop/core": ">=0.5.9 <1.0"
   },
   "authors": [
     {

+ 14 - 2
src/ExtensionManager.php

@@ -3,9 +3,11 @@ declare(strict_types=1);
 
 namespace SixShop\System;
 
+use Composer\InstalledVersions;
 use RuntimeException;
 use SixShop\Core\Contracts\ExtensionInterface;
 use SixShop\Core\Helper;
+use SixShop\Core\Service\CoreService;
 use SixShop\Payment\Contracts\PaymentExtensionInterface;
 use SixShop\System\Config\ExtensionConfig;
 use SixShop\System\Enum\ExtensionStatusEnum;
@@ -289,8 +291,18 @@ class ExtensionManager extends Service
         return app(Migrate::class, [$this->app, $id])->getMigrationList();
     }
 
-    public function refresh(string $id)
+    public function refresh(string $id): void
     {
-        // 更新版本信息 todo
+        // 获取当前版本更新版本信息
+        $currentVersion = '0.0.0';
+        if (isset(CoreService::$extensionComposerMap[$id])) {
+            $packageName = CoreService::$extensionComposerMap[$id]['name'];
+            $currentVersion = InstalledVersions::getPrettyVersion($packageName);
+
+        }
+        ExtensionModel::where([
+            ['id', '=', $id],
+            ['version','<>', $currentVersion],
+        ])->update(['version' => $currentVersion]);
     }
 }

+ 5 - 2
src/Migrate.php

@@ -12,6 +12,7 @@ use Phinx\Util\Util;
 use SixShop\Core\Helper;
 use SixShop\System\Model\MigrationsModel;
 use think\App;
+use think\Model;
 
 class Migrate
 {
@@ -83,8 +84,10 @@ class Migrate
     public function getMigrationList(): array
     {
         $migrations = $this->getMigrations();
-        MigrationsModel::maker(function (MigrationsModel $model) {
-            $model->setOption('suffix', $this->moduleName);
+        MigrationsModel::maker(function (Model $model) {
+            if ($model instanceof MigrationsModel) {
+                $model->setOption('suffix', $this->moduleName);
+            }
         });
         $versionLog =  MigrationsModel::column('*', 'version');
         foreach ($migrations as $key => $migration) {