/**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $reg = new PEAR_Registry();
     if ($reg->getPackage("PEAR_Size") == null) {
         $this->markTestSkipped("PEAR_Size is not installed.");
     }
     $this->cli = new PEAR_Size_CLI();
     $this->genericResponse = "Usage: pearsize [OPTIONS] [PACKAGE]\nDisplay information on how much space an installed PEAR package required.\n\n  -a, --all            display information for all installed packages\n  -A, --allchannels    list packages from all channels, not just the default one\n  -c, --channel        specify which channel\n  -C, --csv            output results in CSV format (sizes are measured in bytes).\n  -h, --human-readable print sizes in human readable format (for example: 492 B 1KB 7MB)\n  -H, --si             likewise, but use powers of 1000 not 1024\n  -t, --type           specify what type of files are required for the report\n                       by default all types are assumed\n  -s, --summarise      display channel summary view\n  -S, --fsort          sort by file size\n  -v, --verbose        display more detailed information\n      --help           display this help and exit\n  -V, --version        output version information and exit\n  -X, --xml            output results in XML format\n  -0, --killzero       do not output zero values in verbose mode\n\nTypes:\nYou can specify a subset of roles/file-types to be listed in the report.\nThese roles are those as supported by the PEAR installer.\nThese are: data, doc, ext, php, script, src, test\n\nExamples:\n                \$ pearsize --all\n                \$ pearsize Console_Table\n                \$ pearsize -ttest,doc Console_Table\n                \$ pearsize --type=test,doc,php -h Console_Table Date_Holidays\n";
     $this->genericIntegratedResponse = "Usage: pear size [OPTIONS] [PACKAGE]\nDisplay information on how much space an installed PEAR package required.\n\n  -a, --all            display information for all installed packages\n  -A, --allchannels    list packages from all channels, not just the default one\n  -c, --channel        specify which channel\n  -C, --csv            output results in CSV format (sizes are measured in bytes).\n  -h, --human-readable print sizes in human readable format (for example: 492 B 1KB 7MB)\n  -H, --si             likewise, but use powers of 1000 not 1024\n  -t, --type           specify what type of files are required for the report\n                       by default all types are assumed\n  -s, --summarise      display channel summary view\n  -S, --fsort          sort by file size\n  -v, --verbose        display more detailed information\n      --help           display this help and exit\n  -V, --version        output version information and exit\n  -X, --xml            output results in XML format\n  -0, --killzero       do not output zero values in verbose mode\n\nTypes:\nYou can specify a subset of roles/file-types to be listed in the report.\nThese roles are those as supported by the PEAR installer.\nThese are: data, doc, ext, php, script, src, test\n\nExamples:\n                \$ pear size --all\n                \$ pear size Console_Table\n                \$ pear size -ttest,doc Console_Table\n                \$ pear size --type=test,doc,php -h Console_Table Date_Holidays\n";
 }
 /**
  * Initialize Task.
  * This method includes any necessary PHPUnit2 libraries and triggers
  * appropriate error if they cannot be found.  This is not done in header
  * because we may want this class to be loaded w/o triggering an error.
  */
 function init()
 {
     if (version_compare(PHP_VERSION, '5.0.3') < 0) {
         throw new BuildException("PHPUnit2Task requires PHP version >= 5.0.3.", $this->getLocation());
     }
     /**
      * Ugly hack to get PHPUnit version number
      */
     $config = new PEAR_Config();
     $registry = new PEAR_Registry($config->get('php_dir'));
     $pkg_info = $registry->_packageInfo("PHPUnit", null, "pear.phpunit.de");
     if ($pkg_info != NULL) {
         if (version_compare($pkg_info['version']['api'], "3.0.0") >= 0) {
             PHPUnitUtil::$installedVersion = 3;
         } else {
             PHPUnitUtil::$installedVersion = 2;
         }
     } else {
         /**
          * Try to find PHPUnit2
          */
         require_once 'PHPUnit2/Util/Filter.php';
         if (!class_exists('PHPUnit2_Util_Filter')) {
             throw new BuildException("PHPUnit2Task depends on PEAR PHPUnit2 package being installed.", $this->getLocation());
         }
         PHPUnitUtil::$installedVersion = 2;
     }
     // other dependencies that should only be loaded when class is actually used.
     require_once 'phing/tasks/ext/phpunit/PHPUnitTestRunner.php';
     require_once 'phing/tasks/ext/phpunit/BatchTest.php';
     require_once 'phing/tasks/ext/phpunit/FormatterElement.php';
     //require_once 'phing/tasks/ext/phpunit/SummaryPHPUnit2ResultFormatter.php';
     // add some defaults to the PHPUnit filter
     if (PHPUnitUtil::$installedVersion == 3) {
         require_once 'PHPUnit/Util/Filter.php';
         // point PHPUnit_MAIN_METHOD define to non-existing method
         define('PHPUnit_MAIN_METHOD', 'PHPUnitTask::undefined');
         PHPUnit_Util_Filter::addFileToFilter('PHPUnitTask.php', 'PHING');
         PHPUnit_Util_Filter::addFileToFilter('PHPUnitTestRunner.php', 'PHING');
         PHPUnit_Util_Filter::addFileToFilter('phing/Task.php', 'PHING');
         PHPUnit_Util_Filter::addFileToFilter('phing/Target.php', 'PHING');
         PHPUnit_Util_Filter::addFileToFilter('phing/Project.php', 'PHING');
         PHPUnit_Util_Filter::addFileToFilter('phing/Phing.php', 'PHING');
         PHPUnit_Util_Filter::addFileToFilter('phing.php', 'PHING');
     } else {
         require_once 'PHPUnit2/Util/Filter.php';
         PHPUnit2_Util_Filter::addFileToFilter('PHPUnitTask.php');
         PHPUnit2_Util_Filter::addFileToFilter('PHPUnitTestRunner.php');
         PHPUnit2_Util_Filter::addFileToFilter('phing/Task.php');
         PHPUnit2_Util_Filter::addFileToFilter('phing/Target.php');
         PHPUnit2_Util_Filter::addFileToFilter('phing/Project.php');
         PHPUnit2_Util_Filter::addFileToFilter('phing/Phing.php');
         PHPUnit2_Util_Filter::addFileToFilter('phing.php');
     }
 }
Beispiel #3
0
 /**
  * Return PEAR packages, versions, etc.
  *
  * @see PEAR_Registry, PEAR_Registry::listPackages()
  * @return array
  */
 public function packages()
 {
     $reg = new PEAR_Registry();
     $packages = $reg->listPackages();
     $p = array();
     foreach ($packages as $package) {
         $pkg = $reg->getPackage($package);
         $p[] = array('package' => $pkg->getName(), 'released' => $pkg->getDate(), 'version' => $pkg->getVersion(), 'state' => $pkg->getState());
     }
     return array('packages' => $p);
 }
 /**
  * Rebuild the dependency DB by reading registry entries.
  * @return true|PEAR_Error
  */
 function rebuildDB()
 {
     $depdb = array('_version' => $this->_version);
     if (!$this->hasWriteAccess()) {
         // allow startup for read-only with older Registry
         return $depdb;
     }
     $packages = $this->_registry->listAllPackages();
     if (PEAR::isError($packages)) {
         return $packages;
     }
     foreach ($packages as $channel => $ps) {
         foreach ($ps as $package) {
             $package = $this->_registry->getPackage($package, $channel);
             if (PEAR::isError($package)) {
                 return $package;
             }
             $this->_setPackageDeps($depdb, $package);
         }
     }
     $error = $this->_writeDepDB($depdb);
     if (PEAR::isError($error)) {
         return $error;
     }
     $this->_cache = $depdb;
     return true;
 }
function pear_prerequisutes()
{
    $exists = include_exists('PEAR' . DIRECTORY_SEPARATOR . 'Registry.php');
    if ($exists['result']) {
        require_once 'PEAR/Registry.php';
        $reg = new PEAR_Registry();
        $packages = $reg->listPackages();
        if (in_array('http_request2', $packages)) {
            $results = array('pear' => "Pass", 'http_request2' => "Pass", 'path' => $exists['path']);
        } else {
            $results = array('pear' => "Pass", 'http_request2' => "Fail", 'path' => $exists['path']);
        }
    } else {
        $results = array('pear' => "Fail", 'http_request2' => "Fail", 'path' => $exists['path']);
    }
    return $results;
}
 /**
  * (non-PHPdoc)
  * @see lib/Faett/Core/Interfaces/Faett_Core_Interfaces_Service#packageInfo($packageName, $channel)
  */
 public function packageInfo($packageName, $channel)
 {
     // store the default channel
     $savechannel = $this->_config->get('default_channel');
     // check if the cannel already exists
     if ($this->_registry->channelExists($channel)) {
         $this->_config->set('default_channel', $channel);
     } else {
         // throw a new exception
         throw Faett_Core_Exceptions_UnknownChannelException::create('Channel ' . $channel . ' does not exist');
     }
     // load the channel from the registry
     $chan = $this->_registry->getChannel($channel);
     // initialize a REST command for checking the channel's state
     $cmd = new PEAR_Command_Remote($this->_ui, $this->_config);
     if (PEAR::isError($e = $cmd->_checkChannelForStatus($channel, $chan))) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_UnknownChannelStateException::create($e->getMessage());
     }
     // get the channel's base URL
     $base = $chan->getBaseURL('REST1.0', $this->_config->get('preferred_mirror'));
     // check if the channel's server is REST enabled
     $restSupport = $chan->supportsREST($this->_config->get('preferred_mirror'));
     // check if the channel is REST enabled
     if ($restSupport && $base) {
         // load the channel data and the package information
         $rest = $this->_config->getREST('1.0', array());
         $info = $rest->packageInfo($base, $packageName);
     } else {
         $r = $this->_config->getRemote();
         $info = $r->call('package.info', $packageName);
     }
     // check if the package information was loaded successfully
     if (PEAR::isError($info)) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_PackageInfoException::create($info->getMessage());
     }
     // if no packge name was found log an error message
     if (!isset($info['name'])) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_PackageInfoException::create('Can\'t find a package name');
     }
     // check if the package is installed
     $installed = $this->_registry->packageInfo($info['name'], null, $channel);
     // if yes, set the information
     $info['installed'] = $installed['version'] ? $installed['version'] : '';
     if (is_array($info['installed'])) {
         $info['installed'] = $info['installed']['release'];
     }
     // return the package information
     return $info;
 }
