function _initializeDepDB()
 {
     if (!isset($this->_dependencyDB)) {
         static $initializing = false;
         if (!$initializing) {
             $initializing = true;
             if (!$this->_config) {
                 // never used?
                 if (OS_WINDOWS) {
                     $file = 'pear.ini';
                 } else {
                     $file = '.pearrc';
                 }
                 $this->_config =& new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR . $file, '-');
                 // NO SYSTEM INI FILE
                 $this->_config->setRegistry($this);
                 $this->_config->set('php_dir', $this->install_dir);
             }
             $this->_dependencyDB =& PEAR_DependencyDB::singleton($this->_config);
             if (PEAR::isError($this->_dependencyDB)) {
                 // attempt to recover by removing the dep db
                 if (file_exists($this->_config->get('php_dir', null, 'pear.php.net') . DIRECTORY_SEPARATOR . '.depdb')) {
                     @unlink($this->_config->get('php_dir', null, 'pear.php.net') . DIRECTORY_SEPARATOR . '.depdb');
                 }
                 $this->_dependencyDB =& PEAR_DependencyDB::singleton($this->_config);
                 if (PEAR::isError($this->_dependencyDB)) {
                     echo $this->_dependencyDB->getMessage();
                     echo 'Unrecoverable error';
                     exit(1);
                 }
             }
             $initializing = false;
         }
     }
 }
示例#2
0
 public function getConfig()
 {
     if (!$this->_config) {
         $pear_dir = $this->getPearDir();
         $config = PEAR_Config::singleton($pear_dir . DS . 'pear.ini', '-');
         $config->set('auto_discover', 1);
         $config->set('cache_ttl', 60);
         #$config->set('preferred_state', 'beta');
         $config->set('bin_dir', $pear_dir);
         $config->set('php_dir', $pear_dir . DS . 'php');
         $config->set('download_dir', $pear_dir . DS . 'download');
         $config->set('temp_dir', $pear_dir . DS . 'temp');
         $config->set('data_dir', $pear_dir . DS . 'data');
         $config->set('cache_dir', $pear_dir . DS . 'cache');
         $config->set('test_dir', $pear_dir . DS . 'tests');
         $config->set('doc_dir', $pear_dir . DS . 'docs');
         foreach ($config->getKeys() as $key) {
             if (!(substr($key, 0, 5) === 'mage_' && substr($key, -4) === '_dir')) {
                 continue;
             }
             $config->set($key, preg_replace('#^\\.#', $this->getBaseDir(), $config->get($key)));
             #echo $key.' : '.$config->get($key).'<br>';
         }
         $reg = $this->getRegistry();
         $config->setRegistry($reg);
         PEAR_DependencyDB::singleton($config, $pear_dir . DS . 'php' . DS . '.depdb');
         PEAR_Frontend::setFrontendObject($this->getFrontend());
         #PEAR_Command::registerCommands(false, $pear_dir.DS.'php'.DS.'PEAR'.DS.'Command'.DS);
         $this->_config = $config;
     }
     return $this->_config;
 }
