From 45c8b22ba7a4db35bf2e27c3e2a7324f49029391 Mon Sep 17 00:00:00 2001
From: joyqi <joyqi@users.noreply.github.com>
Date: Thu, 19 Aug 2021 16:58:12 +0800
Subject: [PATCH 1/6] Update Typecho-dev-Ci.yml

---
 .github/workflows/Typecho-dev-Ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/Typecho-dev-Ci.yml b/.github/workflows/Typecho-dev-Ci.yml
index 4291a589..072df14f 100644
--- a/.github/workflows/Typecho-dev-Ci.yml
+++ b/.github/workflows/Typecho-dev-Ci.yml
@@ -47,5 +47,5 @@ jobs:
     - name: Upload a Build Artifact
       uses: actions/upload-artifact@v2
       with:
-          name: typecho_build
+          name: typecho
           path: ./build/

From 29cf8a070db582393b636d20a6c8f721d4c9b4ef Mon Sep 17 00:00:00 2001
From: joyqi <joyqi@users.noreply.github.com>
Date: Thu, 19 Aug 2021 17:57:44 +0800
Subject: [PATCH 2/6] Update Typecho-dev-Ci.yml

---
 .github/workflows/Typecho-dev-Ci.yml | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/Typecho-dev-Ci.yml b/.github/workflows/Typecho-dev-Ci.yml
index 072df14f..f78fdac1 100644
--- a/.github/workflows/Typecho-dev-Ci.yml
+++ b/.github/workflows/Typecho-dev-Ci.yml
@@ -34,8 +34,6 @@ jobs:
     steps:
     - name: Checkout code
       uses: actions/checkout@v2
-    - name: Install tree
-      run: sudo apt-get -y install tree
     - name: Build
       run: |
         mkdir build
@@ -43,9 +41,8 @@ jobs:
         mkdir build/usr/uploads/
         chmod 777 build/usr/uploads/
         rm -rf build/admin/src
-        tree -d build
+        cd build && tar -cvvzf typecho.tar.gz * && mv typecho.tar.gz && cd ..
     - name: Upload a Build Artifact
       uses: actions/upload-artifact@v2
       with:
-          name: typecho
-          path: ./build/
+          path: typecho.tar.gz

From 78a4cc9f84429215909f7d9f935c45223c5e65f5 Mon Sep 17 00:00:00 2001
From: joyqi <joyqi@users.noreply.github.com>
Date: Thu, 19 Aug 2021 17:58:47 +0800
Subject: [PATCH 3/6] Update Typecho-dev-Ci.yml

---
 .github/workflows/Typecho-dev-Ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/Typecho-dev-Ci.yml b/.github/workflows/Typecho-dev-Ci.yml
index f78fdac1..eeb0138a 100644
--- a/.github/workflows/Typecho-dev-Ci.yml
+++ b/.github/workflows/Typecho-dev-Ci.yml
@@ -41,7 +41,7 @@ jobs:
         mkdir build/usr/uploads/
         chmod 777 build/usr/uploads/
         rm -rf build/admin/src
-        cd build && tar -cvvzf typecho.tar.gz * && mv typecho.tar.gz && cd ..
+        cd build && tar -cvvzf typecho.tar.gz * && mv typecho.tar.gz .. && cd ..
     - name: Upload a Build Artifact
       uses: actions/upload-artifact@v2
       with:

From fc0485c891849706b2b60c67e52fe5638a7e707a Mon Sep 17 00:00:00 2001
From: joyqi <joyqi@users.noreply.github.com>
Date: Thu, 19 Aug 2021 18:20:27 +0800
Subject: [PATCH 4/6] Update Typecho-dev-Ci.yml

---
 .github/workflows/Typecho-dev-Ci.yml | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/Typecho-dev-Ci.yml b/.github/workflows/Typecho-dev-Ci.yml
index eeb0138a..072df14f 100644
--- a/.github/workflows/Typecho-dev-Ci.yml
+++ b/.github/workflows/Typecho-dev-Ci.yml
@@ -34,6 +34,8 @@ jobs:
     steps:
     - name: Checkout code
       uses: actions/checkout@v2
+    - name: Install tree
+      run: sudo apt-get -y install tree
     - name: Build
       run: |
         mkdir build
@@ -41,8 +43,9 @@ jobs:
         mkdir build/usr/uploads/
         chmod 777 build/usr/uploads/
         rm -rf build/admin/src
