From 92f41b0fbd3b5caa08d4c9a55dd6e48c5e169db8 Mon Sep 17 00:00:00 2001 From: Zhai Yiming Date: Fri, 14 Jul 2017 11:08:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=B7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=9A=84=E5=87=BD=E6=95=B0=20=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E7=BB=99=E6=97=A5=E5=90=8E=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Access_Core.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Access_Core.php b/Access_Core.php index e9f590e..c07f775 100644 --- a/Access_Core.php +++ b/Access_Core.php @@ -356,6 +356,33 @@ class Access_Core } catch (Exception $e) {} catch (Typecho_Db_Query_Exception $e) {} } + /** + * 重新刷数据库,当遇到一些算法变更时可能需要用到 + * + * @access public + * @return void + * @throws Typecho_Plugin_Exception + */ + public static function rewriteLogs() { + $db = Typecho_Db::get(); + $rows = $db->fetchAll($db->select()->from('table.access_log')); + foreach ($rows as $row) { + $ua = new Access_UA($row['ua']); + $row['browser_id' ] = $ua->getBrowserID(); + $row['browser_version' ] = $ua->getBrowserVersion(); + $row['os_id' ] = $ua->getOSID(); + $row['os_version' ] = $ua->getOSVersion(); + $row['robot' ] = $ua->isRobot() ? 1 : 0; + $row['robot_id' ] = $ua->getRobotID(); + $row['robot_version' ] = $ua->getRobotVersion(); + try { + $db->query($db->update('table.access_log')->rows($row)->where('id = ?', $row['id'])); + } catch (Typecho_Db_Exception $e) { + throw new Typecho_Plugin_Exception(_t('刷新数据库失败:%s。', $e->getMessage())); + } + } + } + /** * 解析archive对象 *