Beispiel #7
0
 /**
  * @param array output of package.getDownloadURL
  * @param string|array|object information for detecting packages to be downloaded, and
  *                            for errors
  * @param array name information of the package
  * @param array|null packages to be downloaded
  * @access private
  */
 function _analyzeDownloadURL($info, $param, $pname, $params = null)
 {
     if (!is_string($param) && PEAR_Downloader_Package::willDownload($param, $params)) {
         return false;
     }
     if (!$info) {
         if (!is_string($param)) {
             $saveparam = ", cannot download \"{$param}\"";
         } else {
             $saveparam = '';
         }
         // no releases exist
         return PEAR::raiseError('No releases for package "' . $this->_registry->parsedPackageNameToString($pname, true) . '" exist' . $saveparam);
     }
     if (strtolower($info['info']->getChannel()) != strtolower($pname['channel'])) {
         $err = false;
         if ($pname['channel'] == 'pear.php.net') {
             if ($info['info']->getChannel() != 'pecl.php.net') {
                 $err = true;
             }
         } else {
             $err = true;
         }
         if ($err) {
             return PEAR::raiseError('SECURITY ERROR: package in channel "' . $pname['channel'] . '" retrieved another channel\'s name for download! ("' . $info['info']->getChannel() . '")');
         }
     }
     if (!isset($info['url'])) {
         // releases exist, but we failed to get any
         if (isset($this->_downloader->_options['force'])) {
             if (isset($pname['version'])) {
                 $vs = ', version "' . $pname['version'] . '"';
             } elseif (isset($pname['state'])) {
                 $vs = ', stability "' . $pname['state'] . '"';
             } else {
                 $vs = ' within preferred state ' . $this->_config->get('preferred_state') . '"';
             }
             if (!isset($options['soft'])) {
                 $this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] . '/' . $pname['package'] . $vs . ', will instead download version ' . $info['version'] . ', stability "' . $info['info']->getState() . '"');
             }
             // download the latest release
             return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
         } else {
             // construct helpful error message
             if (isset($pname['version'])) {
                 $vs = ', version "' . $pname['version'] . '"';
             } elseif (isset($pname['state'])) {
                 $vs = ', stability "' . $pname['state'] . '"';
             } else {
                 $vs = ' within preferred state ' . $this->_downloader->config->get('preferred_state') . '"';
             }
             $err = PEAR::raiseError('Failed to download ' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package']), true) . $vs . ', latest release is version ' . $info['version'] . ', stability "' . $info['info']->getState() . '", use "' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package'], 'version' => $info['version'])) . '" to install');
             return $err;
         }
     }
     return $info;
 }
Beispiel #8
0
 /**
  * Check php package exists and has corresponding version
  *
  * Returns 0 on success, non-zero otherwise
  *
  * @return int
  */
 public function check()
 {
     require_once 'PEAR/Registry.php';
     $registry = new PEAR_Registry();
     $installedVersion = $registry->packageInfo($this->name, 'version', $this->channel);
     if (is_null($installedVersion)) {
         $this->log('Package "' . $this->name . '" from "' . $this->channel . '" is required', Project::MSG_ERR);
         return 1;
     }
     if ($this->min && version_compare($installedVersion, $this->min, '<')) {
         $this->log('Package "' . $this->name . '" from "' . $this->channel . '" is ' . $installedVersion . '. >= ' . $this->min . ' is required', Project::MSG_ERR);
         return 1;
     }
     if ($this->max && version_compare($installedVersion, $this->max, '>')) {
         $this->log('Package "' . $this->name . '" from "' . $this->channel . '" is ' . $installedVersion . '. <= ' . $this->max . ' is required', Project::MSG_ERR);
         return 1;
     }
     $this->log('Package "' . $this->name . '" ' . $installedVersion . ' is passed', Project::MSG_VERBOSE);
     return 0;
 }
Beispiel #9
0
 /**
  * Installation of source package has failed, attempt to download and install the
  * binary version of this package.
  * @param PEAR_Installer
  */
 function installBinary(&$installer)
 {
     if ($this->getPackageType() == 'extsrc') {
         if (!is_array($installer->getInstallPackages())) {
             return false;
         }
         foreach ($installer->getInstallPackages() as $p) {
             if ($p->isExtension($this->_packageInfo['providesextension'])) {
                 if ($p->getPackageType() != 'extsrc') {
                     return false;
                     // the user probably downloaded it separately
                 }
             }
         }
         if (isset($this->_packageInfo['extsrcrelease']['binarypackage'])) {
             $installer->log(0, 'Attempting to download binary version of extension "' . $this->_packageInfo['providesextension'] . '"');
             $params = $this->_packageInfo['extsrcrelease']['binarypackage'];
             if (!is_array($params) || !isset($params[0])) {
                 $params = array($params);
             }
             if (isset($this->_packageInfo['channel'])) {
                 foreach ($params as $i => $param) {
                     $params[$i] = array('channel' => $this->_packageInfo['channel'], 'package' => $param);
                 }
             }
             $dl =& $this->getPEARDownloader($installer->ui, $installer->getOptions(), $installer->config);
             $verbose = $dl->config->get('verbose');
             $dl->config->set('verbose', -1);
             foreach ($params as $param) {
                 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
                 $ret = $dl->download(array($param));
                 PEAR::popErrorHandling();
                 if (is_array($ret) && count($ret)) {
                     break;
                 }
             }
             $dl->config->set('verbose', $verbose);
             if (is_array($ret)) {
                 if (count($ret) == 1) {
                     $pf = $ret[0]->getPackageFile();
                     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
                     $ret = $installer->install($ret[0]);
                     PEAR::popErrorHandling();
                     if (is_array($ret)) {
                         $installer->log(0, 'Download and install of binary extension "' . $this->_registry->parsedPackageNameToString(array('channel' => $pf->getChannel(), 'package' => $pf->getPackage()), true) . '" successful');
                         return $ret;
                     }
                     $installer->log(0, 'Download and install of binary extension "' . $this->_registry->parsedPackageNameToString(array('channel' => $pf->getChannel(), 'package' => $pf->getPackage()), true) . '" failed');
                 }
             }
         }
     }
     return false;
 }
 /**
  * @deprecated in favor of _getPackageDownloadUrl
  */
 function getPackageDownloadUrl($package, $version = null, $channel = false)
 {
     if ($version) {
         $package .= "-{$version}";
     }
     if ($this === null || $this->_registry === null) {
         $package = "http://pear.php.net/get/{$package}";
     } else {
         $chan = $this->_registry->getChannel($channel);
         $package = "http://" . $chan->getServer() . "/get/{$package}";
     }
     if (!extension_loaded("zlib")) {
         $package .= '?uncompress=yes';
     }
     return $package;
 }
Beispiel #11
0
 /**
  * Returns a list of components that $componentName depends on.
  *
  * If $componentName is left empty, all installed components are returned.
  *
  * The returned array has as keys the component names, and as values the
  * version of the components.
  *
  * @return array(string=>string).
  */
 public function getComponentDependencies($componentName = 'ezcomponents')
 {
     @($packageInfo = $this->registry->packageInfo($componentName, 'dependencies', 'components.ez.no'));
     if (isset($packageInfo['required']['package'])) {
         $deps = array();
         if (isset($packageInfo['required']['package']['name'])) {
             $deps[$packageInfo['required']['package']['name']] = $packageInfo['required']['package']['min'];
         } else {
             foreach ($packageInfo['required']['package'] as $package) {
                 $deps[$package['name']] = $package['min'];
             }
         }
         return $deps;
     }
     return array();
 }
Beispiel #12
0
 /**
  * Rebuild the dependency DB by reading registry entries.
  * @return true|PEAR_Error
  */
 function rebuildDB()
 {
     $depdb = array('_version' => $this->_version);
     $packages = $this->_registry->listAllPackages();
     foreach ($packages as $channel => $ps) {
         foreach ($ps as $package) {
             $package = $this->_registry->getPackage($package, $channel);
             $this->_setPackageDeps($depdb, $package);
         }
     }
     $error = $this->_writeDepDB($depdb);
     if (PEAR::isError($error)) {
         return $error;
     }
     $this->_cache = $depdb;
     return true;
 }
Beispiel #13
0
 function doInstall($command, $options, $params)
 {
     if (empty($this->installer)) {
         $this->installer =& new PEAR_Installer($this->ui);
     }
     if ($command == 'upgrade') {
         $options[$command] = true;
     }
     if ($command == 'upgrade-all') {
         include_once "PEAR/Remote.php";
         $options['upgrade'] = true;
         $remote = new PEAR_Remote($this->config);
         $state = $this->config->get('preferred_state');
         if (empty($state) || $state == 'any') {
             $latest = $remote->call("package.listLatestReleases");
         } else {
             $latest = $remote->call("package.listLatestReleases", $state);
         }
         if (PEAR::isError($latest)) {
             return $latest;
         }
         $reg = new PEAR_Registry($this->config->get('php_dir'));
         $installed = array_flip($reg->listPackages());
         $params = array();
         foreach ($latest as $package => $info) {
             if (!isset($installed[$package])) {
                 // skip packages we don't have installed
                 continue;
             }
             $inst_version = $reg->packageInfo($package, 'version');
             if (version_compare("{$info['version']}", "{$inst_version}", "le")) {
                 // installed version is up-to-date
                 continue;
             }
             $params[] = $package;
             $this->ui->outputData("will upgrade {$package}", $command);
         }
     }
     foreach ($params as $pkg) {
         $bn = basename($pkg);
         $info = $this->installer->install($pkg, $options, $this->config);
         if (is_array($info)) {
             if ($this->config->get('verbose') > 0) {
                 $label = "{$info['package']} {$info['version']}";
                 $out = array('data' => "{$command} ok: {$label}");
                 if (isset($info['release_warnings'])) {
                     $out['release_warnings'] = $info['release_warnings'];
                 }
                 $this->ui->outputData($out, $command);
             }
         } else {
             return $this->raiseError("{$command} failed");
         }
     }
     return true;
 }