-        cd build && tar -cvvzf typecho.tar.gz * && mv typecho.tar.gz .. && cd ..
+        tree -d build
     - name: Upload a Build Artifact
       uses: actions/upload-artifact@v2
       with:
-          path: typecho.tar.gz
+          name: typecho
+          path: ./build/

From df854a3bf0c4a826fc3d9bd05a8b70353a54281e Mon Sep 17 00:00:00 2001
From: joyqi <magike.net@gmail.com>
Date: Fri, 20 Aug 2021 00:58:22 +0800
Subject: [PATCH 5/6] Remove minor version

---
 var/Typecho/Common.php |  2 +-
 var/Typecho/Widget.php |  2 +-
 var/Upgrade.php        |  6 ++--
 var/Widget/Upgrade.php | 81 +++++++++++++++---------------------------
 4 files changed, 33 insertions(+), 58 deletions(-)

diff --git a/var/Typecho/Common.php b/var/Typecho/Common.php
index 81395b77..1e96392f 100644
--- a/var/Typecho/Common.php
+++ b/var/Typecho/Common.php
@@ -65,7 +65,7 @@ function _n(string $single, string $plural, int $number): string
 class Typecho_Common
 {
     /** 程序版本 */
-    const VERSION = '1.2/18.10.23';
+    const VERSION = '1.2.0';
 
     /**
      * 默认编码
diff --git a/var/Typecho/Widget.php b/var/Typecho/Widget.php
index e1195124..c123b076 100644
--- a/var/Typecho/Widget.php
+++ b/var/Typecho/Widget.php
@@ -210,7 +210,7 @@ abstract class Typecho_Widget
      *
      * @param boolean $condition 触发条件
      *
-     * @return mixed
+     * @return $this|Typecho_Widget_Helper_Empty
      */
     public function on(bool $condition)
     {
diff --git a/var/Upgrade.php b/var/Upgrade.php
index b29111f3..10ea993e 100644
--- a/var/Upgrade.php
+++ b/var/Upgrade.php
@@ -346,16 +346,16 @@ Typecho_Date::setTimezoneOffset($options->timezone);
     public static function v0_6r9_4_21($db, $options)
     {
         //创建上传目录
-        $uploadDir = Typecho_Common::url(Widget_Upload::UPLOAD_PATH, __TYPECHO_ROOT_DIR__);
+        $uploadDir = Typecho_Common::url(Widget_Upload::UPLOAD_DIR, __TYPECHO_ROOT_DIR__);
         if (is_dir($uploadDir)) {
             if (!is_writeable($uploadDir)) {
                 if (!@chmod($uploadDir, 0644)) {
-                    throw new Typecho_Widget_Exception(_t('上传目录无法写入, 请手动将安装目录下的 %s 目录的权限设置为可写然后继续升级', Widget_Upload::UPLOAD_PATH));
+                    throw new Typecho_Widget_Exception(_t('上传目录无法写入, 请手动将安装目录下的 %s 目录的权限设置为可写然后继续升级', Widget_Upload::UPLOAD_DIR));
                 }
             }
         } else {
             if (!@mkdir($uploadDir, 0644)) {
-                throw new Typecho_Widget_Exception(_t('上传目录无法创建, 请手动创建安装目录下的 %s 目录, 并将它的权限设置为可写然后继续升级', Widget_Upload::UPLOAD_PATH));
+                throw new Typecho_Widget_Exception(_t('上传目录无法创建, 请手动创建安装目录下的 %s 目录, 并将它的权限设置为可写然后继续升级', Widget_Upload::UPLOAD_DIR));
             }
         }
 
diff --git a/var/Widget/Upgrade.php b/var/Widget/Upgrade.php
index baa87059..318d0d28 100644
--- a/var/Widget/Upgrade.php
+++ b/var/Widget/Upgrade.php
@@ -19,67 +19,46 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
  */
 class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface_Do
 {
-    /**
-     * 当前内部版本号
-     *
-     * @access private
-     * @var string
-     */
-    private $_currentVersion;
-
-    /**
-     * 对升级包按版本进行排序
-     *
-     * @access public
-     *
-     * @param string $a a版本
-     * @param string $b b版本
-     *
-     * @return integer
-     */
-    public function sortPackage($a, $b)
-    {
-        [$ver, $rev] = explode('r', $a);
-        $a = str_replace('_', '.', $rev);
-
-        [$ver, $rev] = explode('r', $b);
-        $b = str_replace('_', '.', $rev);
-
-        return version_compare($a, $b, '>') ? 1 : - 1;
-    }
-
-    /**
-     * 过滤低版本的升级包
-     *
-     * @access public
-     *
-     * @param string $version 版本号
-     *
-     * @return boolean
-     */
-    public function filterPackage($version)
-    {
-        [$ver, $rev] = explode('r', $version);
-        $rev = str_replace('_', '.', $rev);
-        return version_compare($rev, $this->_currentVersion, '>');
-    }
-
     /**
      * 执行升级程序
      *
      * @access public
      * @return void
+     * @throws Typecho_Exception
      */
     public function upgrade()
     {
-        [$prefix, $this->_currentVersion] = explode('/', $this->options->generator);
         $packages = get_class_methods('Upgrade');
-        $packages = array_filter($packages, [$this, 'filterPackage']);
-        usort($packages, [$this, 'sortPackage']);
+
+        preg_match("/^\w+ ([0-9\.]+)(\/[0-9\.]+)?$/i", $this->options->generator, $matches);
+        $currentVersion = $matches[1];
+        $currentMinor = '0';
+        if (isset($matches[2])) {
+            $currentMinor = substr($matches[2], 1);
+        }
 
         $message = [];
 
         foreach ($packages as $package) {
+            preg_match("/^v([_0-9]+)(r[_0-9]+)?$/", $package, $matches);
+
+            $version = str_replace('_', '.', $matches[1]);
+
+            if (version_compare($currentVersion, $version, '>')) {
+                break;
+            }
+
+            if (isset($matches[2])) {
+                $minor = substr(str_replace('_', '.', $matches[2]), 1);
+
+                if (version_compare($currentVersion, $version, '=')
+                    && version_compare($currentMinor, $minor, '>=')) {
+                    break;
+                }
+
+                $version .= '/' . $minor;
+            }
+
             $options = $this->widget('Widget_Options@' . $package);
 
             /** 执行升级脚本 */
@@ -94,12 +73,8 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
                 return;
             }
 
-            [$ver, $rev] = explode('r', $package);
-            $ver = substr(str_replace('_', '.', $ver), 1);
-            $rev = str_replace('_', '.', $rev);
-
             /** 更新版本号 */
-            $this->update(['value' => 'Typecho ' . $ver . '/' . $rev],
+            $this->update(['value' => 'Typecho ' . $version],
                 $this->db->sql()->where('name = ?', 'generator'));
 
             $this->destroy('Widget_Options@' . $package);

From 22cadcc884448cdc388da339f84fcebde6627336 Mon Sep 17 00:00:00 2001
From: joyqi <magike.net@gmail.com>
Date: Fri, 20 Aug 2021 01:08:37 +0800
Subject: [PATCH 6/6] add trigger

---
 .github/workflows/Typecho-dev-Ci.yml |  7 +++++--
 var/Typecho/Widget.php               | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/Typecho-dev-Ci.yml b/.github/workflows/Typecho-dev-Ci.yml
index 072df14f..229a057c 100644
--- a/.github/workflows/Typecho-dev-Ci.yml
+++ b/.github/workflows/Typecho-dev-Ci.yml
@@ -47,5 +47,8 @@ jobs:
     - name: Upload a Build Artifact
       uses: actions/upload-artifact@v2
       with:
-          name: typecho
-          path: ./build/
+        name: typecho
+        path: ./build/
+    - name: Trigger build
+      run: |
+        curl -XPOST -u "${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/typecho/languages/actions/workflows/update.yml/dispatches --data '{"ref": "master"}'
diff --git a/var/Typecho/Widget.php b/var/Typecho/Widget.php
index c123b076..35011d31 100644
--- a/var/Typecho/Widget.php
+++ b/var/Typecho/Widget.php
@@ -408,6 +408,22 @@ abstract class Typecho_Widget
         $this->row[$name] = $value;
     }
 
+    /**
+     * @return int
+     */
+    public function getSequence(): int
+    {
+        return $this->sequence;
+    }
+
+    /**
+     * @return int
+     */
+    public function getLength(): int
+    {
+        return $this->length;
+    }
+
     /**
      * 验证堆栈值是否存在
      *