示例#3
0
 /**
  * Get a raw dependency database.  Calls setConfig() and assertDepsDB()
  * @param PEAR_Config
  * @param string|false full path to the dependency database, or false to use default
  * @return PEAR_DependencyDB|PEAR_Error
  */
 public static function &singleton(&$config, $depdb = false)
 {
     $phpdir = $config->get('php_dir', null, 'pear.php.net');
     if (!isset($GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'][$phpdir])) {
         $a = new PEAR_DependencyDB();
         $GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'][$phpdir] =& $a;
         $a->setConfig($config, $depdb);
         $e = $a->assertDepsDB();
         if (PEAR::isError($e)) {
             return $e;
         }
     }
     return $GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'][$phpdir];
 }
示例#4
0
 /**
  * validate a downloaded package against installed packages
  *
  * As of PEAR 1.4.3, this will only validate
  *
  * @param array|PEAR_Downloader_Package|PEAR_PackageFile_v1|PEAR_PackageFile_v2
  *              $pkg package identifier (either
  *                   array('package' => blah, 'channel' => blah) or an array with
  *                   index 'info' referencing an object)
  * @param PEAR_Downloader $dl
  * @param array $params full list of packages to install
  * @return true|PEAR_Error
  */
 function validatePackage($pkg, &$dl, $params = array())
 {
     if (is_array($pkg) && isset($pkg['info'])) {
         $deps = $this->_dependencydb->getDependentPackageDependencies($pkg['info']);
     } else {
         $deps = $this->_dependencydb->getDependentPackageDependencies($pkg);
     }
     $fail = false;
     if ($deps) {
         if (!class_exists('PEAR_Downloader_Package')) {
             require_once 'PEAR/Downloader/Package.php';
         }
         $dp =& new PEAR_Downloader_Package($dl);
         if (is_object($pkg)) {
             $dp->setPackageFile($pkg);
         } else {
             $dp->setDownloadURL($pkg);
         }
         PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
         foreach ($deps as $channel => $info) {
             foreach ($info as $package => $ds) {
                 foreach ($params as $packd) {
                     if (strtolower($packd->getPackage()) == strtolower($package) && $packd->getChannel() == $channel) {
                         $dl->log(3, 'skipping installed package check of "' . $this->_registry->parsedPackageNameToString(array('channel' => $channel, 'package' => $package), true) . '", version "' . $packd->getVersion() . '" will be ' . 'downloaded and installed');
                         continue 2;
                         // jump to next package
                     }
                 }
                 foreach ($ds as $d) {
                     $checker =& new PEAR_Dependency2($this->_config, $this->_options, array('channel' => $channel, 'package' => $package), $this->_state);
                     $dep = $d['dep'];
                     $required = $d['type'] == 'required';
                     $ret = $checker->_validatePackageDownload($dep, $required, array(&$dp));
                     if (is_array($ret)) {
                         $dl->log(0, $ret[0]);
                     } elseif (PEAR::isError($ret)) {
                         $dl->log(0, $ret->getMessage());
                         $fail = true;
                     }
                 }
             }
         }
         PEAR::popErrorHandling();
     }
     if ($fail) {
         return $this->raiseError('%s cannot be installed, conflicts with installed packages');
     }
     return true;
 }
示例#5
0
 function validatePackage($pkg, &$dl)
 {
     if (is_array($pkg) && isset($pkg['info'])) {
         $deps = $this->_dependencydb->getDependentPackageDependencies($pkg['info']);
     } else {
         $deps = $this->_dependencydb->getDependentPackageDependencies($pkg);
     }
     $fail = false;
     if ($deps) {
         if (!class_exists('PEAR_Downloader_Package')) {
             require_once 'PEAR/Downloader/Package.php';
         }
         $dp =& new PEAR_Downloader_Package($dl);
         if (is_object($pkg)) {
             $dp->setPackageFile($pkg);
         } else {
             $dp->setDownloadURL($pkg);
         }
         PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
         foreach ($deps as $channel => $info) {
             foreach ($info as $package => $ds) {
                 foreach ($ds as $d) {
                     $checker =& new PEAR_Dependency2($this->_config, $this->_options, array('channel' => $channel, 'package' => $package), $this->_state);
                     $dep = $d['dep'];
                     $required = $d['type'] == 'required';
                     $ret = $checker->_validatePackageDownload($dep, $required, array(&$dp));
                     if (is_array($ret)) {
                         $dl->log(0, $ret[0]);
                     } elseif (PEAR::isError($ret)) {
                         $dl->log(0, $ret->getMessage());
                         $fail = true;
                     }
                 }
             }
         }
         PEAR::popErrorHandling();
     }
     if ($fail) {
         return $this->raiseError('%s cannot be installed, conflicts with installed packages');
     }
     return true;
 }
示例#6
0
 /**
  * Sort a list of arrays of array(downloaded packagefilename) by dependency.
  *
  * It also removes duplicate dependencies
  * @param array an array of PEAR_PackageFile_v[1/2] objects
  * @return array|PEAR_Error array of array(packagefilename, package.xml contents)
  */
 function sortPackagesForUninstall(&$packages)
 {
     $this->_dependencyDB =& PEAR_DependencyDB::singleton($this->config);
     if (PEAR::isError($this->_dependencyDB)) {
         return $this->_dependencyDB;
     }
     usort($packages, array(&$this, '_sortUninstall'));
 }
示例#7
0
 function updatePackage2($info)
 {
     if (!is_object($info)) {
         return $this->updatePackage($info['package'], $info, $merge);
     }
     if (!$info->validate(PEAR_VALIDATE_DOWNLOADING)) {
         return false;
     }
     if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
         return $e;
     }
     $ret = $this->_updatePackage2($info);
     $this->_unlock();
     if ($ret) {
         $this->_dependencyDB->uninstallPackage($info);
         $this->_dependencyDB->installPackage($info);
     }
     return $ret;
 }