Beispiel #14
0
 /**
  * @param array output of package.getDownloadURL
  * @param string|array|object information for detecting packages to be downloaded, and
  *                            for errors
  * @param array name information of the package
  * @param array|null packages to be downloaded
  * @param bool is this an optional dependency?
  * @access private
  */
 function _analyzeDownloadURL($info, $param, $pname, $params = null, $optional = false)
 {
     if (!is_string($param) && PEAR_Downloader_Package::willDownload($param, $params)) {
         return false;
     }
     if (!$info) {
         if (!is_string($param)) {
             $saveparam = ", cannot download \"{$param}\"";
         } else {
             $saveparam = '';
         }
         // no releases exist
         return PEAR::raiseError('No releases for package "' . $this->_registry->parsedPackageNameToString($pname, true) . '" exist' . $saveparam);
     }
     if (strtolower($info['info']->getChannel()) != strtolower($pname['channel'])) {
         $err = false;
         if ($pname['channel'] == 'pecl.php.net') {
             if ($info['info']->getChannel() != 'pear.php.net') {
                 $err = true;
             }
         } elseif ($info['info']->getChannel() == 'pecl.php.net') {
             if ($pname['channel'] != 'pear.php.net') {
                 $err = true;
             }
         } else {
             $err = true;
         }
         if ($err) {
             return PEAR::raiseError('SECURITY ERROR: package in channel "' . $pname['channel'] . '" retrieved another channel\'s name for download! ("' . $info['info']->getChannel() . '")');
         }
     }
     if (!isset($info['url'])) {
         $instead = ', will instead download version ' . $info['version'] . ', stability "' . $info['info']->getState() . '"';
         // releases exist, but we failed to get any
         if (isset($this->_downloader->_options['force'])) {
             if (isset($pname['version'])) {
                 $vs = ', version "' . $pname['version'] . '"';
             } elseif (isset($pname['state'])) {
                 $vs = ', stability "' . $pname['state'] . '"';
             } elseif ($param == 'dependency') {
                 if (!class_exists('PEAR_Common')) {
                     require_once 'PEAR/Common.php';
                 }
                 if (!in_array($info['info']->getState(), PEAR_Common::betterStates($this->_config->get('preferred_state'), true))) {
                     if ($optional) {
                         // don't spit out confusing error message
                         return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
                     }
                     $vs = ' within preferred state "' . $this->_config->get('preferred_state') . '"';
                 } else {
                     if (!class_exists('PEAR_Dependency2')) {
                         require_once 'PEAR/Dependency2.php';
                     }
                     if ($optional) {
                         // don't spit out confusing error message
                         return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
                     }
                     $vs = PEAR_Dependency2::_getExtraString($pname);
                     $instead = '';
                 }
             } else {
                 $vs = ' within preferred state "' . $this->_config->get('preferred_state') . '"';
             }
             if (!isset($options['soft'])) {
                 $this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] . '/' . $pname['package'] . $vs . $instead);
             }
             // download the latest release
             return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
         } else {
             // construct helpful error message
             if (isset($pname['version'])) {
                 $vs = ', version "' . $pname['version'] . '"';
             } elseif (isset($pname['state'])) {
                 $vs = ', stability "' . $pname['state'] . '"';
             } elseif ($param == 'dependency') {
                 if (!class_exists('PEAR_Common')) {
                     require_once 'PEAR/Common.php';
                 }
                 if (!in_array($info['info']->getState(), PEAR_Common::betterStates($this->_config->get('preferred_state'), true))) {
                     if ($optional) {
                         // don't spit out confusing error message, and don't die on
                         // optional dep failure!
                         return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
                     }
                     $vs = ' within preferred state "' . $this->_config->get('preferred_state') . '"';
                 } else {
                     if (!class_exists('PEAR_Dependency2')) {
                         require_once 'PEAR/Dependency2.php';
                     }
                     if ($optional) {
                         // don't spit out confusing error message, and don't die on
                         // optional dep failure!
                         return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
                     }
                     $vs = PEAR_Dependency2::_getExtraString($pname);
                 }
             } else {
                 $vs = ' within preferred state "' . $this->_downloader->config->get('preferred_state') . '"';
             }
             $options = $this->_downloader->getOptions();
             // this is only set by the "download-all" command
             if (isset($options['ignorepreferred_state'])) {
                 $err = PEAR::raiseError('Failed to download ' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package']), true) . $vs . ', latest release is version ' . $info['version'] . ', stability "' . $info['info']->getState() . '", use "' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package'], 'version' => $info['version'])) . '" to install', PEAR_DOWNLOADER_PACKAGE_STATE);
                 return $err;
             }
             $err = PEAR::raiseError('Failed to download ' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package']), true) . $vs . ', latest release is version ' . $info['version'] . ', stability "' . $info['info']->getState() . '", use "' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package'], 'version' => $info['version'])) . '" to install');
             return $err;
         }
     }
     return $info;
 }
