⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upgradeitems.inc.php.svn-base

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
<?php/** * $Id$ * * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program.  If not, see <http://www.gnu.org/licenses/>. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * */// {{{ Format of the descriptor/** * Format of the descriptor * * type*version*phase*simple description for uniqueness * * type is: sql, function, subupgrade, upgrade * version is: 1.2.4, 2.0.0rc5 * phase is: 0, 1, 0pre.  Phase is _only_ evaluated by describeUpgrades. * description is: anything, unique in terms of version and type. */// }}}require_once(KT_LIB_DIR . '/upgrades/UpgradeFunctions.inc.php');require_once(KT_LIB_DIR . '/database/sqlfile.inc.php');require_once(KT_LIB_DIR . '/database/datetime.inc');// {{{ Upgrade_Already_Appliedclass Upgrade_Already_Applied extends PEAR_Error {    function Upgrade_Already_Applied($oUpgradeItem) {        $this->oUpgradeItem = $oUpgradeItem;    }}// }}}class UpgradeItem {    var $type = "";    var $name;    var $version;    var $description;    var $phase;    var $priority = 0;    var $parent;    var $date;    var $result;    function UpgradeItem($name, $version, $description = null, $phase = 0, $priority = 0) {        $this->name = $name;        $this->version = $version;        if (is_null($description)) {            $description = $this->type . " upgrade to version " .  $version . " phase " . $phase;        }        $this->description = $description;        $this->phase = $phase;        $this->priority = $priority;    }    function setParent($parent) {        $this->parent = $parent;    }    function setDate($date) {        $this->date = $date;    }    function getDescriptor() {        return join("*", array($this->type, $this->version, $this->phase, $this->name));    }    function getDescription() {        return $this->description;    }    function getVersion() {        return $this->version;    }    function getPhase() {        return $this->phase;    }    function getPriority() {        return $this->priority;    }    function getType() {        return $this->type;    }    function _upgradeTableInstalled() {        $query = "SELECT COUNT(id) FROM upgrades";        $res = DBUtil::getOneResult($query);        if (PEAR::isError($res)) {            return false;        }        return true;    }    function isAlreadyApplied() {        if (!$this->_upgradeTableInstalled()) {            return false;        }        $query = "SELECT id FROM upgrades WHERE descriptor = ? AND result = ?";        $params = array($this->getDescriptor(), true);        $res = DBUtil::getOneResultKey(array($query, $params), 'id');        if (PEAR::isError($res)) {            return $res;        }        if (is_null($res)) {            return false;        }        return true;    }    function performUpgrade($force = false) {        $res = $this->isAlreadyApplied();        if ($res === true) {            if ($force !== true) {                // PHP5: Exception                return new Upgrade_Already_Applied($this);            }        }        if (PEAR::isError($res)) {            return $res;        }        $oCache =& KTCache::getSingleton();        $save = $oCache->bEnabled;        $oCache->bEnabled = false;        $res = $this->_performUpgrade();        $oCache->bEnabled = $save;        if (PEAR::isError($res)) {            $this->_recordUpgrade(false);            return $res;        }        $res = $this->_recordUpgrade(true);        if (PEAR::isError($res)) {            return $res;        }        return true;    }    function _performUpgrade() {        return PEAR::raiseError("Unimplemented");    }    function _recordUpgrade($result) {        if (is_null($this->date)) {            $this->date = getCurrentDateTime();        }        if ($this->parent) {            $parentid = $this->parent->getDescriptor();        } else {            $parentid = null;        }        return DBUtil::autoInsert("upgrades", array(            "descriptor" => $this->getDescriptor(),            "description" => $this->description,            "date_performed" => $this->date,            "result" => $result,            "parent" => $parentid,        ));    }    // STATIC    function getAllUpgrades() {        return array();    }}class SQLUpgradeItem extends UpgradeItem {    function SQLUpgradeItem($path, $version = null, $description = null, $phase = null, $priority = null) {        $this->type = "sql";        $this->priority = 0;        $details = $this->_getDetailsFromFileName($path);        if (is_null($version)) {            $version = $details[1];        }        if (is_null($description)) {            $description = $details[2];        }        if (is_null($phase)) {            $phase = $details[3];        }        if (is_null($priority)) {            $priority = isset($details[4]) ? $details[4] : 0;        }        $this->UpgradeItem($path, $version, $description, $phase, $priority);    }    /**     * Describe the SQL scripts that will be used to upgrade KnowledgeTree     *     * Return an array of arrays with two components: a string identifier     * that uniquely describes the step to be taken and a string which is an     * HTML-formatted description of the step to be taken.  These will be     * returned in any order - describeUpgrade performs the ordering.     *     * @param string Original version (e.g., "1.2.4")     * @param string Current version (e.g., "2.0.2")     *     * @return array Array of SQLUpgradeItem describing steps to be taken     *     * STATIC     */    function getUpgrades($origVersion, $currVersion) {        global $default;        $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/';        $ret = array();        if (!is_dir($sqlupgradedir)) {            return PEAR::raiseError("SQL Upgrade directory ($sqlupgradedir) not accessible");        }        if (!($dh = opendir($sqlupgradedir))) {            return PEAR::raiseError("SQL Upgrade directory ($sqlupgradedir) not accessible");        }        while (($file = readdir($dh)) !== false) {            // Each entry can be a file or a directory            //            // A file is legacy before the upgrade system was created, but            // will be supported anyway.            //            // A directory is the end-result version: so, 2.0.5 contains            // every script that differentiates it from a previous version,            // say, 2.0.5rc1 or 2.0.4.            //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -