增加刷数据库的函数 提供给日后更新数据用

This commit is contained in:
Zhai Yiming 2017-07-14 11:08:33 +08:00
parent 8cdd62dcfe
commit 92f41b0fbd

View File

@ -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对象
*