Beispiel #15
0
include_once "PEAR/Registry.php";
if (WEBINSTALLER || isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'local') {
    $config =& PEAR_Config::singleton($prefix . "/pear.conf", '');
} else {
    $config =& PEAR_Config::singleton();
}
$config->set('preferred_state', 'stable');
foreach ($config_vars as $var) {
    if (isset(${$var}) && ${$var} != '') {
        $config->set($var, ${$var});
    }
}
$config->set('download_dir', $temp_dir . '/download');
$config->set('temp_dir', $temp_dir);
$config->store();
$registry = new PEAR_Registry($php_dir);
PEAR_Command::setFrontendType('CLI');
PEAR::staticPushErrorHandling(PEAR_ERROR_DIE);
//fail silently
$ch_cmd =& PEAR_Command::factory('update-channels', $config);
$ch_cmd->run('update-channels', $options, array());
PEAR::staticPopErrorHandling();
// reset error handling
unset($ch_cmd);
print "\n" . 'Installing selected packages..................' . "\n";
displayHTMLProgress($progress = 45);
$install =& PEAR_Command::factory('install', $config);
foreach ($to_install as $pkg) {
    $pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
    if (in_array($pkg, $installer_packages)) {
        $options = array('nodeps' => true);
 function doInstall($command, $options, $params)
 {
     if (!class_exists('PEAR_PackageFile')) {
         require_once 'PEAR/PackageFile.php';
     }
     if (empty($this->installer)) {
         $this->installer =& $this->getInstaller($this->ui);
     }
     if ($command == 'upgrade' || $command == 'upgrade-all') {
         $options['upgrade'] = true;
     } else {
         $packages = $params;
     }
     if (isset($options['installroot']) && isset($options['packagingroot'])) {
         return $this->raiseError('ERROR: cannot use both --installroot and --packagingroot');
     }
     $reg =& $this->config->getRegistry();
     $instreg =& $reg;
     // instreg used to check if package is installed
     if (isset($options['packagingroot']) && !isset($options['upgrade'])) {
         $packrootphp_dir = $this->installer->_prependPath($this->config->get('php_dir', null, 'pear.php.net'), $options['packagingroot']);
         $instreg = new PEAR_Registry($packrootphp_dir);
         // other instreg!
         if ($this->config->get('verbose') > 2) {
             $this->ui->outputData('using package root: ' . $options['packagingroot']);
         }
     }
     $abstractpackages = array();
     $otherpackages = array();
     // parse params
     PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
     foreach ($params as $param) {
         if (strpos($param, 'http://') === 0) {
             $otherpackages[] = $param;
             continue;
         }
         if (strpos($param, 'channel://') === false && @file_exists($param)) {
             if (isset($options['force'])) {
                 $otherpackages[] = $param;
                 continue;
             }
             $pkg = new PEAR_PackageFile($this->config);
             $pf = $pkg->fromAnyFile($param, PEAR_VALIDATE_DOWNLOADING);
             if (PEAR::isError($pf)) {
                 $otherpackages[] = $param;
                 continue;
             }
             if ($reg->packageExists($pf->getPackage(), $pf->getChannel()) && version_compare($pf->getVersion(), $reg->packageInfo($pf->getPackage(), 'version', $pf->getChannel()), '<=')) {
                 if ($this->config->get('verbose')) {
                     $this->ui->outputData('Ignoring installed package ' . $reg->parsedPackageNameToString(array('package' => $pf->getPackage(), 'channel' => $pf->getChannel()), true));
                 }
                 continue;
             }
             $otherpackages[] = $param;
             continue;
         }
         $e = $reg->parsePackageName($param, $this->config->get('default_channel'));
         if (PEAR::isError($e)) {
             $otherpackages[] = $param;
         } else {
             $abstractpackages[] = $e;
         }
     }
     PEAR::staticPopErrorHandling();
     // if there are any local package .tgz or remote static url, we can't
     // filter.  The filter only works for abstract packages
     if (count($abstractpackages) && !isset($options['force'])) {
         // when not being forced, only do necessary upgrades/installs
         if (isset($options['upgrade'])) {
             $abstractpackages = $this->_filterUptodatePackages($abstractpackages, $command);
         } else {
             foreach ($abstractpackages as $i => $package) {
                 if (isset($package['group'])) {
                     // do not filter out install groups
                     continue;
                 }
                 if ($instreg->packageExists($package['package'], $package['channel'])) {
                     if ($this->config->get('verbose')) {
                         $this->ui->outputData('Ignoring installed package ' . $reg->parsedPackageNameToString($package, true));
                     }
                     unset($abstractpackages[$i]);
                 }
             }
         }
         $abstractpackages = array_map(array($reg, 'parsedPackageNameToString'), $abstractpackages);
     } elseif (count($abstractpackages)) {
         $abstractpackages = array_map(array($reg, 'parsedPackageNameToString'), $abstractpackages);
     }
     $packages = array_merge($abstractpackages, $otherpackages);
     if (!count($packages)) {
         $this->ui->outputData('Nothing to ' . $command);
         return true;
     }
     $this->downloader =& $this->getDownloader($this->ui, $options, $this->config);
     $errors = array();
     $binaries = array();
     $downloaded = array();
     $downloaded =& $this->downloader->download($packages);
     if (PEAR::isError($downloaded)) {
         return $this->raiseError($downloaded);
     }
     $errors = $this->downloader->getErrorMsgs();
     if (count($errors)) {
         $err = array();
         $err['data'] = array();
         foreach ($errors as $error) {
             $err['data'][] = array($error);
         }
         $err['headline'] = 'Install Errors';
         $this->ui->outputData($err);
         if (!count($downloaded)) {
             return $this->raiseError("{$command} failed");
         }
     }
     $data = array('headline' => 'Packages that would be Installed');
     if (isset($options['pretend'])) {
         foreach ($downloaded as $package) {
             $data['data'][] = array($reg->parsedPackageNameToString($package->getParsedPackage()));
         }
         $this->ui->outputData($data, 'pretend');
         return true;
     }
     $this->installer->setOptions($options);
     $this->installer->sortPackagesForInstall($downloaded);
     if (PEAR::isError($err = $this->installer->setDownloadedPackages($downloaded))) {
         $this->raiseError($err->getMessage());
         return true;
     }
     $extrainfo = array();
     $binaries = array();
     foreach ($downloaded as $param) {
         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
         $info = $this->installer->install($param, $options);
         PEAR::staticPopErrorHandling();
         if (PEAR::isError($info)) {
             $oldinfo = $info;
             $pkg =& $param->getPackageFile();
             if ($info->getCode() != PEAR_INSTALLER_NOBINARY) {
                 if (!($info = $pkg->installBinary($this->installer))) {
                     $this->ui->outputData('ERROR: ' . $oldinfo->getMessage());
                     continue;
                 }
                 // we just installed a different package than requested,
                 // let's change the param and info so that the rest of this works
                 $param = $info[0];
                 $info = $info[1];
             }
         }
         if (is_array($info)) {
             if ($param->getPackageType() == 'extsrc' || $param->getPackageType() == 'extbin' || $param->getPackageType() == 'zendextsrc' || $param->getPackageType() == 'zendextbin') {
                 $pkg =& $param->getPackageFile();
                 if ($instbin = $pkg->getInstalledBinary()) {
                     $instpkg =& $instreg->getPackage($instbin, $pkg->getChannel());
                 } else {
                     $instpkg =& $instreg->getPackage($pkg->getPackage(), $pkg->getChannel());
                 }
                 foreach ($instpkg->getFilelist() as $name => $atts) {
                     $pinfo = pathinfo($atts['installed_as']);
                     if (!isset($pinfo['extension']) || in_array($pinfo['extension'], array('c', 'h'))) {
                         continue;
                         // make sure we don't match php_blah.h
                     }
                     if (strpos($pinfo['basename'], 'php_') === 0 && $pinfo['extension'] == 'dll' || $pinfo['extension'] == 'so' || $pinfo['extension'] == 'sl') {
                         $binaries[] = array($atts['installed_as'], $pinfo);
                         break;
                     }
                 }
                 if (count($binaries)) {
                     foreach ($binaries as $pinfo) {
                         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
                         $ret = $this->enableExtension(array($pinfo[0]), $param->getPackageType());
                         PEAR::staticPopErrorHandling();
                         if (PEAR::isError($ret)) {
                             $extrainfo[] = $ret->getMessage();
                             if ($param->getPackageType() == 'extsrc' || $param->getPackageType() == 'extbin') {
                                 $exttype = 'extension';
                             } else {
                                 ob_start();
                                 phpinfo(INFO_GENERAL);
                                 $info = ob_get_contents();
                                 ob_end_clean();
                                 $debug = function_exists('leak') ? '_debug' : '';
                                 $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
                                 $exttype = 'zend_extension' . $debug . $ts;
                             }
                             $extrainfo[] = 'You should add "' . $exttype . '=' . $pinfo[1]['basename'] . '" to php.ini';
                         } else {
                             $extrainfo[] = 'Extension ' . $instpkg->getProvidesExtension() . ' enabled in php.ini';
                         }
                     }
                 }
             }
             if ($this->config->get('verbose') > 0) {
                 $channel = $param->getChannel();
                 $label = $reg->parsedPackageNameToString(array('channel' => $channel, 'package' => $param->getPackage(), 'version' => $param->getVersion()));
                 $out = array('data' => "{$command} ok: {$label}");
                 if (isset($info['release_warnings'])) {
                     $out['release_warnings'] = $info['release_warnings'];
                 }
                 $this->ui->outputData($out, $command);
                 if (!isset($options['register-only']) && !isset($options['offline'])) {
                     if ($this->config->isDefinedLayer('ftp')) {
                         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
                         $info = $this->installer->ftpInstall($param);
                         PEAR::staticPopErrorHandling();
                         if (PEAR::isError($info)) {
                             $this->ui->outputData($info->getMessage());
                             $this->ui->outputData("remote install failed: {$label}");
                         } else {
                             $this->ui->outputData("remote install ok: {$label}");
                         }
                     }
                 }
             }
             $deps = $param->getDeps();
             if ($deps) {
                 if (isset($deps['group'])) {
                     $groups = $deps['group'];
                     if (!isset($groups[0])) {
                         $groups = array($groups);
                     }
                     foreach ($groups as $group) {
                         if ($group['attribs']['name'] == 'default') {
                             // default group is always installed, unless the user
                             // explicitly chooses to install another group
                             continue;
                         }
                         $extrainfo[] = $param->getPackage() . ': Optional feature ' . $group['attribs']['name'] . ' available (' . $group['attribs']['hint'] . ')';
                     }
                     $extrainfo[] = $param->getPackage() . ': To install optional features use "pear install ' . $reg->parsedPackageNameToString(array('package' => $param->getPackage(), 'channel' => $param->getChannel()), true) . '#featurename"';
                 }
             }
             $pkg =& $instreg->getPackage($param->getPackage(), $param->getChannel());
             // $pkg may be NULL if install is a 'fake' install via --packagingroot
             if (is_object($pkg)) {
                 $pkg->setConfig($this->config);
                 if ($list = $pkg->listPostinstallScripts()) {
                     $pn = $reg->parsedPackageNameToString(array('channel' => $param->getChannel(), 'package' => $param->getPackage()), true);
                     $extrainfo[] = $pn . ' has post-install scripts:';
                     foreach ($list as $file) {
                         $extrainfo[] = $file;
                     }
                     $extrainfo[] = $param->getPackage() . ': Use "pear run-scripts ' . $pn . '" to finish setup.';
                     $extrainfo[] = 'DO NOT RUN SCRIPTS FROM UNTRUSTED SOURCES';
                 }
             }
         } else {
             return $this->raiseError("{$command} failed");
         }
     }
     if (count($extrainfo)) {
         foreach ($extrainfo as $info) {
             $this->ui->outputData($info);
         }
     }
     return true;
 }
Beispiel #17
0
 /**
  * Process a dependency, download if necessary
  * @param array dependency information from PEAR_Remote call
  * @param array packages that will be installed in this iteration
  * @return false|string|PEAR_Error
  * @access private
  * @todo Add test for relation 'lt'/'le' -> make sure that the dependency requested is
  *       in fact lower than the required value.  This will be very important for BC dependencies
  */
 function _processDependency($package, $info, $mywillinstall)
 {
     $state = $this->_preferredState;
     if (!isset($this->_options['alldeps']) && isset($info['optional']) && $info['optional'] == 'yes') {
         // skip optional deps
         $this->log(0, "skipping Package '{$package}' optional dependency '{$info['name']}'");
         return false;
     }
     // {{{ get releases
     $releases = $this->_remote->call('package.info', $info['name'], 'releases', true);
     if (PEAR::isError($releases)) {
         return $releases;
     }
     if (!count($releases)) {
         if (!isset($this->_installed[strtolower($info['name'])])) {
             $this->pushError("Package '{$package}' dependency '{$info['name']}' " . "has no releases");
         }
         return false;
     }
     $found = false;
     $save = $releases;
     while (count($releases) && !$found) {
         if (!empty($state) && $state != 'any') {
             list($release_version, $release) = each($releases);
             if ($state != $release['state'] && !in_array($release['state'], $this->betterStates($state))) {
                 // drop this release - it ain't stable enough
                 array_shift($releases);
             } else {
                 $found = true;
             }
         } else {
             $found = true;
         }
     }
     if (!count($releases) && !$found) {
         $get = array();
         foreach ($save as $release) {
             $get = array_merge($get, $this->betterStates($release['state'], true));
         }
         $savestate = array_shift($get);
         $this->pushError("Release for '{$package}' dependency '{$info['name']}' " . "has state '{$savestate}', requires '{$state}'");
         return false;
     }
     if (in_array(strtolower($info['name']), $this->_toDownload) || isset($mywillinstall[strtolower($info['name'])])) {
         // skip upgrade check for packages we will install
         return false;
     }
     if (!isset($this->_installed[strtolower($info['name'])])) {
         // check to see if we can install the specific version required
         if ($info['rel'] == 'eq') {
             return $info['name'] . '-' . $info['version'];
         }
         // skip upgrade check for packages we don't have installed
         return $info['name'];
     }
     // }}}
     // {{{ see if a dependency must be upgraded
     $inst_version = $this->_registry->packageInfo($info['name'], 'version');
     if (!isset($info['version'])) {
         // this is a rel='has' dependency, check against latest
         if (version_compare($release_version, $inst_version, 'le')) {
             return false;
         } else {
             return $info['name'];
         }
     }
     if (version_compare($info['version'], $inst_version, 'le')) {
         // installed version is up-to-date
         return false;
     }
     return $info['name'];
 }
Beispiel #18
0
<?php

# $NetBSD: pear_plist.php,v 1.9 2015/12/11 16:16:48 taca Exp $
# Parses package XML file and outputs appropriate PLIST
include_once "PEAR/Registry.php";
include_once "PEAR/PackageFile.php";
$PREFIX = getenv('PREFIX');
$PEAR_LIB = getenv('PEAR_LIB');
$WRKSRC = getenv('WRKSRC');
if (!($DESTDIR = getenv('DESTDIR'))) {
    $DESTDIR = '';
}
$config = PEAR_Config::singleton();
$package = new PEAR_PackageFile($config);
$info = $package->fromAnyFile("{$WRKSRC}/package.xml", PEAR_VALIDATE_INSTALLING);
$pkg = $info->getName();
$channel = $info->getChannel();
$registry = new PEAR_Registry($DESTDIR . $PREFIX . "/" . $PEAR_LIB);
$flist = $registry->packageInfo($pkg, 'filelist', $channel);
$regfile = $PEAR_LIB . '/.registry/.channel.' . $channel . '/' . strtolower($pkg) . '.reg';
if (!file_exists($DESTDIR . $PREFIX . '/' . $regfile)) {
    $regfile = $PEAR_LIB . '/.registry/' . strtolower($pkg) . '.reg';
}
echo "{$regfile}\n";
# output list of package files, in same order as specified in package
foreach ($flist as $f) {
    echo str_replace($PREFIX . '/', '', $f['installed_as']) . "\n";
}
 function doList($command, $options, $params)
 {
     $reg = new PEAR_Registry($this->config->get('php_dir'));
     if (sizeof($params) == 0) {
         $installed = $reg->packageInfo();
         usort($installed, array(&$this, '_sortinfo'));
         $i = $j = 0;
         $data = array('caption' => 'Installed packages:', 'border' => true, 'headline' => array('Package', 'Version', 'State'));
         foreach ($installed as $package) {
             $data['data'][] = array($package['package'], $package['version'], @$package['release_state']);
         }
         if (count($installed) == 0) {
             $data = '(no packages installed)';
         }
         $this->ui->outputData($data, $command);
     } else {
         if (file_exists($params[0]) && !is_dir($params[0])) {
             include_once "PEAR/Common.php";
             $obj =& new PEAR_Common();
             $info = $obj->infoFromAny($params[0]);
             $headings = array('Package File', 'Install Path');
             $installed = false;
         } else {
             $info = $reg->packageInfo($params[0]);
             $headings = array('Type', 'Install Path');
             $installed = true;
         }
         if (PEAR::isError($info)) {
             return $this->raiseError($info);
         }
         if ($info === null) {
             return $this->raiseError("`{$params['0']}' not installed");
         }
         $list = $info['filelist'];
         if ($installed) {
             $caption = 'Installed Files For ' . $params[0];
         } else {
             $caption = 'Contents of ' . basename($params[0]);
         }
         $data = array('caption' => $caption, 'border' => true, 'headline' => $headings);
         foreach ($list as $file => $att) {
             if ($installed) {
                 if (empty($att['installed_as'])) {
                     continue;
                 }
                 $data['data'][] = array($att['role'], $att['installed_as']);
             } else {
                 if (isset($att['baseinstalldir'])) {
                     $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR . $file;
                 } else {
                     $dest = $file;
                 }
                 switch ($att['role']) {
                     case 'test':
                     case 'data':
                         if ($installed) {
                             break 2;
                         }
                         $dest = '-- will not be installed --';
                         break;
                     case 'doc':
                         $dest = $this->config->get('doc_dir') . DIRECTORY_SEPARATOR . $dest;
                         break;
                     case 'php':
                     default:
                         $dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR . $dest;
                 }
                 $dest = preg_replace('!/+!', '/', $dest);
                 $file = preg_replace('!/+!', '/', $file);
                 $data['data'][] = array($file, $dest);
             }
         }
         $this->ui->outputData($data, $command);
     }
     return true;
 }
Beispiel #20
0
if (false && !file_exists($pear_user_config)) {
    // I think PEAR_Frontend_Web is running for the first time!
    // Install it properly ...
    // First of all set some config-vars:
    $cmd = PEAR_Command::factory('config-set', $config);
    $ok = $cmd->run('config-set', array(), array('php_dir', $dir . 'PEAR'));
    $ok = $cmd->run('config-set', array(), array('doc_dir', $dir . 'docs'));
    $ok = $cmd->run('config-set', array(), array('ext_dir', $dir . 'ext'));
    $ok = $cmd->run('config-set', array(), array('bin_dir', $dir . 'bin'));
    $ok = $cmd->run('config-set', array(), array('data_dir', $dir . 'data'));
    $ok = $cmd->run('config-set', array(), array('test_dir', $dir . 'test'));
    $ok = $cmd->run('config-set', array(), array('cache_dir', $dir . 'cache'));
    $ok = $cmd->run('config-set', array(), array('cache_ttl', 300));
    // Register packages
    $packages = array('Archive_Tar', 'Console_Getopt', 'HTML_Template_IT', 'Net_UserAgent_Detect', 'Pager', 'PEAR', 'PEAR_Frontend_Web', 'XML_RPC');
    $reg = new PEAR_Registry($dir . 'PEAR');
    if (!file_exists($dir . 'PEAR/.registry')) {
        PEAR::raiseError('Directory "' . $dir . 'PEAR/.registry" does not exist. please check your installation');
    }
    foreach ($packages as $pkg) {
        $info = $reg->packageInfo($pkg);
        foreach ($info['filelist'] as $fileName => $fileInfo) {
            if ($fileInfo['role'] == "php") {
                $info['filelist'][$fileName]['installed_as'] = str_replace('{dir}', $dir, $fileInfo['installed_as']);
            }
        }
        $reg->updatePackage($pkg, $info, false);
    }
}
// Handle some diffrent Commands
if (isset($_GET["command"])) {
Beispiel #21
0
    $result = "Database support is ok";
    $status = OK;
}
print_row("Database Support", $result, $status);
// PEAR
$have_pear = false;
if (!($pear_dir = find_path($path_list, "PEAR"))) {
    $result = "Not installed.  The PEAR extension is required by several other " . "PHP extensions that Maia needs.  See <a href=\"http://pear.php.net/\">this page</a> " . "for more information about downloading and installing PEAR.";
    $status = ERROR;
} else {
    // include_once ("PEAR/Remote.php");      // PEAR::Remote
    include_once "PEAR/Registry.php";
    // PEAR::Registry
    $have_pear = true;
    $pear = new PEAR_Config();
    $pear_reg = new PEAR_Registry($pear->get('php_dir'));
    $pear_info = $pear_reg->packageInfo("PEAR");
    $pear_list = $pear_reg->listPackages();
    $pear_version = is_array($pear_info["version"]) ? $pear_info["version"]["release"] : $pear_info["version"];
    $result = $pear_version;
    $status = OK;
}
print_row("PEAR", $result, $status);
// PEAR::Mail_Mime
if ($have_pear) {
    if (!in_array("mail_mime", $pear_list)) {
        $result = "Not installed.  This PHP extension is required to decode " . "MIME-structured e-mail.  Use <b>pear install Mail_Mime</b> to " . "install this.";
        $status = ERROR;
    } else {
        $info = $pear_reg->packageInfo("Mail_Mime");
        $result = is_array($info["version"]) ? $info["version"]["release"] : $info["version"];
Beispiel #22
0
 function doListUpgrades($command, $options, $params)
 {
     include_once "PEAR/Registry.php";
     $remote = new PEAR_Remote($this->config);
     if (empty($params[0])) {
         $state = $this->config->get('preferred_state');
     } else {
         $state = $params[0];
     }
     $caption = 'Available Upgrades';
     if (empty($state) || $state == 'any') {
         $latest = $remote->call("package.listLatestReleases");
     } else {
         $latest = $remote->call("package.listLatestReleases", $state);
         $caption .= ' (' . $state . ')';
     }
     $caption .= ':';
     if (PEAR::isError($latest)) {
         return $latest;
     }
     $reg = new PEAR_Registry($this->config->get('php_dir'));
     $inst = array_flip($reg->listPackages());
     $data = array('caption' => $caption, 'border' => 1, 'headline' => array('Package', 'Version', 'Size'));
     foreach ($latest as $package => $info) {
         if (!isset($inst[$package])) {
             // skip packages we don't have installed
             continue;
         }
         extract($info);
         $inst_version = $reg->packageInfo($package, 'version');
         if (version_compare("{$version}", "{$inst_version}", "le")) {
             // installed version is up-to-date
             continue;
         }
         if ($filesize >= 20480) {
             $filesize += 1024 - $filesize % 1024;
             $fs = sprintf("%dkB", $filesize / 1024);
         } elseif ($filesize > 0) {
             $filesize += 103 - $filesize % 103;
             $fs = sprintf("%.1fkB", $filesize / 1024.0);
         } else {
             $fs = "  -";
             // XXX center instead
         }
         $data['data'][] = array($package, $version, $fs);
     }
     if (empty($data['data'])) {
         $this->ui->outputData('No upgrades available');
     } else {
         $this->ui->outputData($data, $command);
     }
     return true;
 }
Beispiel #23
0
 function warning($msg)
 {
     return array(sprintf($msg, $this->_registry->parsedPackageNameToString($this->_currentPackage, true)));
 }
Beispiel #24
0
 /**
  * Installs the files within the package file specified.
  *
  * @param string|PEAR_Downloader_Package $pkgfile path to the package file,
  *        or a pre-initialized packagefile object
  * @param array $options
  * recognized options:
  * - installroot   : optional prefix directory for installation
  * - force         : force installation
  * - register-only : update registry but don't install files
  * - upgrade       : upgrade existing install
  * - soft          : fail silently
  * - nodeps        : ignore dependency conflicts/missing dependencies
  * - alldeps       : install all dependencies
  * - onlyreqdeps   : install only required dependencies
  *
  * @return array|PEAR_Error package info if successful
  */
 function install($pkgfile, $options = array())
 {
     $this->_options = $options;
     $this->_registry =& $this->config->getRegistry();
     if (is_object($pkgfile)) {
         $dlpkg =& $pkgfile;
         $pkg = $pkgfile->getPackageFile();
         $pkgfile = $pkg->getArchiveFile();
         $descfile = $pkg->getPackageFile();
     } else {
         $descfile = $pkgfile;
         $pkg = $this->_parsePackageXml($descfile);
         if (PEAR::isError($pkg)) {
             return $pkg;
         }
     }
     $tmpdir = dirname($descfile);
     if (realpath($descfile) != realpath($pkgfile)) {
         // Use the temp_dir since $descfile can contain the download dir path
         $tmpdir = $this->config->get('temp_dir', null, 'pear.php.net');
         $tmpdir = System::mktemp('-d -t "' . $tmpdir . '"');
         $tar = new Archive_Tar($pkgfile);
         if (!$tar->extract($tmpdir)) {
             return $this->raiseError("unable to unpack {$pkgfile}");
         }
     }
     $pkgname = $pkg->getName();
     $channel = $pkg->getChannel();
     if (isset($this->_options['packagingroot'])) {
         $regdir = $this->_prependPath($this->config->get('php_dir', null, 'pear.php.net'), $this->_options['packagingroot']);
         $packrootphp_dir = $this->_prependPath($this->config->get('php_dir', null, $channel), $this->_options['packagingroot']);
     }
     if (isset($options['installroot'])) {
         $this->config->setInstallRoot($options['installroot']);
         $this->_registry =& $this->config->getRegistry();
         $installregistry =& $this->_registry;
         $this->installroot = '';
         // all done automagically now
         $php_dir = $this->config->get('php_dir', null, $channel);
     } else {
         $this->config->setInstallRoot(false);
         $this->_registry =& $this->config->getRegistry();
         if (isset($this->_options['packagingroot'])) {
             $installregistry = new PEAR_Registry($regdir);
             if (!$installregistry->channelExists($channel, true)) {
                 // we need to fake a channel-discover of this channel
                 $chanobj = $this->_registry->getChannel($channel, true);
                 $installregistry->addChannel($chanobj);
             }
             $php_dir = $packrootphp_dir;
         } else {
             $installregistry =& $this->_registry;
             $php_dir = $this->config->get('php_dir', null, $channel);
         }
         $this->installroot = '';
     }
     // {{{ checks to do when not in "force" mode
     if (empty($options['force']) && (file_exists($this->config->get('php_dir')) && is_dir($this->config->get('php_dir')))) {
         $testp = $channel == 'pear.php.net' ? $pkgname : array($channel, $pkgname);
         $instfilelist = $pkg->getInstallationFileList(true);
         if (PEAR::isError($instfilelist)) {
             return $instfilelist;
         }
         // ensure we have the most accurate registry
         $installregistry->flushFileMap();
         $test = $installregistry->checkFileMap($instfilelist, $testp, '1.1');
         if (PEAR::isError($test)) {
             return $test;
         }
         if (sizeof($test)) {
             $pkgs = $this->getInstallPackages();
             $found = false;
             foreach ($pkgs as $param) {
                 if ($pkg->isSubpackageOf($param)) {
                     $found = true;
                     break;
                 }
             }
             if ($found) {
                 // subpackages can conflict with earlier versions of parent packages
                 $parentreg = $installregistry->packageInfo($param->getPackage(), null, $param->getChannel());
                 $tmp = $test;
                 foreach ($tmp as $file => $info) {
                     if (is_array($info)) {
                         if (strtolower($info[1]) == strtolower($param->getPackage()) && strtolower($info[0]) == strtolower($param->getChannel())) {
                             if (isset($parentreg['filelist'][$file])) {
                                 unset($parentreg['filelist'][$file]);
                             } else {
                                 $pos = strpos($file, '/');
                                 $basedir = substr($file, 0, $pos);
                                 $file2 = substr($file, $pos + 1);
                                 if (isset($parentreg['filelist'][$file2]['baseinstalldir']) && $parentreg['filelist'][$file2]['baseinstalldir'] === $basedir) {
                                     unset($parentreg['filelist'][$file2]);
                                 }
                             }
                             unset($test[$file]);
                         }
                     } else {
                         if (strtolower($param->getChannel()) != 'pear.php.net') {
                             continue;
                         }
                         if (strtolower($info) == strtolower($param->getPackage())) {
                             if (isset($parentreg['filelist'][$file])) {
                                 unset($parentreg['filelist'][$file]);
                             } else {
                                 $pos = strpos($file, '/');
                                 $basedir = substr($file, 0, $pos);
                                 $file2 = substr($file, $pos + 1);
                                 if (isset($parentreg['filelist'][$file2]['baseinstalldir']) && $parentreg['filelist'][$file2]['baseinstalldir'] === $basedir) {
                                     unset($parentreg['filelist'][$file2]);
                                 }
                             }
                             unset($test[$file]);
                         }
                     }
                 }
                 $pfk = new PEAR_PackageFile($this->config);
                 $parentpkg =& $pfk->fromArray($parentreg);
                 $installregistry->updatePackage2($parentpkg);
             }
             if ($param->getChannel() == 'pecl.php.net' && isset($options['upgrade'])) {
                 $tmp = $test;
                 foreach ($tmp as $file => $info) {
                     if (is_string($info)) {
                         // pear.php.net packages are always stored as strings
                         if (strtolower($info) == strtolower($param->getPackage())) {
                             // upgrading existing package
                             unset($test[$file]);
                         }
                     }
                 }
             }
             if (count($test)) {
                 $msg = "{$channel}/{$pkgname}: conflicting files found:\n";
                 $longest = max(array_map("strlen", array_keys($test)));
                 $fmt = "%{$longest}s (%s)\n";
                 foreach ($test as $file => $info) {
                     if (!is_array($info)) {
                         $info = array('pear.php.net', $info);
                     }
                     $info = $info[0] . '/' . $info[1];
                     $msg .= sprintf($fmt, $file, $info);
                 }
                 if (!isset($options['ignore-errors'])) {
                     return $this->raiseError($msg);
                 }
                 if (!isset($options['soft'])) {
                     $this->log(0, "WARNING: {$msg}");
                 }
             }
         }
     }
     // }}}
     $this->startFileTransaction();
     $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['upgrade']) && empty($options['soft'])) {
         // checks to do only when installing new packages
         if (empty($options['force']) && $test) {
             return $this->raiseError("{$channel}/{$pkgname} is already installed");
         }
     } else {
         // Upgrade
         if ($test) {
             $v1 = $installregistry->packageInfo($pkgname, 'version', $usechannel);
             $v2 = $pkg->getVersion();
             $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})");
             }
         }
     }
     // Do cleanups for upgrade and install, remove old release's files first
     if ($test && empty($options['register-only'])) {
         // when upgrading, remove old release's files first:
         if (PEAR::isError($err = $this->_deletePackageFiles($pkgname, $usechannel, true))) {
             if (!isset($options['ignore-errors'])) {
                 return $this->raiseError($err);
             }
             if (!isset($options['soft'])) {
                 $this->log(0, 'WARNING: ' . $err->getMessage());
             }
         } else {
             $backedup = $err;
         }
     }
     // {{{ Copy files to dest dir ---------------------------------------
     // info from the package it self we want to access from _installFile
     $this->pkginfo =& $pkg;
     // used to determine whether we should build any C code
     $this->source_files = 0;
     $savechannel = $this->config->get('default_channel');
     if (empty($options['register-only']) && !is_dir($php_dir)) {
         if (PEAR::isError(System::mkdir(array('-p'), $php_dir))) {
             return $this->raiseError("no installation destination directory '{$php_dir}'\n");
         }
     }
     if (substr($pkgfile, -4) != '.xml') {
         $tmpdir .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkg->getVersion();
     }
     $this->configSet('default_channel', $channel);
     // {{{ install files
     $ver = $pkg->getPackagexmlVersion();
     if (version_compare($ver, '2.0', '>=')) {
         $filelist = $pkg->getInstallationFilelist();
     } else {
         $filelist = $pkg->getFileList();
     }
     if (PEAR::isError($filelist)) {
         return $filelist;
     }
     $p =& $installregistry->getPackage($pkgname, $channel);
     $dirtree = empty($options['register-only']) && $p ? $p->getDirTree() : false;
     $pkg->resetFilelist();
     $pkg->setLastInstalledVersion($installregistry->packageInfo($pkg->getPackage(), 'version', $pkg->getChannel()));
     foreach ($filelist as $file => $atts) {
         $this->expectError(PEAR_INSTALLER_FAILED);
         if ($pkg->getPackagexmlVersion() == '1.0') {
             $res = $this->_installFile($file, $atts, $tmpdir, $options);
         } else {
             $res = $this->_installFile2($pkg, $file, $atts, $tmpdir, $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);
             }
             if (!isset($options['soft'])) {
                 $this->log(0, "Warning: " . $res->getMessage());
             }
         }
         $real = isset($atts['attribs']) ? $atts['attribs'] : $atts;
         if ($res == PEAR_INSTALLER_OK && $real['role'] != 'src') {
             // 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 {
         if ($dirtree) {
             $this->startFileTransaction();
             // attempt to delete empty directories
             uksort($dirtree, array($this, '_sortDirs'));
             foreach ($dirtree as $dir => $notused) {
                 $this->addFileOperation('rmdir', array($dir));
             }
             $this->commitFileTransaction();
         }
         $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);
 }
