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

📄 upgradeitems.inc.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
            if (in_array($file, array('.', '..', 'CVS'))) {
                continue;
            }
            $fullpath = $sqlupgradedir . $file;
            if (is_file($fullpath)) {
                // Legacy file support, will be in form of
                // 1.2.4-to-2.0.0.sql.
                $details = SQLUpgradeItem::_getDetailsFromFileName($file);
                if ($details) {
                    if (!gte_version($details[0], $origVersion)) {
                        continue;
                    }
                    if (!lte_version($details[1], $currVersion)) {
                        continue;
                    }
                    //print "Will run $file\n";
                    $ret[] = new SQLUpgradeItem($file);
                }
            }
            if (is_dir($fullpath)) {
                $subdir = $file;
                if (!($subdh = opendir($fullpath))) {
                    continue;
                }
                while (($file = readdir($subdh)) !== false) {
                    $relpath = $subdir . '/' . $file;
                    $details = SQLUpgradeItem::_getDetailsFromFileName($relpath);
                    if ($details) {
                        if (!gte_version($details[0], $origVersion)) {
                            continue;
                        }
                        if (!lte_version($details[1], $currVersion)) {
                            continue;
                        }
                        //print "Will run $file\n";
                        $ret[] = new SQLUpgradeItem($relpath);
                    }
                }
            }
       }
       closedir($dh);
       return $ret;
    }

    function _getDetailsFromFileName($path) {
        // Old format (pre 2.0.6)
        $matched = preg_match('#^([\d.]*)-to-([\d.]*).sql$#', $path, $matches);
        if ($matched != 0) {
            $fromVersion = $matches[1];
            $toVersion = $matches[2];
            $description = "Database upgrade from version $fromVersion to $toVersion";
            $phase = 0;
            return array($fromVersion, $toVersion, $description, $phase);
        }
        $matched = preg_match('#^([\d.]*)/(?:(\d*)-)?(.*)\.sql$#', $path, $matches);
        //$matched = preg_match('#^([\d.]*)/(?:(\d*)-)?(.*):(?:(\d*))\.sql$#', $path, $matches);
        if ($matched != 0) {
            $fromVersion = $matches[1];
            $toVersion = $matches[1];
            $in = array('_');
            $out = array(' ');
            $phase = (int)$matches[2];

            //$priority = (int)$matches[4];
            $priority = 0;
            $iPriority = preg_match('#^(.*)-(\d*)$#', $matches[3], $priorities);
            if($iPriority != 0){
                $priority = $priorities[2];
                $matches[3] = $priorities[1];
            }

            $description = "Database upgrade to version $toVersion: " . ucfirst(str_replace($in, $out, $matches[3]));
            return array($fromVersion, $toVersion, $description, $phase, $priority);
        }
        // XXX: handle new format
        return null;
    }

    function _performUpgrade() {
        global $default;
        $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/';
        $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name);
        return DBUtil::runQueries($queries, $default->_admindb);
    }
}

class FunctionUpgradeItem extends UpgradeItem {
    function FunctionUpgradeItem ($func, $version, $description = null, $phase = null, $priority = null) {
        $this->type = "func";
        if (is_null($description)) {
            $aUpgradeFunctions = new UpgradeFunctions;
            $description = $UpgradeFunctions->descriptions[$func];
        }
        if (is_null($phase)) {
            $phase = 0;
        }
        if(is_null($priority)){
            $priority = 0;
        }
        $this->UpgradeItem($func, $version, $description, $phase, $priority);
    }

    function getUpgrades($origVersion, $currVersion) {
        $aUpgradeFunctions = new UpgradeFunctions;

        $ret = array();

        foreach ($aUpgradeFunctions->upgrades as $version => $funcs) {
            if (!gte_version($version, $origVersion)) {
                continue;
            }
            if (!lte_version($version, $currVersion)) {
                continue;
            }
            foreach ($funcs as $func) {
                $iPhase = KTUtil::arrayGet($aUpgradeFunctions->phases, $func, 0);
                $iPriority = KTUtil::arrayGet($aUpgradeFunctions->priority, $func, 0);
                $ret[] = new FunctionUpgradeItem($func, $version, $aUpgradeFunctions->descriptions[$func], $iPhase, $iPriority);
            }
        }
        return $ret;
    }

