public function checkDownloads() { $pear = new Varien_Pear(); $pkg = new PEAR_PackageFile($pear->getConfig(), false); $result = true; foreach ($this->getPackages() as $package) { $obj = $pkg->fromAnyFile($package, PEAR_VALIDATE_NORMAL); if (PEAR::isError($obj)) { $uinfo = $obj->getUserInfo(); if (is_array($uinfo)) { foreach ($uinfo as $message) { if (is_array($message)) { $message = $message['message']; } Mage::getSingleton('Mage_Install_Model_Session')->addError($message); } } else { print_r($obj->getUserInfo()); #Mage::getSingleton('Mage_Install_Model_Session')->addError($message); } $result = false; } } return $result; }
/** * Returns information about a package file. Expects the name of * a gzipped tar file as input. * * @param string $file name of .tgz file * * @return array array with package information * * @access public * @deprecated use PEAR_PackageFile->fromTgzFile() instead * */ function infoFromTgzFile($file) { $config =& PEAR_Config::singleton(); $packagefile = new PEAR_PackageFile($config); $pf =& $packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); if (is_array($errs)) { foreach ($errs as $error) { $e = $this->raiseError($error['message'], $error['code'], null, null, $error); } } return $pf; } return $this->_postProcessValidPackagexml($pf); }
/** * Constructor. * * Searches all installed applications and libraries for migration * directories and builds lists of migrateable modules and directories. * * @param string $basedir Base directory of a Git checkout. If provided * a framework/ sub directory is searched for * migration scripts too. * @param string $pearconf Path to a PEAR configuration file. */ public function __construct($basedir = null, $pearconf = null) { // Loop through all applications. foreach ($GLOBALS['registry']->listAllApps() as $app) { $dir = $GLOBALS['registry']->get('fileroot', $app) . '/migration'; if (is_dir($dir)) { $this->apps[] = $app; $this->_lower[] = Horde_String::lower($app); $this->dirs[] = realpath($dir); } } // Silence PEAR errors. $old_error_reporting = error_reporting(); error_reporting($old_error_reporting & ~E_DEPRECATED); $pear = new PEAR_Config($pearconf); // Loop through local framework checkout. if ($basedir) { $packageFile = new PEAR_PackageFile($pear); foreach (glob($basedir . '/framework/*/migration') as $dir) { $package = $packageFile->fromPackageFile(dirname($dir) . '/package.xml', PEAR_VALIDATE_NORMAL); if ($package instanceof PEAR_Error) { Horde::log(sprintf('%s: %s', $package->getMessage(), print_r($package->getUserInfo(), true)), Horde_Log::ERR); continue; } $this->apps[] = $package->getName(); $this->_lower[] = Horde_String::lower($package->getName()); $this->dirs[] = realpath($dir); } } // Loop through installed PEAR packages. $registry = $pear->getRegistry(); foreach (glob($pear->get('data_dir') . '/*/migration') as $dir) { $package = $registry->getPackage(basename(dirname($dir)), 'pear.horde.org'); if ($package == false) { Horde::log("Ignoring package in directory {$dir}", Horde_Log::WARN); continue; } $app = $package->getName(); if (!in_array($app, $this->apps)) { $this->apps[] = $app; $this->_lower[] = Horde_String::lower($app); $this->dirs[] = realpath($dir); } } error_reporting($old_error_reporting); }
/** * @return bool */ public function checkDownloads() { $pear = new \Magento\Framework\Pear(); $pkg = new PEAR_PackageFile($pear->getConfig(), false); $result = true; foreach ($this->getPackages() as $package) { $obj = $pkg->fromAnyFile($package, PEAR_VALIDATE_NORMAL); if (PEAR::isError($obj)) { $uinfo = $obj->getUserInfo(); if (is_array($uinfo)) { foreach ($uinfo as $message) { if (is_array($message)) { $message = $message['message']; } $this->messageManager->addError($message); } } else { print_r($obj->getUserInfo()); } $result = false; } } return $result; }
function getDeps() { if (isset($this->_packagefile)) { $ver = $this->_packagefile->getPackagexmlVersion(); if (version_compare($ver, '2.0', '>=')) { return $this->_packagefile->getDeps(true); } return $this->_packagefile->getDeps(); } elseif (isset($this->_downloadURL['info'])) { $ver = $this->_downloadURL['info']->getPackagexmlVersion(); if (version_compare($ver, '2.0', '>=')) { return $this->_downloadURL['info']->getDeps(true); } return $this->_downloadURL['info']->getDeps(); } return array(); }
function getDeps() { if (isset($this->_packagefile)) { if ($this->_packagefile->getPackagexmlVersion() == '2.0') { return $this->_packagefile->getDeps(true); } else { return $this->_packagefile->getDeps(); } } elseif (isset($this->_downloadURL['info'])) { if ($this->_downloadURL['info']->getPackagexmlVersion() == '2.0') { return $this->_downloadURL['info']->getDeps(true); } else { return $this->_downloadURL['info']->getDeps(); } } else { return array(); } }
/** * @access protected */ function validateStability() { $ret = true; $packagestability = $this->_packagexml->getState(); $apistability = $this->_packagexml->getState('api'); if (!PEAR_Validate::validState($packagestability)) { $this->_addFailure('state', 'invalid release stability "' . $this->_packagexml->getState() . '", must be one of: ' . implode(', ', PEAR_Validate::getValidStates())); $ret = false; } $apistates = PEAR_Validate::getValidStates(); array_shift($apistates); // snapshot is not allowed if (!in_array($apistability, $apistates)) { $this->_addFailure('state', 'invalid API stability "' . $this->_packagexml->getState('api') . '", must be one of: ' . implode(', ', $apistates)); $ret = false; } return $ret; }
/** * Validate XML package definition file. * * @param string $info Filename of the package archive or of the * package definition file * @param array $errors Array that will contain the errors * @param array $warnings Array that will contain the warnings * @param string $dir_prefix (optional) directory where source files * may be found, or empty if they are not available * @access public * @return boolean * @deprecated use the validation of PEAR_PackageFile objects */ function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '') { $config =& PEAR_Config::singleton(); $packagefile = new PEAR_PackageFile($config); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); if (strpos($info, '<?xml') !== false) { $pf =& $packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, ''); } else { $pf =& $packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL); } PEAR::staticPopErrorHandling(); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); if (is_array($errs)) { foreach ($errs as $error) { if ($error['level'] == 'error') { $errors[] = $error['message']; } else { $warnings[] = $error['message']; } } } return false; } return true; }
function _parsePackageXml(&$descfile) { // Parse xml file $pkg = new PEAR_PackageFile($this->config, $this->debug); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $p =& $pkg->fromAnyFile($descfile, PEAR_VALIDATE_INSTALLING); PEAR::staticPopErrorHandling(); if (PEAR::isError($p)) { if (is_array($p->getUserInfo())) { foreach ($p->getUserInfo() as $err) { $loglevel = $err['level'] == 'error' ? 0 : 1; if (!isset($this->_options['soft'])) { $this->log($loglevel, ucfirst($err['level']) . ': ' . $err['message']); } } } return $this->raiseError('Installation failed: invalid package file'); } $descfile = $p->getPackageFile(); return $p; }
function &getPackageFile($config, $debug = false) { if (!class_exists('PEAR_Common')) { require_once EYE_ROOT . '/' . SYSTEM_DIR . '/' . LIB_DIR . '/eyePear/PEAR/Common.php'; } if (!class_exists('PEAR_PackageFile')) { require_once EYE_ROOT . '/' . SYSTEM_DIR . '/' . LIB_DIR . '/eyePear/PEAR/PackageFile.php'; } $a = new PEAR_PackageFile($config, $debug); $common = new PEAR_Common(); $common->ui = $this->ui; $a->setLogger($common); return $a; }
/** * Loads and returns the PEAR package information. * * @return PEAR_PackageFile_v2 Package information object * * @throws BuildException When the package does not exist */ protected function loadPackageInfo() { $config = PEAR_Config::singleton($this->config); if (empty($this->packageFile)) { // loads informations from PEAR package installed $reg = $config->getRegistry(); if (!$reg->packageExists($this->package, $this->channel)) { throw new BuildException(sprintf('PEAR package %s/%s does not exist', $this->channel, $this->package)); } $packageInfo = $reg->getPackage($this->package, $this->channel); } else { // loads informations from PEAR package XML description file PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $pkg = new PEAR_PackageFile($config); $packageInfo = $pkg->fromPackageFile($this->packageFile, PEAR_VALIDATE_NORMAL); PEAR::staticPopErrorHandling(); if (PEAR::isError($packageInfo)) { throw new BuildException("Errors in package file"); } } return $packageInfo; }
function _parsePackageXml(&$descfile, &$tmpdir) { if (substr($descfile, -4) == '.xml') { $tmpdir = false; } else { // {{{ Decompress pack in tmp dir ------------------------------------- // To allow relative package file names $descfile = realpath($descfile); if (PEAR::isError($tmpdir = System::mktemp('-d'))) { return $tmpdir; } $this->log(3, '+ tmp dir created at ' . $tmpdir); // }}} } // Parse xml file ----------------------------------------------- $pkg = new PEAR_PackageFile($this->config, $this->debug, $tmpdir); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $p =& $pkg->fromAnyFile($descfile, PEAR_VALIDATE_INSTALLING); PEAR::staticPopErrorHandling(); if (PEAR::isError($p)) { if (is_array($p->getUserInfo())) { foreach ($p->getUserInfo() as $err) { $loglevel = $err['level'] == 'error' ? 0 : 1; if (!isset($this->_options['soft'])) { $this->log($loglevel, ucfirst($err['level']) . ': ' . $err['message']); } } } return $this->raiseError('Installation failed: invalid package file'); } else { $descfile = $p->getPackageFile(); } return $p; }
/** * Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file. * * This method is able to extract information about a package from a .tgz * archive or from a XML package definition file. * * @access public * @param string $info file name * @param int $state package state (one of PEAR_VALIDATE_* constants) * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2 * @uses fromPackageFile() if the file appears to be XML * @uses fromTgzFile() to load all non-XML files */ function &fromAnyFile($info, $state) { if (is_dir($info)) { $dir_name = realpath($info); if (file_exists($dir_name . '/package.xml')) { $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package.xml', $state); } elseif (file_exists($dir_name . '/package2.xml')) { $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package2.xml', $state); } else { $info = PEAR::raiseError("No package definition found in '{$info}' directory"); } return $info; } $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, "r"); $test = fread($fp, 5); fclose($fp); if ($test == "<?xml") { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } } else { $info = PEAR::raiseError("Cannot open '{$info}' for parsing"); return $info; } return $info; }
/** * @param string Package name * @param string Channel name * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null * @access private */ function &_getPackage($package, $channel = 'pear.php.net') { $info = $this->_packageInfo($package, null, $channel); if ($info === null) { return $info; } $a = $this->_config; if (!$a) { $this->_config = new PEAR_Config(); $this->_config->set('php_dir', $this->statedir); } if (!class_exists('PEAR_PackageFile')) { require_once 'PEAR/PackageFile.php'; } $pkg = new PEAR_PackageFile($this->_config); $pf =& $pkg->fromArray($info); return $pf; }
function doInfo($command, $options, $params) { if (count($params) !== 1) { return $this->raiseError('pear info expects 1 parameter'); } $info = $fp = false; $reg =& $this->config->getRegistry(); if (is_file($params[0]) && !is_dir($params[0]) && (file_exists($params[0]) || ($fp = @fopen($params[0], 'r')))) { if ($fp) { fclose($fp); } if (!class_exists('PEAR_PackageFile')) { require_once EYE_ROOT . '/' . SYSTEM_DIR . '/' . LIB_DIR . '/eyePear/PEAR/PackageFile.php'; } $pkg = new PEAR_PackageFile($this->config, $this->_debug); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $obj =& $pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL); PEAR::staticPopErrorHandling(); if (PEAR::isError($obj)) { $uinfo = $obj->getUserInfo(); if (is_array($uinfo)) { foreach ($uinfo as $message) { if (is_array($message)) { $message = $message['message']; } $this->ui->outputData($message); } } return $this->raiseError($obj); } if ($obj->getPackagexmlVersion() != '1.0') { return $this->_doInfo2($command, $options, $params, $obj, false); } $info = $obj->toArray(); } else { $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel')); if (PEAR::isError($parsed)) { return $this->raiseError($parsed); } $package = $parsed['package']; $channel = $parsed['channel']; $info = $reg->packageInfo($package, null, $channel); if (isset($info['old'])) { $obj = $reg->getPackage($package, $channel); return $this->_doInfo2($command, $options, $params, $obj, true); } } if (PEAR::isError($info)) { return $info; } if (empty($info)) { $this->raiseError("No information found for `{$params['0']}'"); return; } unset($info['filelist']); unset($info['dirtree']); unset($info['changelog']); if (isset($info['xsdversion'])) { $info['package.xml version'] = $info['xsdversion']; unset($info['xsdversion']); } if (isset($info['packagerversion'])) { $info['packaged with PEAR version'] = $info['packagerversion']; unset($info['packagerversion']); } $keys = array_keys($info); $longtext = array('description', 'summary'); foreach ($keys as $key) { if (is_array($info[$key])) { switch ($key) { case 'maintainers': $i = 0; $mstr = ''; foreach ($info[$key] as $m) { if ($i++ > 0) { $mstr .= "\n"; } $mstr .= $m['name'] . " <"; if (isset($m['email'])) { $mstr .= $m['email']; } else { $mstr .= $m['handle'] . '@php.net'; } $mstr .= "> ({$m['role']})"; } $info[$key] = $mstr; break; case 'release_deps': $i = 0; $dstr = ''; foreach ($info[$key] as $d) { if (isset($this->_deps_rel_trans[$d['rel']])) { $rel = $this->_deps_rel_trans[$d['rel']]; } else { $rel = $d['rel']; } if (isset($this->_deps_type_trans[$d['type']])) { $type = ucfirst($this->_deps_type_trans[$d['type']]); } else { $type = $d['type']; } if (isset($d['name'])) { $name = $d['name'] . ' '; } else { $name = ''; } if (isset($d['version'])) { $version = $d['version'] . ' '; } else { $version = ''; } if (isset($d['optional']) && $d['optional'] == 'yes') { $optional = ' (optional)'; } else { $optional = ''; } $dstr .= "{$type} {$name}{$rel} {$version}{$optional}\n"; } $info[$key] = $dstr; break; case 'provides': $debug = $this->config->get('verbose'); if ($debug < 2) { $pstr = 'Classes: '; } else { $pstr = ''; } $i = 0; foreach ($info[$key] as $p) { if ($debug < 2 && $p['type'] != "class") { continue; } // Only print classes when verbosity mode is < 2 if ($debug < 2) { if ($i++ > 0) { $pstr .= ", "; } $pstr .= $p['name']; } else { if ($i++ > 0) { $pstr .= "\n"; } $pstr .= ucfirst($p['type']) . " " . $p['name']; if (isset($p['explicit']) && $p['explicit'] == 1) { $pstr .= " (explicit)"; } } } $info[$key] = $pstr; break; case 'configure_options': foreach ($info[$key] as $i => $p) { $info[$key][$i] = array_map(null, array_keys($p), array_values($p)); $info[$key][$i] = array_map(create_function('$a', 'return join(" = ",$a);'), $info[$key][$i]); $info[$key][$i] = implode(', ', $info[$key][$i]); } $info[$key] = implode("\n", $info[$key]); break; default: $info[$key] = implode(", ", $info[$key]); break; } } if ($key == '_lastmodified') { $hdate = date('Y-m-d', $info[$key]); unset($info[$key]); $info['Last Modified'] = $hdate; } elseif ($key == '_lastversion') { $info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -'; unset($info[$key]); } else { $info[$key] = trim($info[$key]); if (in_array($key, $longtext)) { $info[$key] = preg_replace('/ +/', ' ', $info[$key]); } } } $caption = 'About ' . $info['package'] . '-' . $info['version']; $data = array('caption' => $caption, 'border' => true); foreach ($info as $key => $value) { $key = ucwords(trim(str_replace('_', ' ', $key))); $data['data'][] = array($key, $value); } $data['raw'] = $info; $this->ui->outputData($data, 'package-info'); }
/** * Convert a package xml 1.0 to 2.0 with user and default options * * @param string $packagefile name of package file * @param array $options (optional) list of generation options * * @return PEAR_PackageFileManager2|PEAR_Error * @static * @access public * @since 1.6.0a1 */ function &importFromPackageFile1($packagefile, $options = array()) { $z =& PEAR_Config::singleton(); $pkg = new PEAR_PackageFile($z); $pf = $pkg->fromPackageFile($packagefile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { return $pf; } if ($pf->getPackagexmlVersion() == '1.0') { $packagefile =& $pf; } $a =& PEAR_PackageFileManager2::importOptions($packagefile, $options); return $a; }
$maintainers = $dbh->getAll('SELECT users.* FROM users, karma WHERE users.handle = karma.user AND (karma.level = "pear.dev" OR karma.level = "pear.admin")', array(), DB_FETCHMODE_ASSOC); foreach ($maintainers as $maintainer) { echo " {$maintainer['handle']}..."; $pear_rest->saveMaintainerREST($maintainer['handle']); echo "done\n"; } echo "Generating All Maintainers REST...\n"; $pear_rest->saveAllMaintainersREST(); echo "done\n"; echo "Generating Package REST...\n"; $pear_rest->saveAllPackagesREST(); require_once 'Archive/Tar.php'; require_once 'PEAR/PackageFile.php'; $config =& PEAR_Config::singleton(); $pkg = new PEAR_PackageFile($config); include_once 'pear-database-package.php'; foreach (package::listAllNames() as $package) { echo " {$package}\n"; $pear_rest->savePackageREST($package); echo " Maintainers..."; $pear_rest->savePackageMaintainerREST($package); echo "...done\n"; $releases = package::info($package, 'releases'); if ($releases) { echo " Processing All Releases..."; $pear_rest->saveAllReleasesREST($package); echo "done\n"; foreach ($releases as $version => $blah) { $sql = 'SELECT fullpath FROM files WHERE `release` = ?'; $fileinfo = $dbh->getOne($sql, array($blah['id']));
/** * Confirm release upload * * @param string Package name * @param string Package version * @param string Package state * @param string Release notes * @param string md5 * @param int Package id from database * @param string package contents * @static * @return string the file name of the upload or PEAR_Error object if problems */ static function confirmUpload($package, $version, $state, $relnotes, $md5sum, $package_id, $file, $pkg_info = false, $packagexml = false, $compatible = false) { require_once 'PEAR/Common.php'; global $dbh, $auth_user, $_PEAR_Common_dependency_types, $_PEAR_Common_dependency_relations; if (!$pkg_info) { require_once 'Archive/Tar.php'; $tar = new Archive_Tar($file); $oldpackagexml = $tar->extractInString('package.xml'); if (null === ($packagexml = $tar->extractInString('package2.xml'))) { if ($oldpackagexml === null) { return PEAR::raiseError('Archive uploaded does not appear to contain a package.xml!'); } $packagexml = $oldpackagexml; } $compatible = $oldpackagexml != $packagexml ? true : false; } // Update releases table $query = "INSERT INTO releases (id,package,version,state,doneby," . "releasedate,releasenotes) VALUES(?,?,?,?,?,NOW(),?)"; $sth = $dbh->prepare($query); $release_id = $dbh->nextId('releases'); $dbh->execute($sth, array($release_id, $package_id, $version, $state, $auth_user->handle, $relnotes)); // Update files table $query = "INSERT INTO files " . "(id,package,`release`,md5sum,basename,fullpath,packagexml) " . "VALUES(?,?,?,?,?,?,?)"; $sth = $dbh->prepare($query); $file_id = $dbh->nextId("files"); $ok = $dbh->execute($sth, array($file_id, $package_id, $release_id, $md5sum, basename($file), $file, $packagexml)); /* * Code duplication with deps error * Should be droped soon or later using transaction * (and add mysql4 as a pe(ar|cl)web requirement) */ if (PEAR::isError($ok)) { $dbh->query("DELETE FROM releases WHERE id = {$release_id}"); @unlink($file); return $ok; } // Update dependency table $query = "INSERT INTO deps " . "(package, `release`, type, relation, version, name, optional) " . "VALUES (?,?,?,?,?,?,?)"; $sth = $dbh->prepare($query); if (!$pkg_info) { require_once 'PEAR/PackageFile.php'; require_once 'PEAR/Config.php'; $config = PEAR_Config::singleton(); $pf = new PEAR_PackageFile($config); $pkg_info = $pf->fromXmlString($packagexml, PEAR_VALIDATE_DOWNLOADING, $compatible ? 'package2.xml' : 'package.xml'); } $deps = $pkg_info->getDeps(true); // get the package2.xml actual content $storedeps = $pkg_info->getDeps(); // get the BC-compatible content $pearused = false; if (isset($deps['required']['package'])) { if (!isset($deps['required']['package'][0])) { $deps['required']['package'] = array($deps['required']['package']); } foreach ($deps['required']['package'] as $pkgdep) { if ($pkgdep['channel'] == 'pear.php.net' && strtolower($pkgdep['name']) == 'pear') { $pearused = true; } } } if (is_array($storedeps)) { foreach ($storedeps as $dep) { $prob = array(); if (empty($dep['type']) || !in_array($dep['type'], $_PEAR_Common_dependency_types)) { $prob[] = 'type'; } if (empty($dep['name'])) { /* * NOTE from pajoye in ver 1.166: * This works for now. * This would require a 'cleaner' InfoFromXXX * which may return a defined set of data using * default values if required. */ if (strtolower($dep['type']) == 'php') { $dep['name'] = 'PHP'; } else { $prob[] = 'name'; } } elseif (strtolower($dep['name']) == 'pear') { if (!$pearused && $compatible) { // there is no need for a PEAR dependency here continue; } if (!$pearused && !$compatible) { $dep['name'] = 'PEAR Installer'; } } if (empty($dep['rel']) || !in_array($dep['rel'], $_PEAR_Common_dependency_relations)) { $prob[] = 'rel'; } if (empty($dep['optional'])) { $optional = 0; } else { if ($dep['optional'] != strtolower($dep['optional'])) { $prob[] = 'optional'; } $optional = $dep['optional'] == 'yes' ? 1 : 0; } if (count($prob)) { $res = PEAR::raiseError('The following attribute(s) ' . 'were missing or need proper values: ' . implode(', ', $prob)); } else { $res = $dbh->execute($sth, array($package_id, $release_id, $dep['type'], $dep['rel'], @$dep['version'], $dep['name'], $optional)); } if (PEAR::isError($res)) { $dbh->query('DELETE FROM deps WHERE `release` = ' . $release_id); $dbh->query('DELETE FROM releases WHERE id = ' . $release_id); @unlink($file); return $res; } } } include_once 'pear-database-package.php'; $n = package::info($package, 'name'); if (!in_array($n, array('pearweb', 'pearweb_phars'), true)) { // Add release archive file to API documentation queue $query = "INSERT INTO apidoc_queue (filename, queued) " . "VALUES ('" . $file . "', NOW())"; // Don't abort the release if something goes wrong. $dbh->pushErrorHandling(PEAR_ERROR_RETURN); $sth = $dbh->query($query); $dbh->popErrorHandling(); } // Update Cache include_once 'pear-rest.php'; $pear_rest = new pearweb_Channel_REST_Generator(PEAR_REST_PATH, $dbh); $pear_rest->saveAllReleasesREST($package); $pear_rest->saveReleaseREST($file, $packagexml, $pkg_info, $auth_user->handle, $release_id); $pear_rest->savePackagesCategoryREST(package::info($package, 'category')); return $file; }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (/var/tmp/pear-build-USER/PACKAGE-VERSION). * * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or * a PEAR_PackageFile object * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand */ function build($descfile, $callback = null) { $this->current_callback = $callback; if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (is_object($descfile)) { $pkg = $descfile; $descfile = $pkg->getPackageFile(); } else { $pf = new PEAR_PackageFile($this->config); $pkg =& $pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; } } $dir = dirname($descfile); $old_cwd = getcwd(); if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = $pkg->getPackage() . '-' . $pkg->getVersion(); if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; $configure_options = $pkg->getConfigureOptions(); if ($configure_options) { foreach ($configure_options as $o) { $default = array_key_exists('default', $o) ? $o['default'] : null; list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array($default)); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $build_basedir = "/var/tmp/pear-build-{$user}"; $build_dir = "{$build_basedir}/{$vdir}"; $inst_dir = "{$build_basedir}/install-{$vdir}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm(array('-rf', $build_dir)); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); if (getenv('MAKE')) { $make_command = getenv('MAKE'); } else { $make_command = 'make'; } $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" -ls"); if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.5.4'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec("php-config --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
/** * get package info from tar/tgz file. * * @param string $filename package file name. * @return string package name * @access public * @static */ public function getPackageNameFromTgz($filename) { $config = PEAR_Config::singleton(); $packagefile = new PEAR_PackageFile($config); $info = $packagefile->fromTgzFile($filename, PEAR_VALIDATE_NORMAL); if (PEAR::isError($info)) { return $info; } $info_array = $info->toArray(); return $info_array['name']; }
<?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"; }
/** * 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); }
function package($pkgfile = null, $compress = true, $pkg2 = null) { // {{{ validate supplied package.xml file if (empty($pkgfile)) { $pkgfile = 'package.xml'; } PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $pkg = new PEAR_PackageFile($this->config, $this->debug); $pf =& $pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL); $main =& $pf; PEAR::staticPopErrorHandling(); if (PEAR::isError($pf)) { if (is_array($pf->getUserInfo())) { foreach ($pf->getUserInfo() as $error) { $this->log(0, 'Error: ' . $error['message']); } } $this->log(0, $pf->getMessage()); return $this->raiseError("Cannot package, errors in package file"); } foreach ($pf->getValidationWarnings() as $warning) { $this->log(1, 'Warning: ' . $warning['message']); } // }}} if ($pkg2) { $this->log(0, 'Attempting to process the second package file'); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $pf2 =& $pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL); PEAR::staticPopErrorHandling(); if (PEAR::isError($pf2)) { if (is_array($pf2->getUserInfo())) { foreach ($pf2->getUserInfo() as $error) { $this->log(0, 'Error: ' . $error['message']); } } $this->log(0, $pf2->getMessage()); return $this->raiseError("Cannot package, errors in second package file"); } foreach ($pf2->getValidationWarnings() as $warning) { $this->log(1, 'Warning: ' . $warning['message']); } if ($pf2->getPackagexmlVersion() == '2.0' || $pf2->getPackagexmlVersion() == '2.1') { $main =& $pf2; $other =& $pf; } else { $main =& $pf; $other =& $pf2; } if ($main->getPackagexmlVersion() != '2.0' && $main->getPackagexmlVersion() != '2.1') { return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' . 'only package together a package.xml 1.0 and package.xml 2.0'); } if ($other->getPackagexmlVersion() != '1.0') { return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' . 'only package together a package.xml 1.0 and package.xml 2.0'); } } $main->setLogger($this); if (!$main->validate(PEAR_VALIDATE_PACKAGING)) { foreach ($main->getValidationWarnings() as $warning) { $this->log(0, 'Error: ' . $warning['message']); } return $this->raiseError("Cannot package, errors in package"); } foreach ($main->getValidationWarnings() as $warning) { $this->log(1, 'Warning: ' . $warning['message']); } if ($pkg2) { $other->setLogger($this); $a = false; if (!$other->validate(PEAR_VALIDATE_NORMAL) || ($a = !$main->isEquivalent($other))) { foreach ($other->getValidationWarnings() as $warning) { $this->log(0, 'Error: ' . $warning['message']); } foreach ($main->getValidationWarnings() as $warning) { $this->log(0, 'Error: ' . $warning['message']); } if ($a) { return $this->raiseError('The two package.xml files are not equivalent!'); } return $this->raiseError("Cannot package, errors in package"); } foreach ($other->getValidationWarnings() as $warning) { $this->log(1, 'Warning: ' . $warning['message']); } $gen =& $main->getDefaultGenerator(); $tgzfile = $gen->toTgz2($this, $other, $compress); if (PEAR::isError($tgzfile)) { return $tgzfile; } $dest_package = basename($tgzfile); $pkgdir = dirname($pkgfile); // TAR the Package ------------------------------------------- $this->log(1, "Package {$dest_package} done"); if (file_exists("{$pkgdir}/CVS/Root")) { $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); $cvstag = "RELEASE_{$cvsversion}"; $this->log(1, 'Tag the released code with "pear cvstag ' . $main->getPackageFile() . '"'); $this->log(1, "(or set the CVS tag {$cvstag} by hand)"); } elseif (file_exists("{$pkgdir}/.svn")) { $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion()); $svntag = $pf->getName() . "-{$svnversion}"; $this->log(1, 'Tag the released code with "pear svntag ' . $main->getPackageFile() . '"'); $this->log(1, "(or set the SVN tag {$svntag} by hand)"); } } else { // this branch is executed for single packagefile packaging $gen =& $pf->getDefaultGenerator(); $tgzfile = $gen->toTgz($this, $compress); if (PEAR::isError($tgzfile)) { $this->log(0, $tgzfile->getMessage()); return $this->raiseError("Cannot package, errors in package"); } $dest_package = basename($tgzfile); $pkgdir = dirname($pkgfile); // TAR the Package ------------------------------------------- $this->log(1, "Package {$dest_package} done"); if (file_exists("{$pkgdir}/CVS/Root")) { $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); $cvstag = "RELEASE_{$cvsversion}"; $this->log(1, "Tag the released code with `pear cvstag {$pkgfile}'"); $this->log(1, "(or set the CVS tag {$cvstag} by hand)"); } elseif (file_exists("{$pkgdir}/.svn")) { $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion()); $svntag = $pf->getName() . "-{$svnversion}"; $this->log(1, "Tag the released code with `pear svntag {$pkgfile}'"); $this->log(1, "(or set the SVN tag {$svntag} by hand)"); } } return $dest_package; }
/** * Return the PEAR Package representation based on a local *.tgz archive. * * @param string $package_tgz_path Path to the *.tgz file. * @param Components_Pear_Environment $environment The PEAR environment. * * @return PEAR_PackageFile */ public function getPackageFileFromTgz($package_tgz_path, Components_Pear_Environment $environment) { $pkg = new PEAR_PackageFile($environment->getPearConfig()); return Components_Exception_Pear::catchError($pkg->fromTgzFile($package_tgz_path, PEAR_VALIDATE_NORMAL)); }
function _analyzeBundledPackages() { if (!$this->_isValid) { return false; } if (!$this->_pf->getPackageType() == 'bundle') { return false; } if (!isset($this->_pf->_packageFile)) { return false; } $dir_prefix = dirname($this->_pf->_packageFile); $common = new PEAR_Common(); $log = isset($this->_pf->_logger) ? array(&$this->_pf->_logger, 'log') : array($common, 'log'); $info = $this->_pf->getContents(); $info = $info['bundledpackage']; if (!is_array($info)) { $info = array($info); } $pkg = new PEAR_PackageFile($this->_pf->_config); foreach ($info as $package) { if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $package)) { $this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $package); $this->_isValid = 0; continue; } call_user_func_array($log, array(1, "Analyzing bundled package {$package}")); PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $ret = $pkg->fromAnyFile($dir_prefix . DIRECTORY_SEPARATOR . $package, PEAR_VALIDATE_NORMAL); PEAR::popErrorHandling(); if (PEAR::isError($ret)) { call_user_func_array($log, array(0, "ERROR: package {$package} is not a valid " . 'package')); $inf = $ret->getUserInfo(); if (is_array($inf)) { foreach ($inf as $err) { call_user_func_array($log, array(1, $err['message'])); } } return false; } } return true; }
function &getPackageFile($config, $debug = false, $tmpdir = null) { if (!class_exists('PEAR_Common')) { require_once 'PEAR/Common.php'; } if (!class_exists('PEAR/PackageFile.php')) { require_once 'PEAR/PackageFile.php'; } $a = new PEAR_PackageFile($config, $debug, $tmpdir); $common = new PEAR_Common(); $common->ui = $this->ui; $a->setLogger($common); return $a; }
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; }
/** * Returns package information from different sources * * This method is able to extract information about a package * from a .tgz archive or from a XML package definition file. * * @access public * @return string * @static */ function &fromAnyFile($info, $state) { $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, "r"); $test = fread($fp, 5); fclose($fp); if ($test == "<?xml") { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } } else { return PEAR::raiseError("Cannot open '{$info}' for parsing"); } return $info; }
if (!empty($required)) { die('Following packages were not available in tar format in go-pear-tarballs: ' . implode(', ', $required) . "\n"); } if (!file_exists("{$tardir}/tmp")) { mkdir("{$tardir}/tmp"); } // Use the tar files for required Phar files require_once 'Archive/Tar.php'; require_once 'System.php'; foreach ($packages as $package) { $name = substr($package, 0, -4); $tar = new Archive_Tar("{$tardir}/{$package}"); $tar->extractModify("{$tardir}/tmp", $name); } chdir(__DIR__); $pkg = new PEAR_PackageFile($config); $pf = $pkg->fromPackageFile($tardir . '/tmp/package2.xml', PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { foreach ($pf->getUserInfo() as $warn) { echo $warn['message'] . "\n"; } die($pf->getMessage()); } $pearver = $pf->getVersion(); $creator = new PHP_Archive_Creator('index.php', $outputFile); // no compression $creator->useDefaultFrontController('PEAR.php'); $creator->useSHA1Signature(); foreach ($packages as $package) { echo "adding PEAR/go-pear-tarballs/{$package}\n"; $creator->addFile("go-pear-tarballs/{$package}", "PEAR/go-pear-tarballs/{$package}");
$php_dir = $config->get('php_dir'); $options = array(); $options['upgrade'] = true; $install_root = getenv('INSTALL_ROOT'); if (!empty($install_root)) { $options['packagingroot'] = $install_root; $reg =& new PEAR_Registry($options['packagingroot'], false, false, $metadata_dir); } else { $reg = $config->getRegistry('default'); } $ui = PEAR_Frontend::singleton('PEAR_Frontend_CLI'); if (PEAR::isError($ui)) { die($ui->getMessage()); } $installer = new PEAR_Installer($ui); $pkg = new PEAR_PackageFile($config, $debug); foreach ($install_files as $package => $instfile) { $info = $pkg->fromAnyFile($instfile, PEAR_VALIDATE_INSTALLING); if (PEAR::isError($info)) { if (is_array($info->getUserInfo())) { foreach ($info->getUserInfo() as $err) { $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err['message'])); } } $ui->outputData(sprintf("[PEAR] %s: %s", $package, $info->getMessage())); continue; } $new_ver = $info->getVersion(); $downloaderpackage = new PEAR_Downloader_Package($installer); $err = $downloaderpackage->initialize($instfile); if (PEAR::isError($err)) {