') ? 1 : -1; } /** * 过滤低版本的升级包 * * @access public * @param string $version 版本号 * @return boolean */ public function filterPackage($version) { list ($ver, $rev) = explode('r', $version); $rev = str_replace('_', '.', $rev); return version_compare($rev, $this->_currentVersion, '>'); } /** * 执行升级程序 * * @access public * @return void */ public function upgrade() { list($prefix, $this->_currentVersion) = explode('/', $this->options->generator); $packages = get_class_methods('Upgrade'); $packages = array_filter($packages, array($this, 'filterPackage')); usort($packages, array($this, 'sortPackage')); $message = array(); foreach ($packages as $package) { $options = $this->widget('Widget_Options@' . $package); /** 执行升级脚本 */ try { $result = call_user_func(array('Upgrade', $package), $this->db, $options); if (!empty($result)) { $message[] = $result; } } catch (Typecho_Exception $e) { $this->widget('Widget_Notice')->set($e->getMessage(), 'error'); $this->response->goBack(); return; } list ($ver, $rev) = explode('r', $package); $ver = substr(str_replace('_', '.', $ver), 1); $rev = str_replace('_', '.', $rev); /** 更新版本号 */ $this->update(array('value' => 'Typecho ' . $ver . '/' . $rev), $this->db->sql()->where('name = ?', 'generator')); $this->destory('Widget_Options@' . $package); } /** 更新版本号 */ $this->update(array('value' => 'Typecho ' . Typecho_Common::VERSION), $this->db->sql()->where('name = ?', 'generator')); $this->widget('Widget_Notice')->set(empty($message) ? _t("升级已经完成") : $message, empty($message) ? 'success' : 'notice'); } /** * 初始化函数 * * @access public * @return void */ public function action() { $this->user->pass('administrator'); $this->security->protect(); $this->on($this->request->isPost())->upgrade(); $this->response->redirect($this->options->adminUrl); } }