From f3dab3996d69f58eb999965c07ca41ab22068058 Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 8 Dec 2017 18:38:19 +0800 Subject: [PATCH] fix #682 --- install/Mysql.sql | 2 +- install/Pgsql.sql | 2 +- install/SQLite.sql | 2 +- var/Typecho/Common.php | 2 +- var/Upgrade.php | 64 ++++++++++++++++++++++++++++++++ var/Widget/Abstract/Comments.php | 5 +++ 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/install/Mysql.sql b/install/Mysql.sql index 73c6de51..c55a584c 100644 --- a/install/Mysql.sql +++ b/install/Mysql.sql @@ -27,7 +27,7 @@ CREATE TABLE `typecho_comments` ( `mail` varchar(150) default NULL, `url` varchar(150) default NULL, `ip` varchar(64) default NULL, - `agent` varchar(150) default NULL, + `agent` varchar(511) default NULL, `text` text, `type` varchar(16) default 'comment', `status` varchar(16) default 'approved', diff --git a/install/Pgsql.sql b/install/Pgsql.sql index cdb82032..b3bceb8c 100644 --- a/install/Pgsql.sql +++ b/install/Pgsql.sql @@ -12,7 +12,7 @@ CREATE TABLE "typecho_comments" ( "coid" INT NOT NULL DEFAULT nextval('typecho_ "mail" VARCHAR(150) NULL DEFAULT NULL, "url" VARCHAR(150) NULL DEFAULT NULL, "ip" VARCHAR(64) NULL DEFAULT NULL, - "agent" VARCHAR(150) NULL DEFAULT NULL, + "agent" VARCHAR(511) NULL DEFAULT NULL, "text" TEXT NULL DEFAULT NULL, "type" VARCHAR(16) NULL DEFAULT 'comment', "status" VARCHAR(16) NULL DEFAULT 'approved', diff --git a/install/SQLite.sql b/install/SQLite.sql index ba8df08d..d389875a 100644 --- a/install/SQLite.sql +++ b/install/SQLite.sql @@ -7,7 +7,7 @@ CREATE TABLE typecho_comments ( "coid" INTEGER NOT NULL PRIMARY KEY, "mail" varchar(150) default NULL , "url" varchar(150) default NULL , "ip" varchar(64) default NULL , -"agent" varchar(150) default NULL , +"agent" varchar(511) default NULL , "text" text , "type" varchar(16) default 'comment' , "status" varchar(16) default 'approved' , diff --git a/var/Typecho/Common.php b/var/Typecho/Common.php index cd4fcc0f..271e1314 100644 --- a/var/Typecho/Common.php +++ b/var/Typecho/Common.php @@ -22,7 +22,7 @@ define('__TYPECHO_MB_SUPPORTED__', function_exists('mb_get_info') && function_ex class Typecho_Common { /** 程序版本 */ - const VERSION = '1.1/17.11.15'; + const VERSION = '1.1/17.12.8'; /** * 允许的属性 diff --git a/var/Upgrade.php b/var/Upgrade.php index 68c915d7..800b09bd 100644 --- a/var/Upgrade.php +++ b/var/Upgrade.php @@ -1264,5 +1264,69 @@ Typecho_Date::setTimezoneOffset($options->timezone); ->rows(array('name' => 'allowXmlRpc', 'user' => 0, 'value' => 2))); } } + + /** + * 升级至17.12.8 + * + * @param $db + */ + public static function v1_1r17_12_8($db) + { + /** 修改数据库字段 */ + $adapterName = $db->getAdapterName(); + $prefix = $db->getPrefix(); + + switch (true) { + case false !== strpos($adapterName, 'Mysql'): + $db->query("ALTER TABLE `" . $prefix . "comments` MODIFY COLUMN `agent` varchar(511)", Typecho_Db::WRITE); + break; + + case false !== strpos($adapterName, 'Pgsql'): + $db->query('ALTER TABLE "' . $prefix . 'comments" ALTER COLUMN "agent" TYPE varchar(511)', Typecho_Db::WRITE); + break; + + case false !== strpos($adapterName, 'SQLite'): + $uuid = uniqid(); + $db->query('CREATE TABLE ' . $prefix . 'comments' . $uuid . ' ( "coid" INTEGER NOT NULL PRIMARY KEY, +"cid" int(10) default \'0\' , +"created" int(10) default \'0\' , +"author" varchar(150) default NULL , +"authorId" int(10) default \'0\' , +"ownerId" int(10) default \'0\' , +"mail" varchar(150) default NULL , +"url" varchar(150) default NULL , +"ip" varchar(64) default NULL , +"agent" varchar(511) default NULL , +"text" text , +"type" varchar(16) default \'comment\' , +"status" varchar(16) default \'approved\' , +"parent" int(10) default \'0\')', Typecho_Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'comments' . $uuid . ' SELECT * FROM ' . $prefix . 'comments', Typecho_Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'metas', Typecho_Db::WRITE); + $db->query('CREATE TABLE ' . $prefix . 'comments ( "coid" INTEGER NOT NULL PRIMARY KEY, +"cid" int(10) default \'0\' , +"created" int(10) default \'0\' , +"author" varchar(150) default NULL , +"authorId" int(10) default \'0\' , +"ownerId" int(10) default \'0\' , +"mail" varchar(150) default NULL , +"url" varchar(150) default NULL , +"ip" varchar(64) default NULL , +"agent" varchar(511) default NULL , +"text" text , +"type" varchar(16) default \'comment\' , +"status" varchar(16) default \'approved\' , +"parent" int(10) default \'0\')', Typecho_Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'comments SELECT * FROM ' . $prefix . 'comments' . $uuid, Typecho_Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'comments' . $uuid, Typecho_Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'comments_cid ON ' . $prefix . 'comments ("cid")', Typecho_Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'comments_created ON ' . $prefix . 'comments ("created")', Typecho_Db::WRITE); + $db->flushPool(); + break; + + default: + break; + } + } } diff --git a/var/Widget/Abstract/Comments.php b/var/Widget/Abstract/Comments.php index 22ed2065..aafd9ae4 100644 --- a/var/Widget/Abstract/Comments.php +++ b/var/Widget/Abstract/Comments.php @@ -185,6 +185,11 @@ class Widget_Abstract_Comments extends Widget_Abstract $insertStruct['coid'] = $comment['coid']; } + /** 过长的客户端字符串要截断 */ + if (Typecho_Common::strLen($insertStruct['agent']) > 511) { + $insertStruct['agent'] = Typecho_Common::subStr($insertStruct['agent'], 0, 511, ''); + } + /** 首先插入部分数据 */ $insertId = $this->db->query($this->db->insert('table.comments')->rows($insertStruct));