    function _performUpgrade() {
        $function = array('UpgradeFunctions', $this->name);
        return call_user_func($function);
    }
}

class KTRebuildPermissionObserver {
    function start() {
        $this->lastBeat = time();
    }
    function receiveMessage() {
        $now = time();
        if ($this->lastBeat + 15 < $now) {
            print "<!--          -->";
            ob_flush();
            flush();
        }
    }
    function end() {
    }
}

class RecordUpgradeItem extends UpgradeItem {
    function RecordUpgradeItem ($version, $oldversion = null) {
        $this->type = "upgrade";
        if (is_null($oldversion)) {
            $this->description = "Upgrade to version $version";
        } else {
            $this->description = "Upgrade from version $oldversion to $version";
        }
        $this->phase = 99;
        $this->version = $version;
        $this->name = 'upgrade' . $version;
    }

    function _performUpgrade() {
        $this->_deleteSmartyFiles();
        $this->_deleteProxyFiles();
        require_once(KT_LIB_DIR . '/cache/cache.inc.php');
        $oCache =& KTCache::getSingleton();
        $oCache->deleteAllCaches();

        require_once(KT_LIB_DIR .  '/permissions/permissionutil.inc.php');

        $po =& new KTRebuildPermissionObserver($this);
        $po->start();
        $oChannel =& KTPermissionChannel::getSingleton();
        $oChannel->addObserver($po);

        set_time_limit(0);
        ignore_user_abort(true);

        KTPermissionUtil::rebuildPermissionLookups(true);
        $po->end();

        $versionFile=KT_DIR . '/docs/VERSION-NAME.txt';
        $fp = fopen($versionFile,'rt');
        $systemVersion = fread($fp, filesize($versionFile));
        fclose($fp);

        $query = "UPDATE system_settings SET value = ? WHERE name = ?";
        $aParams = array($systemVersion, "knowledgetreeVersion");
        DBUtil::runQuery(array($query, $aParams));

        $query = "UPDATE system_settings SET value = ? WHERE name = ?";
        $aParams = array($this->version, "databaseVersion");
        return DBUtil::runQuery(array($query, $aParams));
    }

    function _deleteSmartyFiles() {
        $oConfig =& KTConfig::getSingleton();
        $dir = sprintf('%s/%s', $oConfig->get('urls/varDirectory'), 'tmp');

        $dh = @opendir($dir);
        if (empty($dh)) {
            return;
        }
        $aFiles = array();
        while (false !== ($sFilename = readdir($dh))) {
            if (substr($sFilename, -10) == "smarty.inc") {
               $aFiles[] = sprintf('%s/%s', $dir, $sFilename);
            }
            if (substr($sFilename, -10) == "smarty.php") {
               $aFiles[] = sprintf('%s/%s', $dir, $sFilename);
            }
        }
        foreach ($aFiles as $sFile) {
            @unlink($sFile);
        }
    }


    function _deleteProxyFiles() {
        $oKTConfig =& KTConfig::getSingleton();


        // from ktentityutil::_proxyCreate
        $sDirectory = $oKTConfig->get('cache/proxyCacheDirectory');

        if (!file_exists($sDirectory)) {
            return;
        }
        $sRunningUser = KTUtil::running_user();
        if ($sRunningUser) {
            $sDirectory = sprintf("%s/%s", $sDirectory, $sRunningUser);
        }
        if (!file_exists($sDirectory)) {
            return ;
        }

        $dh = @opendir($sDirectory);
        if (empty($dh)) {
            return;
        }
        $aFiles = array();
        while (false !== ($sFilename = readdir($dh))) {

            if (substr($sFilename, -8) == ".inc.php") {
               $aFiles[] = sprintf('%s/%s', $sDirectory, $sFilename);
            }
        }

        foreach ($aFiles as $sFile) {
            @unlink($sFile);
        }
    }
}

?>

⌨️ 快捷键说明

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