示例#8
0
 /**
  * Private constructor to initialize the instance
  * with the necessary data.
  *
  * @param string $baseDir The Magento base directory
  * @return void
  */
 public function __construct($baseDir)
 {
     // check if the passed Magento base directory exists
     if (!is_dir($baseDir)) {
         throw new Exception('Magento base directory ' . $baseDir . ' doesn\'t exists');
     }
     // load the PEAR directory for the Magento channel
     $pearDir = $baseDir . DS . 'downloader' . DS . 'pearlib';
     // check if the Magento PEAR directory exists
     if (!is_dir($pearDir)) {
         throw new Exception('Magento PEAR base directory ' . $pearDir . ' doesn\'t exists');
     }
     // load the registry
     $this->_registry = new PEAR_Registry($pearDir . DS . 'php');
     // initialize the configuration with the channels configuration file
     $this->_config = PEAR_Config::singleton($pearDir . DS . 'pear.ini', '-');
     // overwrite the configuration values
     $this->_config->set('auto_discover', 1);
     $this->_config->set('cache_ttl', 60);
     $this->_config->set('preferred_state', 'alpha');
     $this->_config->set('bin_dir', $pearDir);
     $this->_config->set('php_dir', $pearDir . DS . 'php');
     $this->_config->set('download_dir', $pearDir . DS . 'download');
     $this->_config->set('temp_dir', $pearDir . DS . 'temp');
     $this->_config->set('data_dir', $pearDir . DS . 'data');
     $this->_config->set('cache_dir', $pearDir . DS . 'cache');
     $this->_config->set('test_dir', $pearDir . DS . 'tests');
     $this->_config->set('doc_dir', $pearDir . DS . 'docs');
     // initialize the Magento specific settings
     foreach ($this->_config->getKeys() as $key) {
         if (!(substr($key, 0, 5) === 'mage_' && substr($key, -4) === '_dir')) {
             continue;
         }
         $this->_config->set($key, preg_replace('#^\\.#', addslashes(Mage::getBaseDir()), $this->_config->get($key)));
     }
     // set the registry
     $this->_config->setRegistry($this->_registry);
     // initialize the dependeny database
     PEAR_DependencyDB::singleton($this->_config, $pearDir . DS . 'php' . DS . '.depdb');
     // register the commands, including the one for Magento
     PEAR_Command::registerCommands(true, $pearDir . DS . 'php' . DS . 'PEAR' . DS . 'Command' . DS);
     // initialize the PEAR frontend
     PEAR_Frontend::setFrontendClass('Faett_Core_Frontend_PEAR');
     $this->_ui = PEAR_Command::getFrontendObject();
     $this->_ui->setConfig($this->_config);
     // set the callback for rendering the messages
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this->_ui, "log"));
 }