Beispiel #25
0
 function doUninstall($command, $options, $params)
 {
     if (empty($this->installer)) {
         $this->installer =& new PEAR_Installer($this->ui);
     }
     if (sizeof($params) < 1) {
         return $this->raiseError("Please supply the package(s) you want to uninstall");
     }
     include_once 'PEAR/Registry.php';
     $reg = new PEAR_Registry($this->config->get('php_dir'));
     $newparams = array();
     $badparams = array();
     foreach ($params as $pkg) {
         $info = $reg->packageInfo($pkg);
         if ($info === null) {
             $badparams[] = $pkg;
         } else {
             $newparams[] = $info;
         }
     }
     PEAR_Common::sortPkgDeps($newparams, true);
     $params = array();
     foreach ($newparams as $info) {
         $params[] = $info['info']['package'];
     }
     $params = array_merge($params, $badparams);
     foreach ($params as $pkg) {
         if ($this->installer->uninstall($pkg, $options)) {
             if ($this->config->get('verbose') > 0) {
                 $this->ui->outputData("uninstall ok: {$pkg}", $command);
             }
         } else {
             return $this->raiseError("uninstall failed: {$pkg}");
         }
     }
     return true;
 }
Beispiel #26
0
 function call_epi($method)
 {
     if (!extension_loaded("xmlrpc")) {
         return $this->raiseError("xmlrpc extension is not loaded");
     }
     $server_channel = $this->config->get('default_channel');
     $channel = $this->_registry->getChannel($server_channel);
     if (!PEAR::isError($channel)) {
         $mirror = $this->config->get('preferred_mirror');
         if ($channel->getMirror($mirror)) {
             if ($channel->supports('xmlrpc', $method, $mirror)) {
                 $server_channel = $server_host = $mirror;
                 // use the preferred mirror
                 $server_port = $channel->getPort($mirror);
             } elseif (!$channel->supports('xmlrpc', $method)) {
                 return $this->raiseError("Channel {$server_channel} does not " . "support xml-rpc method {$method}");
             }
         }
         if (!isset($server_host)) {
             if (!$channel->supports('xmlrpc', $method)) {
                 return $this->raiseError("Channel {$server_channel} does not support " . "xml-rpc method {$method}");
             } else {
                 $server_host = $server_channel;
                 $server_port = $channel->getPort();
             }
         }
     } else {
         return $this->raiseError("Unknown channel '{$server_channel}'");
     }
     $params = func_get_args();
     array_shift($params);
     $method = str_replace("_", ".", $method);
     $request = xmlrpc_encode_request($method, $params);
     if ($http_proxy = $this->config->get('http_proxy')) {
         $proxy = parse_url($http_proxy);
         $proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
         $proxy_host = isset($proxy['host']) ? $proxy['host'] : null;
         if (isset($proxy['scheme']) && $proxy['scheme'] == 'https') {
             $proxy_host = 'https://' . $proxy_host;
         }
         $proxy_port = isset($proxy['port']) ? $proxy['port'] : null;
         $proxy_user = isset($proxy['user']) ? urldecode($proxy['user']) : null;
         $proxy_pass = isset($proxy['pass']) ? urldecode($proxy['pass']) : null;
         $fp = @fsockopen($proxy_host, $proxy_port);
         $use_proxy = true;
         if ($channel->getSSL()) {
             $server_host = "https://{$server_host}";
         }
     } else {
         $use_proxy = false;
         $ssl = $channel->getSSL();
         $fp = @fsockopen(($ssl ? 'ssl://' : '') . $server_host, $server_port);
         if (!$fp) {
             $server_host = "{$ssl}{$server_host}";
             // for error-reporting
         }
     }
     if (!$fp && $http_proxy) {
         return $this->raiseError("PEAR_Remote::call: fsockopen(`{$proxy_host}', {$proxy_port}) failed");
     } elseif (!$fp) {
         return $this->raiseError("PEAR_Remote::call: fsockopen(`{$server_host}', {$server_port}) failed");
     }
     $len = strlen($request);
     $req_headers = "Host: {$server_host}:{$server_port}\r\n" . "Content-type: text/xml\r\n" . "Content-length: {$len}\r\n";
     $username = $this->config->get('username');
     $password = $this->config->get('password');
     if ($username && $password) {
         $req_headers .= "Cookie: PEAR_USER={$username}; PEAR_PW={$password}\r\n";
         $tmp = base64_encode("{$username}:{$password}");
         $req_headers .= "Authorization: Basic {$tmp}\r\n";
     }
     if ($this->cache !== null) {
         $maxAge = '?maxAge=' . $this->cache['lastChange'];
     } else {
         $maxAge = '';
     }
     if ($use_proxy && $proxy_host != '' && $proxy_user != '') {
         $req_headers .= 'Proxy-Authorization: Basic ' . base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n";
     }
     if ($this->config->get('verbose') > 3) {
         print "XMLRPC REQUEST HEADERS:\n";
         var_dump($req_headers);
         print "XMLRPC REQUEST BODY:\n";
         var_dump($request);
     }
     if ($use_proxy && $proxy_host != '') {
         $post_string = "POST http://" . $server_host;
         if ($proxy_port > '') {
             $post_string .= ':' . $server_port;
         }
     } else {
         $post_string = "POST ";
     }
     $path = '/' . $channel->getPath('xmlrpc');
     fwrite($fp, $post_string . $path . "{$maxAge} HTTP/1.0\r\n{$req_headers}\r\n{$request}");
     $response = '';
     $line1 = fgets($fp, 2048);
     if (!preg_match('!^HTTP/[0-9\\.]+ (\\d+) (.*)!', $line1, $matches)) {
         return $this->raiseError("PEAR_Remote: invalid HTTP response from XML-RPC server");
     }
     switch ($matches[1]) {
         case "200":
             // OK
             break;
         case "304":
             // Not Modified
             return $this->cache['content'];
         case "401":
             // Unauthorized
             if ($username && $password) {
                 return $this->raiseError("PEAR_Remote ({$server_host}:{$server_port}) " . ": authorization failed", 401);
             } else {
                 return $this->raiseError("PEAR_Remote ({$server_host}:{$server_port}) " . ": authorization required, please log in first", 401);
             }
         default:
             return $this->raiseError("PEAR_Remote ({$server_host}:{$server_port}) : " . "unexpected HTTP response", (int) $matches[1], null, null, "{$matches['1']} {$matches['2']}");
     }
     while (trim(fgets($fp, 2048)) != '') {
     }
     // skip rest of headers
     while ($chunk = fread($fp, 10240)) {
         $response .= $chunk;
     }
     fclose($fp);
     if ($this->config->get('verbose') > 3) {
         print "XMLRPC RESPONSE:\n";
         var_dump($response);
     }
     $ret = xmlrpc_decode($response);
     if (is_array($ret) && isset($ret['__PEAR_TYPE__'])) {
         if ($ret['__PEAR_TYPE__'] == 'error') {
             if (isset($ret['__PEAR_CLASS__'])) {
                 $class = $ret['__PEAR_CLASS__'];
             } else {
                 $class = "PEAR_Error";
             }
             if ($ret['code'] === '') {
                 $ret['code'] = null;
             }
             if ($ret['message'] === '') {
                 $ret['message'] = null;
             }
             if ($ret['userinfo'] === '') {
                 $ret['userinfo'] = null;
             }
             if (strtolower($class) == 'db_error') {
                 $ret = $this->raiseError(PEAR::errorMessage($ret['code']), $ret['code'], null, null, $ret['userinfo']);
             } else {
                 $ret = $this->raiseError($ret['message'], $ret['code'], null, null, $ret['userinfo']);
             }
         }
     } elseif (is_array($ret) && sizeof($ret) == 1 && isset($ret[0]) && is_array($ret[0]) && !empty($ret[0]['faultString']) && !empty($ret[0]['faultCode'])) {
         extract($ret[0]);
         $faultString = "XML-RPC Server Fault: " . str_replace("\n", " ", $faultString);
         return $this->raiseError($faultString, $faultCode);
     } elseif (is_array($ret) && sizeof($ret) == 2 && !empty($ret['faultString']) && !empty($ret['faultCode'])) {
         extract($ret);
         $faultString = "XML-RPC Server Fault: " . str_replace("\n", " ", $faultString);
         return $this->raiseError($faultString, $faultCode);
     }
     return $ret;
 }
