installer.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,594 行 · 第 1/5 页

PHP
1,594
字号
                $res = $this->_installFile2($pkg, $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 {                    if (!isset($options['soft'])) {                        $this->log(0, "Warning: " . $res->getMessage());                    }                }            }            if ($res == PEAR_INSTALLER_OK) {                // Register files that were installed                $pkg->installedFile($file, $atts);            }        }        // }}}        // {{{ compile and install source files        if ($this->source_files > 0 && empty($options['nobuild'])) {            if (PEAR::isError($err =                  $this->_compileSourceFiles($savechannel, $pkg))) {                return $err;            }        }        // }}}        if (isset($backedup)) {            $this->_removeBackups($backedup);        }        if (!$this->commitFileTransaction()) {            $this->rollbackFileTransaction();            $this->configSet('default_channel', $savechannel);            return $this->raiseError("commit failed", PEAR_INSTALLER_FAILED);        }        // }}}        $ret = false;        $installphase = 'install';        $oldversion = false;        // {{{ Register that the package is installed -----------------------        if (empty($options['upgrade'])) {            // if 'force' is used, replace the info in registry            $usechannel = $channel;            if ($channel == 'pecl.php.net') {                $test = $installregistry->packageExists($pkgname, $channel);                if (!$test) {                    $test = $installregistry->packageExists($pkgname, 'pear.php.net');                    $usechannel = 'pear.php.net';                }            } else {                $test = $installregistry->packageExists($pkgname, $channel);            }            if (!empty($options['force']) && $test) {                $oldversion = $installregistry->packageInfo($pkgname, 'version', $usechannel);                $installregistry->deletePackage($pkgname, $usechannel);            }            $ret = $installregistry->addPackage2($pkg);        } else {            $usechannel = $channel;            if ($channel == 'pecl.php.net') {                $test = $installregistry->packageExists($pkgname, $channel);                if (!$test) {                    $test = $installregistry->packageExists($pkgname, 'pear.php.net');                    $usechannel = 'pear.php.net';                }            } else {                $test = $installregistry->packageExists($pkgname, $channel);            }            // new: upgrade installs a package if it isn't installed            if (!$test) {                $ret = $installregistry->addPackage2($pkg);            } else {                if ($usechannel != $channel) {                    $installregistry->deletePackage($pkgname, $usechannel);                    $ret = $installregistry->addPackage2($pkg);                } else {                    $ret = $installregistry->updatePackage2($pkg);                }                $installphase = 'upgrade';            }        }        if (!$ret) {            $this->configSet('default_channel', $savechannel);            return $this->raiseError("Adding package $channel/$pkgname to registry failed");        }        // }}}        $this->configSet('default_channel', $savechannel);        if (class_exists('PEAR_Task_Common')) { // this is auto-included if any tasks exist            if (PEAR_Task_Common::hasPostinstallTasks()) {                PEAR_Task_Common::runPostinstallTasks($installphase);            }        }        return $pkg->toArray(true);    }    // }}}    // {{{ _compileSourceFiles()    /**     * @param string     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2     */    function _compileSourceFiles($savechannel, &$filelist)    {        require_once 'PEAR/Builder.php';        $this->log(1, "$this->source_files source files, building");        $bob = &new PEAR_Builder($this->ui);        $bob->debug = $this->debug;        $built = $bob->build($filelist, array(&$this, '_buildCallback'));        if (PEAR::isError($built)) {            $this->rollbackFileTransaction();            $this->configSet('default_channel', $savechannel);            return $built;        }        $this->log(1, "\nBuild process completed successfully");        foreach ($built as $ext) {            $bn = basename($ext['file']);            list($_ext_name, $_ext_suff) = explode('.', $bn);            if ($_ext_suff == '.so' || $_ext_suff == '.dll') {                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');                }                $role = 'ext';            } else {                $role = 'src';            }            $dest = $ext['dest'];            $packagingroot = '';            if (isset($this->_options['packagingroot'])) {                $packagingroot = $this->_options['packagingroot'];            }            $copyto = $this->_prependPath($dest, $packagingroot);            if ($copyto != $dest) {	            $this->log(1, "Installing '$dest' as '$copyto'");            } else {	            $this->log(1, "Installing '$dest'");            }            $copydir = dirname($copyto);            // pretty much nothing happens if we are only registering the install            if (empty($this->_options['register-only'])) {                if (!file_exists($copydir) || !is_dir($copydir)) {                    if (!$this->mkDirHier($copydir)) {                        return $this->raiseError("failed to mkdir $copydir",                            PEAR_INSTALLER_FAILED);                    }                    $this->log(3, "+ mkdir $copydir");                }                if (!@copy($ext['file'], $copyto)) {                    return $this->raiseError("failed to write $copyto ($php_errormsg)", PEAR_INSTALLER_FAILED);                }                $this->log(3, "+ cp $ext[file] $copyto");                $this->addFileOperation('rename', array($ext['file'], $copyto));                if (!OS_WINDOWS) {                    $mode = 0666 & ~(int)octdec($this->config->get('umask'));                    $this->addFileOperation('chmod', array($mode, $copyto));                    if (!@chmod($copyto, $mode)) {                        $this->log(0, "failed to change mode of $copyto ($php_errormsg)");                    }                }            }            if ($filelist->getPackageXmlVersion() == '1.0') {                $filelist->installedFile($bn, array(                    'role' => $role,                    'name' => $bn,                    'installed_as' => $dest,                    'php_api' => $ext['php_api'],                    'zend_mod_api' => $ext['zend_mod_api'],                    'zend_ext_api' => $ext['zend_ext_api'],                    ));            } else {                $filelist->installedFile($bn, array('attribs' => array(                    'role' => $role,                    'name' => $bn,                    'installed_as' => $dest,                    'php_api' => $ext['php_api'],                    'zend_mod_api' => $ext['zend_mod_api'],                    'zend_ext_api' => $ext['zend_ext_api'],                    )));            }        }    }    // }}}    function &getUninstallPackages()    {        return $this->_downloadedPackages;    }    // {{{ 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     *              - register-only : update registry but don't remove files     *              - nodeps: do not process dependencies of other packages to ensure     *                        uninstallation does not break things     */    function uninstall($package, $options = array())    {        if (isset($options['installroot'])) {            $this->config->setInstallRoot($options['installroot']);            $this->installroot = '';        } else {            $this->config->setInstallRoot('');            $this->installroot = '';        }        $this->_registry = &$this->config->getRegistry();        if (is_object($package)) {            $channel = $package->getChannel();            $pkg = $package;            $package = $pkg->getPackage();        } else {            $pkg = false;            $info = $this->_registry->parsePackageName($package,                $this->config->get('default_channel'));            $channel = $info['channel'];            $package = $info['package'];        }        $savechannel = $this->config->get('default_channel');        $this->configSet('default_channel', $channel);        if (!is_object($pkg)) {            $pkg = $this->_registry->getPackage($package, $channel);        }        if (!$pkg) {            $this->configSet('default_channel', $savechannel);            return $this->raiseError($this->_registry->parsedPackageNameToString(                array(                    'channel' => $channel,                    'package' => $package                ), true) . ' not installed');        }        if ($pkg->getInstalledBinary()) {            // this is just an alias for a binary package            return $this->_registry->deletePackage($package, $channel);        }        $filelist = $pkg->getFilelist();        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);        if (!class_exists('PEAR_Dependency2')) {            require_once 'PEAR/Dependency2.php';        }        $depchecker = &new PEAR_Dependency2($this->config, $options,             array('channel' => $channel, 'package' => $package),            PEAR_VALIDATE_UNINSTALLING);        $e = $depchecker->validatePackageUninstall($this);        PEAR::staticPopErrorHandling();        if (PEAR::isError($e)) {            if (!isset($options['ignore-errors'])) {                return $this->raiseError($e);            } else {                if (!isset($options['soft'])) {                    $this->log(0, 'WARNING: ' . $e->getMessage());                }            }        } elseif (is_array($e)) {            if (!isset($options['soft'])) {                $this->log(0, $e[0]);            }        }        $this->pkginfo = &$pkg;        // pretty much nothing happens if we are only registering the uninstall        if (empty($options['register-only'])) {            // {{{ Delete the files            $this->startFileTransaction();            PEAR::pushErrorHandling(PEAR_ERROR_RETURN);            if (PEAR::isError($err = $this->_deletePackageFiles($package, $channel))) {                PEAR::popErrorHandling();                $this->rollbackFileTransaction();                $this->configSet('default_channel', $savechannel);                if (!isset($options['ignore-errors'])) {                    return $this->raiseError($err);                } else {                    if (!isset($options['soft'])) {                        $this->log(0, 'WARNING: ' . $err->getMessage());                    }                }            } else {                PEAR::popErrorHandling();            }            if (!$this->commitFileTransaction()) {                $this->rollbackFileTransaction();                if (!isset($options['ignore-errors'])) {                    return $this->raiseError("uninstall failed");                } elseif (!isset($options['soft'])) {                    $this->log(0, 'WARNING: uninstall failed');                }            } else {                $this->startFileTransaction();                if ($dirtree = $pkg->getDirTree()) {                    // attempt to delete empty directories                    uksort($dirtree, array($this, '_sortDirs'));                    foreach($dirtree as $dir => $notused) {                        $this->addFileOperation('rmdir', array($dir));                    }                } else {                    $this->configSet('default_channel', $savechannel);                    return $this->_registry->deletePackage($package, $channel);                }                if (!$this->commitFileTransaction()) {                    $this->rollbackFileTransaction();                    if (!isset($options['ignore-errors'])) {                        return $this->raiseError("uninstall failed");                    } elseif (!isset($options['soft'])) {                        $this->log(0, 'WARNING: uninstall failed');                    }

⌨️ 快捷键说明

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