Copyright 2010-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Gunnar Wrobel (wrobel@pardus.de)
Inheritance: extends Horde_Exception_Pear
Exemplo n.º 1
0
 /**
  * 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));
 }
Exemplo n.º 2
0
 public function run()
 {
     $options = $this->_config->getOptions();
     if (!empty($options['destination'])) {
         $environment = realpath($options['destination']);
         if (!$environment) {
             $environment = $options['destination'];
         }
     } else {
         throw new Components_Exception('You MUST specify the path to the installation environment with the --destination flag!');
     }
     if (empty($options['pearrc'])) {
         $options['pearrc'] = $environment . '/pear.conf';
         $this->_output->info(sprintf('Undefined path to PEAR configuration file (--pearrc). Assuming %s for this installation.', $options['pearrc']));
     }
     if (empty($options['horde_dir'])) {
         $options['horde_dir'] = $environment;
         $this->_output->info(sprintf('Undefined path to horde web root (--horde-dir). Assuming %s for this installation.', $options['horde_dir']));
     }
     if (!empty($options['instructions'])) {
         if (!file_exists($options['instructions'])) {
             throw new Components_Exception(sprintf('Instructions file "%s" is missing!', $options['instructions']));
         }
         $lines = explode("\n", file_get_contents($options['instructions']));
         $result = array();
         foreach ($lines as $line) {
             $trimmed = trim($line);
             if (empty($trimmed) || preg_match('/^#/', $trimmed)) {
                 continue;
             }
             preg_match('/(.*):(.*)/', $trimmed, $matches);
             $id = $matches[1];
             $c_options = $matches[2];
             foreach (explode(',', $c_options) as $option) {
                 $result[trim($id)][trim($option)] = true;
             }
         }
         $options['instructions'] = $result;
     }
     $target = $this->_factory->createEnvironment($environment, $options['pearrc']);
     $target->setResourceDirectories($options);
     //@todo: fix role handling
     $target->provideChannel('pear.horde.org', $options);
     $target->getPearConfig()->setChannels(array('pear.horde.org', true));
     $target->getPearConfig()->set('horde_dir', $options['horde_dir'], 'user', 'pear.horde.org');
     Components_Exception_Pear::catchError($target->getPearConfig()->store());
     $this->_installer->installTree($target, $this->_config->getComponent(), $options);
 }
Exemplo n.º 3
0
 /**
  * Place the component source archive at the specified location.
  *
  * @param string $destination The path to write the archive to.
  * @param array  $options     Options for the operation.
  *
  * @return array An array with at least [0] the path to the resulting
  *               archive, optionally [1] an array of error strings, and [2]
  *               PEAR output.
  */
 public function placeArchive($destination, $options = array())
 {
     if (!file_exists($this->getPackageXmlPath())) {
         throw new Components_Exception(sprintf('The component "%s" still lacks a package.xml file at "%s"!', $this->getName(), $this->getPackageXmlPath()));
     }
     if (empty($options['keep_version'])) {
         $version = preg_replace('/([.0-9]+).*/', '\\1dev' . strftime('%Y%m%d%H%M'), $this->getVersion());
     } else {
         $version = $this->getVersion();
     }
     $this->createDestination($destination);
     $package = $this->_getPackageFile();
     $pkg = $this->getFactory()->pear()->getPackageFile($this->getPackageXmlPath(), $package->getEnvironment());
     $pkg->_packageInfo['version']['release'] = $version;
     $pkg->setDate(date('Y-m-d'));
     $pkg->setTime(date('H:i:s'));
     if (isset($options['logger'])) {
         $pkg->setLogger($options['logger']);
     }
     $errors = array();
     ob_start();
     $old_dir = getcwd();
     chdir($destination);
     try {
         $result = Components_Exception_Pear::catchError($pkg->getDefaultGenerator()->toTgz(new PEAR_Common()));
     } catch (Components_Exception_Pear $e) {
         $errors[] = $e->getMessage();
         $errors[] = '';
         $result = false;
         foreach ($pkg->getValidationWarnings() as $error) {
             $errors[] = isset($error['message']) ? $error['message'] : 'Unknown Error';
         }
     }
     chdir($old_dir);
     $output = array($result, $errors);
     $output[] = ob_get_clean();
     return $output;
 }
Exemplo n.º 4
0
 /**
  * Exception handling.
  *
  * @param mixed $result The result to be checked for a PEAR_Error.
  *
  * @return mixed Returns the original result if it was no PEAR_Error.
  *
  * @throws Horde_Exception_Pear In case the result was a PEAR_Error.
  */
 public static function catchError($result)
 {
     self::$_class = __CLASS__;
     return parent::catchError($result);
 }
Exemplo n.º 5
0
 /**
  * Add a component to the environemnt.
  *
  * @param string $component The name of the component that should be
  *                          installed.
  * @param string $install   The package that should be installed.
  * @param array  $options   PEAR specific installation opions.
  * @param string $info      Installation details.
  * @param string $reason    Optional reason for adding the package.
  * @param array  $warnings  Optional warnings that should be displayed to
  *                          the user.
  *
  * @return NULL
  */
 public function addComponent($component, $install, $options, $info, $reason = '', $warnings = array())
 {
     $installer = $this->getInstallationHandler();
     $this->_output->ok(sprintf('About to add component %s%s', $component, $reason));
     if (!empty($warnings)) {
         foreach ($warnings as $warning) {
             $this->_output->warn($warnings);
         }
     }
     ob_start();
     Components_Exception_Pear::catchError($installer->doInstall('install', $options, $install));
     $this->_output->pear(ob_get_clean());
     $this->_output->ok(sprintf('Successfully added component %s%s%s', $component, $info, $reason));
 }