Beispiel #27
0
 /**
  * Validate XML package definition file.
  *
  * @access public
  * @return boolean
  */
 function validate($state = PEAR_VALIDATE_NORMAL, $nofilechecking = false)
 {
     if (($this->_isValid & $state) == $state) {
         return true;
     }
     $this->_isValid = true;
     $info = $this->_packageInfo;
     if (empty($info['package'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_NAME);
         $this->_packageName = $pn = 'unknown';
     } else {
         $this->_packageName = $pn = $info['package'];
     }
     if (empty($info['summary'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_SUMMARY);
     } elseif (strpos(trim($info['summary']), "\n") !== false) {
         $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY, array('summary' => $info['summary']));
     }
     if (empty($info['description'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION);
     }
     if (empty($info['release_license'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_LICENSE);
     }
     if (empty($info['version'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_VERSION);
     }
     if (empty($info['release_state'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_STATE);
     }
     if (empty($info['release_date'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DATE);
     }
     if (empty($info['release_notes'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_NOTES);
     }
     if (empty($info['maintainers'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS);
     } else {
         $haslead = false;
         $i = 1;
         foreach ($info['maintainers'] as $m) {
             if (empty($m['handle'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE, array('index' => $i));
             }
             if (empty($m['role'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE, array('index' => $i, 'roles' => PEAR_Common::getUserRoles()));
             } elseif ($m['role'] == 'lead') {
                 $haslead = true;
             }
             if (empty($m['name'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME, array('index' => $i));
             }
             if (empty($m['email'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL, array('index' => $i));
             }
             $i++;
         }
         if (!$haslead) {
             $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_LEAD);
         }
     }
     if (!empty($info['release_deps'])) {
         $i = 1;
         foreach ($info['release_deps'] as $d) {
             if (!isset($d['type']) || empty($d['type'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE, array('index' => $i, 'types' => PEAR_Common::getDependencyTypes()));
                 continue;
             }
             if (!isset($d['rel']) || empty($d['rel'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPREL, array('index' => $i, 'rels' => PEAR_Common::getDependencyRelations()));
                 continue;
             }
             if (!empty($d['optional'])) {
                 if (!in_array($d['optional'], array('yes', 'no'))) {
                     $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL, array('index' => $i, 'opt' => $d['optional']));
                 }
             }
             if ($d['rel'] != 'has' && $d['rel'] != 'not' && empty($d['version'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION, array('index' => $i));
             } elseif (($d['rel'] == 'has' || $d['rel'] == 'not') && !empty($d['version'])) {
                 $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED, array('index' => $i, 'rel' => $d['rel']));
             }
             if ($d['type'] == 'php' && !empty($d['name'])) {
                 $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED, array('index' => $i, 'name' => $d['name']));
             } elseif ($d['type'] != 'php' && empty($d['name'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPNAME, array('index' => $i));
             }
             if ($d['type'] == 'php' && empty($d['version'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION, array('index' => $i));
             }
             if ($d['rel'] == 'not' && $d['type'] == 'php') {
                 $this->_validateError(PEAR_PACKAGEFILE_PHP_NO_NOT, array('index' => $i));
             }
             $i++;
         }
     }
     if (!empty($info['configure_options'])) {
         $i = 1;
         foreach ($info['configure_options'] as $c) {
             if (empty($c['name'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_CONFNAME, array('index' => $i));
             }
             if (empty($c['prompt'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT, array('index' => $i));
             }
             $i++;
         }
     }
     if (empty($info['filelist'])) {
         $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_FILES);
         $errors[] = 'no files';
     } else {
         foreach ($info['filelist'] as $file => $fa) {
             if (empty($fa['role'])) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_FILEROLE, array('file' => $file, 'roles' => PEAR_Common::getFileRoles()));
                 continue;
             } elseif (!in_array($fa['role'], PEAR_Common::getFileRoles())) {
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE, array('file' => $file, 'role' => $fa['role'], 'roles' => PEAR_Common::getFileRoles()));
             }
             if (preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $file))) {
                 // file contains .. parent directory or . cur directory references
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME, array('file' => $file));
             }
             if (isset($fa['install-as']) && preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $fa['install-as']))) {
                 // install-as contains .. parent directory or . cur directory references
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME, array('file' => $file . ' [installed as ' . $fa['install-as'] . ']'));
             }
             if (isset($fa['baseinstalldir']) && preg_match('~/\\.\\.?(/|\\z)|^\\.\\.?/~', str_replace('\\', '/', $fa['baseinstalldir']))) {
                 // install-as contains .. parent directory or . cur directory references
                 $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME, array('file' => $file . ' [baseinstalldir ' . $fa['baseinstalldir'] . ']'));
             }
         }
     }
     if (isset($this->_registry) && $this->_isValid) {
         $chan = $this->_registry->getChannel('pear.php.net');
         if (PEAR::isError($chan)) {
             $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $chan->getMessage());
             return $this->_isValid = 0;
         }
         $validator = $chan->getValidationObject();
         $validator->setPackageFile($this);
         $validator->validate($state);
         $failures = $validator->getFailures();
         foreach ($failures['errors'] as $error) {
             $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $error);
         }
         foreach ($failures['warnings'] as $warning) {
             $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $warning);
         }
     }
     if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$nofilechecking) {
         if ($this->_analyzePhpFiles()) {
             $this->_isValid = true;
         }
     }
     if ($this->_isValid) {
         return $this->_isValid = $state;
     }
     return $this->_isValid = 0;
 }
