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

📄 installer.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 3 页
字号:
                    if ($pkg == $pkgname) {                        unset($test[$file]);                    }                }                if (sizeof($test)) {                    $msg = "$pkgname: conflicting files found:\n";                    $longest = max(array_map("strlen", array_keys($test)));                    $fmt = "%${longest}s (%s)\n";                    foreach ($test as $file => $pkg) {                        $msg .= sprintf($fmt, $file, $pkg);                    }                    return $this->raiseError($msg);                }            }        }        // }}}        $this->startFileTransaction();        if (empty($options['upgrade'])) {            // checks to do only when installing new packages            if (empty($options['force']) && $this->registry->packageExists($pkgname)) {                return $this->raiseError("$pkgname already installed");            }        } else {            if ($this->registry->packageExists($pkgname)) {                $v1 = $this->registry->packageInfo($pkgname, 'version');                $v2 = $pkginfo['version'];                $cmp = version_compare("$v1", "$v2", 'gt');                if (empty($options['force']) && !version_compare("$v2", "$v1", 'gt')) {                    return $this->raiseError("upgrade to a newer version ($v2 is not newer than $v1)");                }                if (empty($options['register-only'])) {                    // when upgrading, remove old release's files first:                    if (PEAR::isError($err = $this->_deletePackageFiles($pkgname))) {                        return $this->raiseError($err);                    }                }            }        }        // {{{ Copy files to dest dir ---------------------------------------        // info from the package it self we want to access from _installFile        $this->pkginfo = &$pkginfo;        // used to determine whether we should build any C code        $this->source_files = 0;        if (empty($options['register-only'])) {            if (!is_dir($php_dir)) {                return $this->raiseError("no script destination directory\n",                                         null, PEAR_ERROR_DIE);            }            $tmp_path = dirname($descfile);            if (substr($pkgfile, -4) != '.xml') {                $tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkginfo['version'];            }            //  ==> XXX This part should be removed later on            if ($flag_old_format) {                $tmp_path = dirname($descfile);            }            // <== XXX This part should be removed later on            // {{{ install files            foreach ($pkginfo['filelist'] as $file => $atts) {                $this->expectError(PEAR_INSTALLER_FAILED);                $res = $this->_installFile($file, $atts, $tmp_path, $options);                $this->popExpect();                if (PEAR::isError($res)) {                    if (empty($options['ignore-errors'])) {                        $this->rollbackFileTransaction();                        if ($res->getMessage() == "file does not exist") {                            $this->raiseError("file $file in package.xml does not exist");                        }                        return $this->raiseError($res);                    } else {                        $this->log(0, "Warning: " . $res->getMessage());                    }                }                if ($res != PEAR_INSTALLER_OK) {                    // Do not register files that were not installed                    unset($pkginfo['filelist'][$file]);                }            }            // }}}            // {{{ compile and install source files            if ($this->source_files > 0 && empty($options['nobuild'])) {                $this->log(1, "$this->source_files source files, building");                $bob = &new PEAR_Builder($this->ui);                $bob->debug = $this->debug;                $built = $bob->build($descfile, array(&$this, '_buildCallback'));                if (PEAR::isError($built)) {                    $this->rollbackFileTransaction();                    return $built;                }                $this->log(1, "\nBuild process completed successfully");                foreach ($built as $ext) {                    $bn = basename($ext['file']);                    list($_ext_name, ) = explode('.', $bn);                    if (extension_loaded($_ext_name)) {                        $this->raiseError("Extension '$_ext_name' already loaded. Please unload it ".                                          "in your php.ini file prior to install or upgrade it.");                    }                    $dest = $this->config->get('ext_dir') . DIRECTORY_SEPARATOR . $bn;                    $this->log(1, "Installing '$bn' at ext_dir ($dest)");                    $this->log(3, "+ cp $ext[file] ext_dir ($dest)");                    $copyto = $this->_prependPath($dest, $this->installroot);                    if (!@copy($ext['file'], $copyto)) {                        $this->rollbackFileTransaction();                        return $this->raiseError("failed to copy $bn to $copyto");                    }                    $pkginfo['filelist'][$bn] = array(                        'role' => 'ext',                        'installed_as' => $dest,                        'php_api' => $ext['php_api'],                        'zend_mod_api' => $ext['zend_mod_api'],                        'zend_ext_api' => $ext['zend_ext_api'],                        );                }            }            // }}}        }        if (!$this->commitFileTransaction()) {            $this->rollbackFileTransaction();            return $this->raiseError("commit failed", PEAR_INSTALLER_FAILED);        }        // }}}        $ret = false;        // {{{ Register that the package is installed -----------------------        if (empty($options['upgrade'])) {            // if 'force' is used, replace the info in registry            if (!empty($options['force']) && $this->registry->packageExists($pkgname)) {                $this->registry->deletePackage($pkgname);            }            $ret = $this->registry->addPackage($pkgname, $pkginfo);        } else {            // new: upgrade installs a package if it isn't installed            if (!$this->registry->packageExists($pkgname)) {                $ret = $this->registry->addPackage($pkgname, $pkginfo);            } else {                $ret = $this->registry->updatePackage($pkgname, $pkginfo, false);            }        }        if (!$ret) {            return $this->raiseError("Adding package $pkgname to registry failed");        }        // }}}        return $pkginfo;    }    // }}}    // {{{ uninstall()    /**     * Uninstall a package     *     * This method removes all files installed by the application, and then     * removes any empty directories.     * @param string package name     * @param array Command-line options.  Possibilities include:     *     *              - installroot: base installation dir, if not the default     *              - nodeps: do not process dependencies of other packages to ensure     *                        uninstallation does not break things     */    function uninstall($package, $options = array())    {        $php_dir = $this->config->get('php_dir');        if (isset($options['installroot'])) {            if (substr($options['installroot'], -1) == DIRECTORY_SEPARATOR) {                $options['installroot'] = substr($options['installroot'], 0, -1);            }            $this->installroot = $options['installroot'];            $php_dir = $this->_prependPath($php_dir, $this->installroot);        } else {            $this->installroot = '';        }        $this->registry = &new PEAR_Registry($php_dir);        $filelist = $this->registry->packageInfo($package, 'filelist');        if ($filelist == null) {            return $this->raiseError("$package not installed");        }        if (empty($options['nodeps'])) {            $depchecker = &new PEAR_Dependency($this->registry);            $error = $depchecker->checkPackageUninstall($errors, $warning, $package);            if ($error) {                return $this->raiseError($errors . 'uninstall failed');            }            if ($warning) {                $this->log(0, $warning);            }        }        // {{{ Delete the files        $this->startFileTransaction();        if (PEAR::isError($err = $this->_deletePackageFiles($package))) {            $this->rollbackFileTransaction();            return $this->raiseError($err);        }        if (!$this->commitFileTransaction()) {            $this->rollbackFileTransaction();            return $this->raiseError("uninstall failed");        } else {            $this->startFileTransaction();            if (!isset($filelist['dirtree']) || !count($filelist['dirtree'])) {                return $this->registry->deletePackage($package);            }            // attempt to delete empty directories            uksort($filelist['dirtree'], array($this, '_sortDirs'));            foreach($filelist['dirtree'] as $dir => $notused) {                $this->addFileOperation('rmdir', array($dir));            }            if (!$this->commitFileTransaction()) {                $this->rollbackFileTransaction();            }        }        // }}}        // Register that the package is no longer installed        return $this->registry->deletePackage($package);    }    // }}}    // {{{ _sortDirs()    function _sortDirs($a, $b)    {        if (strnatcmp($a, $b) == -1) return 1;        if (strnatcmp($a, $b) == 1) return -1;        return 0;    }    // }}}    // {{{ checkDeps()    /**     * Check if the package meets all dependencies     *     * @param  array   Package information (passed by reference)     * @param  string  Error message (passed by reference)     * @return boolean False when no error occured, otherwise true     */    function checkDeps(&$pkginfo, &$errors)    {        if (empty($this->registry)) {            $this->registry = &new PEAR_Registry($this->config->get('php_dir'));        }        $depchecker = &new PEAR_Dependency($this->registry);        $error = $errors = '';        $failed_deps = $optional_deps = array();        if (is_array($pkginfo['release_deps'])) {            foreach($pkginfo['release_deps'] as $dep) {                $code = $depchecker->callCheckMethod($error, $dep);                if ($code) {                    if (isset($dep['optional']) && $dep['optional'] == 'yes') {                        $optional_deps[] = array($dep, $code, $error);                    } else {                        $failed_deps[] = array($dep, $code, $error);                    }                }            }            // {{{ failed dependencies            $n = count($failed_deps);            if ($n > 0) {                for ($i = 0; $i < $n; $i++) {                    if (isset($failed_deps[$i]['type'])) {                        $type = $failed_deps[$i]['type'];                    } else {                        $type = 'pkg';                    }                    switch ($failed_deps[$i][1]) {                        case PEAR_DEPENDENCY_MISSING:                            if ($type == 'pkg') {                                // install                            }                            $errors .= "\n" . $failed_deps[$i][2];                            break;                        case PEAR_DEPENDENCY_UPGRADE_MINOR:                            if ($type == 'pkg') {                                // upgrade                            }                            $errors .= "\n" . $failed_deps[$i][2];                            break;                        default:                            $errors .= "\n" . $failed_deps[$i][2];                            break;                    }                }                return true;            }            // }}}            // {{{ optional dependencies            $count_optional = count($optional_deps);            if ($count_optional > 0) {                $errors = "Optional dependencies:";                for ($i = 0; $i < $count_optional; $i++) {                    if (isset($optional_deps[$i]['type'])) {                        $type = $optional_deps[$i]['type'];                    } else {                        $type = 'pkg';                    }                    switch ($optional_deps[$i][1]) {                        case PEAR_DEPENDENCY_MISSING:                        case PEAR_DEPENDENCY_UPGRADE_MINOR:                        default:                            $errors .= "\n" . $optional_deps[$i][2];                            break;                    }                }                return false;            }            // }}}        }        return false;    }    // }}}    // {{{ _buildCallback()    function _buildCallback($what, $data)    {        if (($what == 'cmdoutput' && $this->debug > 1) ||            ($what == 'output' && $this->debug > 0)) {            $this->ui->outputData(rtrim($data), 'build');        }    }    // }}}}// {{{ md5_file() utility functionif (!function_exists("md5_file")) {    function md5_file($filename) {        $fp = fopen($filename, "r");        if (!$fp) return null;        $contents = fread($fp, filesize($filename));        fclose($fp);        return md5($contents);    }}// }}}?>

⌨️ 快捷键说明

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