install() public method

Installs the files within the package file specified.
public install ( string | PEAR_Downloader_Package $pkgfile, array $options = [] ) : array | PEAR_Error
$pkgfile string | PEAR_Downloader_Package path to the package file, or a pre-initialized packagefile object
$options array 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
Example #1
0
 function doMakeRPM($command, $options, $params)
 {
     if (sizeof($params) != 1) {
         return $this->raiseError("bad parameter(s), try \"help {$command}\"");
     }
     if (!file_exists($params[0])) {
         return $this->raiseError("file does not exist: {$params['0']}");
     }
     include_once "Archive/Tar.php";
     include_once "PEAR/Installer.php";
     include_once "System.php";
     $tar = new Archive_Tar($params[0]);
     $tmpdir = System::mktemp('-d pear2rpm');
     $instroot = System::mktemp('-d pear2rpm');
     $tmp = $this->config->get('verbose');
     $this->config->set('verbose', 0);
     $installer = new PEAR_Installer($this->ui);
     $info = $installer->install($params[0], array('installroot' => $instroot, 'nodeps' => true));
     $pkgdir = "{$info['package']}-{$info['version']}";
     $info['rpm_xml_dir'] = '/var/lib/pear';
     $this->config->set('verbose', $tmp);
     if (!$tar->extractList("package.xml", $tmpdir, $pkgdir)) {
         return $this->raiseError("failed to extract {$params['0']}");
     }
     if (!file_exists("{$tmpdir}/package.xml")) {
         return $this->raiseError("no package.xml found in {$params['0']}");
     }
     if (isset($options['spec-template'])) {
         $spec_template = $options['spec-template'];
     } else {
         $spec_template = $this->config->get('data_dir') . '/PEAR/template.spec';
     }
     if (isset($options['rpm-pkgname'])) {
         $rpm_pkgname_format = $options['rpm-pkgname'];
     } else {
         $rpm_pkgname_format = "PEAR::%s";
     }
     $info['extra_headers'] = '';
     $info['doc_files'] = '';
     $info['files'] = '';
     $info['rpm_package'] = sprintf($rpm_pkgname_format, $info['package']);
     $srcfiles = 0;
     foreach ($info['filelist'] as $name => $attr) {
         if ($attr['role'] == 'doc') {
             $info['doc_files'] .= " {$name}";
             // Map role to the rpm vars
         } else {
             $c_prefix = '%{_libdir}/php/pear';
             switch ($attr['role']) {
                 case 'php':
                     $prefix = $c_prefix;
                     break;
                 case 'ext':
                     $prefix = '%{_libdir}/php';
                     break;
                     // XXX good place?
                 // XXX good place?
                 case 'src':
                     $srcfiles++;
                     $prefix = '%{_includedir}/php';
                     break;
                     // XXX good place?
                 // XXX good place?
                 case 'test':
                     $prefix = "{$c_prefix}/tests/" . $info['package'];
                     break;
                 case 'data':
                     $prefix = "{$c_prefix}/data/" . $info['package'];
                     break;
                 case 'script':
                     $prefix = '%{_bindir}';
                     break;
             }
             $info['files'] .= "{$prefix}/{$name}\n";
         }
     }
     if ($srcfiles > 0) {
         include_once "OS/Guess.php";
         $os = new OS_Guess();
         $arch = $os->getCpu();
     } else {
         $arch = 'noarch';
     }
     $cfg = array('master_server', 'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'test_dir');
     foreach ($cfg as $k) {
         $info[$k] = $this->config->get($k);
     }
     $info['arch'] = $arch;
     $fp = @fopen($spec_template, "r");
     if (!$fp) {
         return $this->raiseError("could not open RPM spec file template {$spec_template}: {$php_errormsg}");
     }
     $spec_contents = preg_replace('/@([a-z0-9_-]+)@/e', '$info["\\1"]', fread($fp, filesize($spec_template)));
     fclose($fp);
     $spec_file = "{$info['rpm_package']}-{$info['version']}.spec";
     $wp = fopen($spec_file, "wb");
     if (!$wp) {
         return $this->raiseError("could not write RPM spec file {$spec_file}: {$php_errormsg}");
     }
     fwrite($wp, $spec_contents);
     fclose($wp);
     $this->ui->outputData("Wrote RPM spec file {$spec_file}", $command);
     return true;
 }
 /**
  * Installs a plugin
  *
  * @see installPlugin()
  */
 protected function doInstallPlugin($plugin, $options = array())
 {
     $channel = isset($options['channel']) ? $options['channel'] : $this->environment->getConfig()->get('default_channel');
     $stability = isset($options['stability']) ? $options['stability'] : $this->environment->getConfig()->get('preferred_state', null, $channel);
     $version = isset($options['version']) ? $options['version'] : null;
     $isPackage = true;
     if (0 === strpos($plugin, 'http://') || file_exists($plugin)) {
         if (0 === strpos($plugin, 'http://plugins.symfony-project.')) {
             throw new sfPluginException("You try to install a symfony 1.0 plugin.\nPlease read the help message of this task to know how to install a plugin for the current version of symfony.");
         }
         $download = $plugin;
         $isPackage = false;
     } else {
         if (false !== strpos($plugin, '/')) {
             list($channel, $plugin) = explode('/', $plugin);
         }
     }
     $this->dispatcher->notify(new sfEvent($this, 'plugin.pre_install', array('channel' => $channel, 'plugin' => $plugin, 'is_package' => $isPackage)));
     if ($isPackage) {
         $this->environment->getRest()->setChannel($channel);
         if (!preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $plugin)) {
             throw new sfPluginException(sprintf('Plugin name "%s" is not a valid package name', $plugin));
         }
         if (!$version) {
             $version = $this->getPluginVersion($plugin, $stability);
         } else {
             if (!$this->isPluginCompatible($plugin, $version)) {
                 throw new sfPluginDependencyException(sprintf('Plugin "%s" in version "%s" is not compatible with the current application', $plugin, $version));
             }
         }
         if (!preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $version)) {
             throw new sfPluginException(sprintf('Plugin version "%s" is not a valid version', $version));
         }
         $existing = $this->environment->getRegistry()->packageInfo($plugin, 'version', $channel);
         if (version_compare($existing, $version) === 0) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Plugin is already installed')));
             return true;
         }
         // skip if the plugin is already installing and we are here through a dependency)
         if (isset($this->installing[$channel . '/' . $plugin])) {
             return true;
         }
         // convert the plugin package into a discrete download URL
         $download = $this->environment->getRest()->getPluginDownloadURL($plugin, $version, $stability);
         if (PEAR::isError($download)) {
             throw new sfPluginException(sprintf('Problem downloading the plugin "%s": %s', $plugin, $download->getMessage()));
         }
     }
     // download the plugin and install
     $class = $this->environment->getOption('downloader_base_class');
     $downloader = new $class($this, array('upgrade' => true), $this->environment->getConfig());
     $this->installing[$channel . '/' . $plugin] = true;
     if ($isPackage) {
         $this->checkPluginDependencies($plugin, $version, isset($options['install_deps']) ? (bool) $options['install_deps'] : false);
     }
     // download the actual URL to the plugin
     $downloaded = $downloader->download(array($download));
     if (PEAR::isError($downloaded)) {
         throw new sfPluginException(sprintf('Problem when downloading "%s": %s', $download, $downloaded->getMessage()));
     }
     $errors = $downloader->getErrorMsgs();
     if (count($errors)) {
         $err = array();
         foreach ($errors as $error) {
             $err[] = $error;
         }
         if (!count($downloaded)) {
             throw new sfPluginException(sprintf('Plugin "%s" installation failed: %s', $plugin, implode("\n", $err)));
         }
     }
     $pluginPackage = $downloaded[0];
     $installer = new PEAR_Installer($this);
     $installer->setOptions(array('upgrade' => true));
     $packages = array($pluginPackage);
     $installer->sortPackagesForInstall($packages);
     PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
     $err = $installer->setDownloadedPackages($packages);
     if (PEAR::isError($err)) {
         PEAR::staticPopErrorHandling();
         throw new sfPluginException($err->getMessage());
     }
     $info = $installer->install($pluginPackage, array('upgrade' => true));
     PEAR::staticPopErrorHandling();
     if (PEAR::isError($info)) {
         throw new sfPluginException(sprintf('Installation of "%s" plugin failed: %s', $plugin, $info->getMessage()));
     }
     if (is_array($info)) {
         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Installation successful for plugin "%s"', $plugin))));
         $this->dispatcher->notify(new sfEvent($this, 'plugin.post_install', array('channel' => $channel, 'plugin' => $plugin)));
         unset($this->installing[$channel . '/' . $plugin]);
         return true;
     } else {
         throw new sfPluginException(sprintf('Installation of "%s" plugin failed', $plugin));
     }
 }
Example #3
0
     continue;
 }
 $new_ver = $info->getVersion();
 $downloaderpackage = new PEAR_Downloader_Package($installer);
 $err = $downloaderpackage->initialize($instfile);
 if (PEAR::isError($err)) {
     $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
     continue;
 }
 if ($reg->packageExists($package)) {
     $old_ver = $reg->packageInfo($package, 'version');
     if (version_compare($new_ver, $old_ver, 'gt')) {
         $installer->setOptions($options);
         $dp = array($downloaderpackage);
         $installer->setDownloadedPackages($dp);
         $err = $installer->install($downloaderpackage, $options);
         if (PEAR::isError($err)) {
             $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
             continue;
         }
         $ui->outputData(sprintf("[PEAR] %-15s- upgraded:  %s", $package, $new_ver));
     } else {
         if ($force) {
             $options['force'] = true;
             $installer->setOptions($options);
             $dp = array($downloaderpackage);
             $installer->setDownloadedPackages($dp);
             $err = $installer->install($downloaderpackage, $options);
             if (PEAR::isError($err)) {
                 $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
                 continue;