Beispiel #28
0
 /**
  * @param array output of package.getDownloadURL
  * @param string|array|object information for detecting packages to be downloaded, and
  *                            for errors
  * @param array name information of the package
  * @param array|null packages to be downloaded
  * @param bool is this an optional dependency?
  * @param bool is this any kind of dependency?
  * @access private
  */
 function _analyzeDownloadURL($info, $param, $pname, $params = null, $optional = false, $isdependency = false)
 {
     if (!is_string($param) && PEAR_Downloader_Package::willDownload($param, $params)) {
         return false;
     }
     if ($info === false) {
         $saveparam = !is_string($param) ? ", cannot download \"{$param}\"" : '';
         // no releases exist
         return PEAR::raiseError('No releases for package "' . $this->_registry->parsedPackageNameToString($pname, true) . '" exist' . $saveparam);
     }
     if (strtolower($info['info']->getChannel()) != strtolower($pname['channel'])) {
         $err = false;
         if ($pname['channel'] == 'pecl.php.net') {
             if ($info['info']->getChannel() != 'pear.php.net') {
                 $err = true;
             }
         } elseif ($info['info']->getChannel() == 'pecl.php.net') {
             if ($pname['channel'] != 'pear.php.net') {
                 $err = true;
             }
         } else {
             $err = true;
         }
         if ($err) {
             return PEAR::raiseError('SECURITY ERROR: package in channel "' . $pname['channel'] . '" retrieved another channel\'s name for download! ("' . $info['info']->getChannel() . '")');
         }
     }
     $preferred_state = $this->_config->get('preferred_state');
     if (!isset($info['url'])) {
         $package_version = $this->_registry->packageInfo($info['info']->getPackage(), 'version', $info['info']->getChannel());
         if ($this->isInstalled($info)) {
             if ($isdependency && version_compare($info['version'], $package_version, '<=')) {
                 // ignore bogus errors of "failed to download dependency"
                 // if it is already installed and the one that would be
                 // downloaded is older or the same version (Bug #7219)
                 return false;
             }
         }
         if ($info['version'] === $package_version) {
             if (!isset($options['soft'])) {
                 $this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] . '/' . $pname['package'] . '-' . $package_version . ', additionally the suggested version' . ' (' . $package_version . ') is the same as the locally installed one.');
             }
             return false;
         }
         if (version_compare($info['version'], $package_version, '<=')) {
             if (!isset($options['soft'])) {
                 $this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] . '/' . $pname['package'] . '-' . $package_version . ', additionally the suggested version' . ' (' . $info['version'] . ') is a lower version than the locally installed one (' . $package_version . ').');
             }
             return false;
         }
         $instead = ', will instead download version ' . $info['version'] . ', stability "' . $info['info']->getState() . '"';
         // releases exist, but we failed to get any
         if (isset($this->_downloader->_options['force'])) {
             if (isset($pname['version'])) {
                 $vs = ', version "' . $pname['version'] . '"';
             } elseif (isset($pname['state'])) {
                 $vs = ', stability "' . $pname['state'] . '"';
             } elseif ($param == 'dependency') {
                 if (!class_exists('PEAR_Common')) {
                     require_once 'PEAR/Common.php';
                 }
                 if (!in_array($info['info']->getState(), PEAR_Common::betterStates($preferred_state, true))) {
                     if ($optional) {
                         // don't spit out confusing error message
                         return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
                     }
                     $vs = ' within preferred state "' . $preferred_state . '"';
                 } else {
                     if (!class_exists('PEAR_Dependency2')) {
                         require_once 'PEAR/Dependency2.php';
                     }
                     if ($optional) {
                         // don't spit out confusing error message
                         return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
                     }
                     $vs = PEAR_Dependency2::_getExtraString($pname);
                     $instead = '';
                 }
             } else {
                 $vs = ' within preferred state "' . $preferred_state . '"';
             }
             if (!isset($options['soft'])) {
                 $this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] . '/' . $pname['package'] . $vs . $instead);
             }
             // download the latest release
             return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
         } else {
             if (isset($info['php']) && $info['php']) {
                 $err = PEAR::raiseError('Failed to download ' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package']), true) . ', latest release is version ' . $info['php']['v'] . ', but it requires PHP version "' . $info['php']['m'] . '", use "' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package'], 'version' => $info['php']['v'])) . '" to install', PEAR_DOWNLOADER_PACKAGE_PHPVERSION);
                 return $err;
             }
             // construct helpful error message
             if (isset($pname['version'])) {
                 $vs = ', version "' . $pname['version'] . '"';
             } elseif (isset($pname['state'])) {
                 $vs = ', stability "' . $pname['state'] . '"';
             } elseif ($param == 'dependency') {
                 if (!class_exists('PEAR_Common')) {
                     require_once 'PEAR/Common.php';
                 }
                 if (!in_array($info['info']->getState(), PEAR_Common::betterStates($preferred_state, true))) {
                     if ($optional) {
                         // don't spit out confusing error message, and don't die on
                         // optional dep failure!
                         return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
                     }
                     $vs = ' within preferred state "' . $preferred_state . '"';
                 } else {
                     if (!class_exists('PEAR_Dependency2')) {
                         require_once 'PEAR/Dependency2.php';
                     }
                     if ($optional) {
                         // don't spit out confusing error message, and don't die on
                         // optional dep failure!
                         return $this->_downloader->_getPackageDownloadUrl(array('package' => $pname['package'], 'channel' => $pname['channel'], 'version' => $info['version']));
                     }
                     $vs = PEAR_Dependency2::_getExtraString($pname);
                 }
             } else {
                 $vs = ' within preferred state "' . $this->_downloader->config->get('preferred_state') . '"';
             }
             $options = $this->_downloader->getOptions();
             // this is only set by the "download-all" command
             if (isset($options['ignorepreferred_state'])) {
                 $err = PEAR::raiseError('Failed to download ' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package']), true) . $vs . ', latest release is version ' . $info['version'] . ', stability "' . $info['info']->getState() . '", use "' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package'], 'version' => $info['version'])) . '" to install', PEAR_DOWNLOADER_PACKAGE_STATE);
                 return $err;
             }
             // Checks if the user has a package installed already and checks the release against
             // the state against the installed package, this allows upgrades for packages
             // with lower stability than the preferred_state
             $stability = $this->_registry->packageInfo($pname['package'], 'stability', $pname['channel']);
             if (!$this->isInstalled($info) || !in_array($info['info']->getState(), PEAR_Common::betterStates($stability['release'], true))) {
                 $err = PEAR::raiseError('Failed to download ' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package']), true) . $vs . ', latest release is version ' . $info['version'] . ', stability "' . $info['info']->getState() . '", use "' . $this->_registry->parsedPackageNameToString(array('channel' => $pname['channel'], 'package' => $pname['package'], 'version' => $info['version'])) . '" to install');
                 return $err;
             }
         }
     }
     if (isset($info['deprecated']) && $info['deprecated']) {
         $this->_downloader->log(0, 'WARNING: "' . $this->_registry->parsedPackageNameToString(array('channel' => $info['info']->getChannel(), 'package' => $info['info']->getPackage()), true) . '" is deprecated in favor of "' . $this->_registry->parsedPackageNameToString($info['deprecated'], true) . '"');
     }
     return $info;
 }
Beispiel #29
0
 /**
  * Set up the dependency for installation parsing
  *
  * @param array $t dependency information
  * @param PEAR_Registry $reg
  * @param array $deplinks list of dependency links already established
  * @param array $nodes all existing package nodes
  * @param string $package parent package name
  * @access private
  */
 function _setupGraph($t, $reg, &$deplinks, &$nodes, $package)
 {
     foreach ($t as $dep) {
         $depchannel = !isset($dep['channel']) ? '__uri' : $dep['channel'];
         $dname = $reg->parsedPackageNameToString(array('channel' => $depchannel, 'package' => strtolower($dep['name'])));
         if (isset($nodes[$dname])) {
             if (!isset($deplinks[$dname])) {
                 $deplinks[$dname] = array();
             }
             $deplinks[$dname][$package] = 1;
         }
     }
 }
Beispiel #30
0
 /**
  * Installation of source package has failed, attempt to download and install the
  * binary version of this package.
  * @param PEAR_Installer
  * @return array|false
  */
 function installBinary(&$installer)
 {
     if (!OS_WINDOWS) {
         $a = false;
         return $a;
     }
     if ($this->getPackageType() == 'extsrc' || $this->getPackageType() == 'zendextsrc') {
         $releasetype = $this->getPackageType() . 'release';
         if (!is_array($installer->getInstallPackages())) {
             $a = false;
             return $a;
         }
         foreach ($installer->getInstallPackages() as $p) {
             if ($p->isExtension($this->_packageInfo['providesextension'])) {
                 if ($p->getPackageType() != 'extsrc' && $p->getPackageType() != 'zendextsrc') {
                     $a = false;
                     return $a;
                     // the user probably downloaded it separately
                 }
             }
         }
         if (isset($this->_packageInfo[$releasetype]['binarypackage'])) {
             $installer->log(0, 'Attempting to download binary version of extension "' . $this->_packageInfo['providesextension'] . '"');
             $params = $this->_packageInfo[$releasetype]['binarypackage'];
             if (!is_array($params) || !isset($params[0])) {
                 $params = array($params);
             }
             if (isset($this->_packageInfo['channel'])) {
                 foreach ($params as $i => $param) {
                     $params[$i] = array('channel' => $this->_packageInfo['channel'], 'package' => $param, 'version' => $this->getVersion());
                 }
             }
             $dl =& $this->getPEARDownloader($installer->ui, $installer->getOptions(), $installer->config);
             $verbose = $dl->config->get('verbose');
             $dl->config->set('verbose', -1);
             foreach ($params as $param) {
                 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
                 $ret = $dl->download(array($param));
                 PEAR::popErrorHandling();
                 if (is_array($ret) && count($ret)) {
                     break;
                 }
             }
             $dl->config->set('verbose', $verbose);
             if (is_array($ret)) {
                 if (count($ret) == 1) {
                     $pf = $ret[0]->getPackageFile();
                     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
                     $err = $installer->install($ret[0]);
                     PEAR::popErrorHandling();
                     if (is_array($err)) {
                         $this->_packageInfo['#binarypackage'] = $ret[0]->getPackage();
                         // "install" self, so all dependencies will work transparently
                         $this->_registry->addPackage2($this);
                         $installer->log(0, 'Download and install of binary extension "' . $this->_registry->parsedPackageNameToString(array('channel' => $pf->getChannel(), 'package' => $pf->getPackage()), true) . '" successful');
                         $a = array($ret[0], $err);
                         return $a;
                     }
                     $installer->log(0, 'Download and install of binary extension "' . $this->_registry->parsedPackageNameToString(array('channel' => $pf->getChannel(), 'package' => $pf->getPackage()), true) . '" failed');
                 }
             }
         }
     }
     $a = false;
     return $a;
 }