Example #1
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;
 }
Example #2
0
 function &setFrontendClass($uiclass)
 {
     if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) && is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], $uiclass)) {
         return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
     }
     if (!class_exists($uiclass)) {
         $file = str_replace('_', '/', $uiclass) . '.php';
         if (PEAR_Frontend::isIncludeable($file)) {
             include_once $file;
         }
     }
     if (class_exists($uiclass)) {
         $obj =& new $uiclass();
         // quick test to see if this class implements a few of the most
         // important frontend methods
         if (method_exists($obj, 'userConfirm')) {
             $GLOBALS['_PEAR_FRONTEND_SINGLETON'] =& $obj;
             $GLOBALS['_PEAR_FRONTEND_CLASS'] = $uiclass;
             return $obj;
         } else {
             $err = PEAR::raiseError("not a frontend class: {$uiclass}");
             return $err;
         }
     }
     $err = PEAR::raiseError("no such class: {$uiclass}");
     return $err;
 }
Example #3
0
 function setUI($ui = null)
 {
     if (!$ui) {
         $this->_ui = PEAR_Frontend::singleton();
     } else {
         $this->_ui = $ui;
     }
 }
 /**
  * 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"));
 }
Example #5
0
 function PEAR_Frontend_CLI()
 {
     parent::PEAR();
     $term = getenv('TERM');
     //(cox) $_ENV is empty for me in 4.1.1
     if (function_exists('posix_isatty') && !posix_isatty(1)) {
         // output is being redirected to a file or through a pipe
     } elseif ($term) {
         if (preg_match('/^(xterm|vt220|linux)/', $term)) {
             $this->term['bold'] = sprintf("%c%c%c%c", 27, 91, 49, 109);
             $this->term['normal'] = sprintf("%c%c%c", 27, 91, 109);
         } elseif (preg_match('/^vt100/', $term)) {
             $this->term['bold'] = sprintf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0);
             $this->term['normal'] = sprintf("%c%c%c%c%c", 27, 91, 109, 0, 0);
         }
     } elseif (OS_WINDOWS) {
         // XXX add ANSI codes here
     }
 }
Example #6
0
 function init(&$config, &$pkg, $lastversion)
 {
     $this->_config =& $config;
     $this->_registry =& $config->getRegistry();
     $this->_ui =& PEAR_Frontend::singleton();
     $this->_pkg =& $pkg;
     $this->_lastversion = $lastversion;
     $this->_wwwDirectory = $this->_config->get('www_dir');
     if ($this->_wwwDirectory === false || !file_exists($this->_wwwDirectory)) {
         $this->_ui->log("Failed to find a web directory {$this->_wwwDirectory}");
         return false;
     }
     $sfile = $this->_wwwDirectory . DIRECTORY_SEPARATOR . 'LocalSettings.php.sample';
     $this->contents = file_get_contents($sfile, true);
     if ($this->contents === false) {
         $this->_ui->log("Failed to load '{$sfile}'");
         return false;
     }
     $this->_ui->log("Loaded '{$sfile}'");
     return true;
 }
Example #7
0
 function listAll($base, $dostable, $basic = true, $searchpackage = false, $searchsummary = false)
 {
     $packagelist = $this->_rest->retrieveData($base . 'p/packages.xml');
     if (PEAR::isError($packagelist)) {
         return $packagelist;
     }
     if ($this->_rest->config->get('verbose') > 0) {
         $ui =& PEAR_Frontend::singleton();
         $ui->log('Retrieving data...0%', false);
     }
     $ret = array();
     if (!is_array($packagelist) || !isset($packagelist['p'])) {
         return $ret;
     }
     if (!is_array($packagelist['p'])) {
         $packagelist['p'] = array($packagelist['p']);
     }
     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
     $next = 0.1;
     foreach ($packagelist['p'] as $progress => $package) {
         if ($this->_rest->config->get('verbose') > 0) {
             if ($progress / count($packagelist['p']) >= $next) {
                 if ($next == 0.5) {
                     $ui->log('50%', false);
                 } else {
                     $ui->log('.', false);
                 }
                 $next += 0.1;
             }
         }
         if ($basic) {
             // remote-list command
             if ($dostable) {
                 $latest = $this->_rest->retrieveData($base . 'r/' . strtolower($package) . '/stable.txt');
             } else {
                 $latest = $this->_rest->retrieveData($base . 'r/' . strtolower($package) . '/latest.txt');
             }
             if (PEAR::isError($latest)) {
                 $latest = false;
             }
             $info = array('stable' => $latest);
         } else {
             // list-all command
             $inf = $this->_rest->retrieveData($base . 'p/' . strtolower($package) . '/info.xml');
             if (PEAR::isError($inf)) {
                 PEAR::popErrorHandling();
                 return $inf;
             }
             if ($searchpackage) {
                 $found = !empty($searchpackage) && stristr($package, $searchpackage) !== false;
                 if (!$found && !(isset($searchsummary) && !empty($searchsummary) && (stristr($inf['s'], $searchsummary) !== false || stristr($inf['d'], $searchsummary) !== false))) {
                     continue;
                 }
             }
             $releases = $this->_rest->retrieveData($base . 'r/' . strtolower($package) . '/allreleases.xml');
             if (PEAR::isError($releases)) {
                 continue;
             }
             if (!isset($releases['r'][0])) {
                 $releases['r'] = array($releases['r']);
             }
             unset($latest);
             unset($unstable);
             unset($stable);
             unset($state);
             foreach ($releases['r'] as $release) {
                 if (!isset($latest)) {
                     if ($dostable && $release['s'] == 'stable') {
                         $latest = $release['v'];
                         $state = 'stable';
                     }
                     if (!$dostable) {
                         $latest = $release['v'];
                         $state = $release['s'];
                     }
                 }
                 if (!isset($stable) && $release['s'] == 'stable') {
                     $stable = $release['v'];
                     if (!isset($unstable)) {
                         $unstable = $stable;
                     }
                 }
                 if (!isset($unstable) && $release['s'] != 'stable') {
                     $latest = $unstable = $release['v'];
                     $state = $release['s'];
                 }
                 if (isset($latest) && !isset($state)) {
                     $state = $release['s'];
                 }
                 if (isset($latest) && isset($stable) && isset($unstable)) {
                     break;
                 }
             }
             $deps = array();
             if (!isset($unstable)) {
                 $unstable = false;
                 $state = 'stable';
                 if (isset($stable)) {
                     $latest = $unstable = $stable;
                 }
             } else {
                 $latest = $unstable;
             }
             if (!isset($latest)) {
                 $latest = false;
             }
             if ($latest) {
                 $d = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/deps.' . $latest . '.txt');
                 if (!PEAR::isError($d)) {
                     $d = unserialize($d);
                     if ($d) {
                         if (isset($d['required'])) {
                             if (!class_exists('PEAR_PackageFile_v2')) {
                                 require_once 'PEAR/PackageFile/v2.php';
                             }
                             if (!isset($pf)) {
                                 $pf = new PEAR_PackageFile_v2();
                             }
                             $pf->setDeps($d);
                             $tdeps = $pf->getDeps();
                         } else {
                             $tdeps = $d;
                         }
                         foreach ($tdeps as $dep) {
                             if ($dep['type'] !== 'pkg') {
                                 continue;
                             }
                             $deps[] = $dep;
                         }
                     }
                 }
             }
             if (!isset($stable)) {
                 $stable = '-n/a-';
             }
             if (!$searchpackage) {
                 $info = array('stable' => $latest, 'summary' => $inf['s'], 'description' => $inf['d'], 'deps' => $deps, 'category' => $inf['ca']['_content'], 'unstable' => $unstable, 'state' => $state);
             } else {
                 $info = array('stable' => $stable, 'summary' => $inf['s'], 'description' => $inf['d'], 'deps' => $deps, 'category' => $inf['ca']['_content'], 'unstable' => $unstable, 'state' => $state);
             }
         }
         $ret[$package] = $info;
     }
     PEAR::popErrorHandling();
     return $ret;
 }
Example #8
0
 function runPostinstallScripts()
 {
     if ($this->initPostinstallScripts()) {
         $ui =& PEAR_Frontend::singleton();
         if ($ui) {
             $ui->runPostinstallScripts($this->_scripts, $this);
         }
     }
 }
Example #9
0
        // extreme debugging
        exit;
    }
}
// end print
$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;
 /**
  * Initializes the PEAR Frontend instance.
  */
 protected function initializeFrontend()
 {
     $this->frontend = PEAR_Frontend::singleton('sfPearFrontendPlugin');
     if (PEAR::isError($this->frontend)) {
         throw new sfPluginException(sprintf('Unable to initialize PEAR Frontend object: %s', $this->frontend->getMessage()));
     }
     $this->frontend->setEventDispatcher($this->dispatcher);
 }
Example #11
0
 /**
  * Logging method.
  *
  * @param int    $level  log level (0 is quiet, higher is noisier)
  * @param string $msg    message to write to the log
  *
  * @return void
  *
  * @access public
  * @static
  */
 function log($level, $msg, $append_crlf = true)
 {
     if ($this->debug >= $level) {
         $ui =& PEAR_Frontend::singleton();
         if (is_a($ui, 'PEAR_Frontend')) {
             $ui->log($msg, $append_crlf);
         } else {
             print "{$msg}\n";
         }
     }
 }
Example #12
0
 /**
  * Load current frontend class.
  *
  * @param string $uiclass Name of class implementing the frontend
  *
  * @return object the frontend object, or a PEAR error
  * @static
  */
 function &setFrontendClass($uiclass)
 {
     $a =& PEAR_Frontend::setFrontendClass($uiclass);
     return $a;
 }
Example #13
0
 /**
  * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
  * @return bool
  * @access private
  */
 function _addPackage2($info)
 {
     if (!is_a($info, 'PEAR_PackageFile_v1') && !is_a($info, 'PEAR_PackageFile_v2')) {
         return false;
     }
     if (!$info->validate()) {
         if (class_exists('PEAR_Common')) {
             $ui = PEAR_Frontend::singleton();
             if ($ui) {
                 foreach ($info->getValidationWarnings() as $err) {
                     $ui->log($err['message'], true);
                 }
             }
         }
         return false;
     }
     $channel = $info->getChannel();
     $package = $info->getPackage();
     $save = $info;
     if ($this->_packageExists($package, $channel)) {
         return false;
     }
     if (!$this->_channelExists($channel, true)) {
         return false;
     }
     $info = $info->toArray(true);
     if (!$info) {
         return false;
     }
     $fp = $this->_openPackageFile($package, 'wb', $channel);
     if ($fp === null) {
         return false;
     }
     $info['_lastmodified'] = time();
     fwrite($fp, serialize($info));
     $this->_closePackageFile($fp);
     $this->_rebuildFileMap();
     return true;
 }
Example #14
0
    /**
     * This helper function parses httpd.conf and adds needed information
     * for pearweb to run.
     *
     * In essence, this takes the contents of docs/apache_setup.txt and
     * adds them to httpd.conf with paths replaced that are needed to
     * make the thing work.
     *
     * @param array $answers
     * @return boolean
     */
    function setupHttpdconf($answers)
    {
        $eol = defined('PHP_EOL') ? PHP_EOL : (OS_WINDOWS ? "\r\n" : "\n");
        if (!realpath($answers['path']) || !file_exists($answers['path'])) {
            $this->_ui->outputData('No such file: "' . $answers['path'] . '"');
            return false;
        }
        $httpdconf = file(realpath($answers['path']));
        $found = array();
        foreach ($httpdconf as $num => $line) {
            $line = trim($line);
            if (!$line) {
                continue;
            }
            if (strpos($line, '# inserted by pearweb #### (do not remove) start') === 0) {
                $found['start'] = $num;
                continue;
            }
            if (strpos($line, '# inserted by pearweb #### (do not remove) end') === 0) {
                $found['end'] = $num;
            }
        }
        if (array_key_exists('start', $found) && array_key_exists('end', $found)) {
            $one = array_slice($httpdconf, 0, $found['start'] - 1);
            $two = array_slice($httpdconf, $found['end'] + 1);
        } else {
            $one = $httpdconf;
            $two = array();
        }
        // here we go...
        $middle = array();
        $middle[] = $eol;
        $middle[] = '# inserted by pearweb #### (do not remove) start' . $eol;
        $middle[] = '<VirtualHost ' . $answers['namehost'] . '>' . $eol;
        $middle[] = ' ServerName ' . $answers['pear'] . $eol;
        $middle[] = $eol;
        // apache requires all path separators to be "/" even on windows
        $middle[] = ' DocumentRoot ' . str_replace('\\', '/', '@www-dir@') . '/public_html' . $eol;
        $middle[] = ' DirectoryIndex index.php index.html' . $eol;
        $middle[] = $eol;
        $middle[] = ' php_value include_path .' . PATH_SEPARATOR . str_replace('\\', '/', '@www-dir@') . '/include' . PATH_SEPARATOR . str_replace('\\', '/', '@php-dir@') . $eol;
        $middle[] = ' php_value auto_prepend_file pear-prepend.php' . $eol;
        $middle[] = ' php_flag magic_quotes_gpc off' . $eol;
        $middle[] = ' php_flag magic_quotes_runtime off' . $eol;
        $middle[] = ' php_flag register_globals Off' . $eol;
        $middle[] = $eol;
        $middle[] = ' ErrorDocument 404 /error/404.php' . $eol;
        $middle[] = $eol;
        $middle[] = ' Alias /package ' . str_replace('\\', '/', '@www-dir@') . '/public_html/package-info.php' . $eol;
        $middle[] = ' Alias /user    ' . str_replace('\\', '/', '@www-dir@') . '/public_html/account-info.php' . $eol;
        $middle[] = ' Alias /sidebar/pear.gif ' . str_replace('\\', '/', '@www-dir@') . '/public_html/gifs/pear_item.gif' . $eol;
        $middle[] = ' Alias /distributions/manual/chm /var/lib/pear/chm' . $eol;
        $middle[] = ' Alias /reference /var/lib/pear/apidoc' . $eol;
        $middle[] = $eol;
        $middle[] = ' RedirectPermanent /download-docs.php          http://' . $answers['pear'] . '/manual/' . $eol;
        $middle[] = ' RedirectPermanent /rss.php                    http://' . $answers['pear'] . '/feeds/latest.rss' . $eol;
        $middle[] = ' RedirectPermanent /weeklynews.php             http://' . $answers['pear'] . '/' . $eol;
        $middle[] = ' RedirectPermanent /support.php                http://' . $answers['pear'] . '/support/' . $eol;
        $middle[] = ' RedirectPermanent /credits.php                http://' . $answers['pear'] . '/about/credits.php' . $eol;
        $middle[] = ' RedirectPermanent /pepr/pepr-overview.php     http://' . $answers['pear'] . '/pepr/' . $eol;
        $middle[] = $eol;
        $middle[] = ' RewriteEngine On' . $eol;
        $middle[] = $eol;
        $middle[] = ' #' . $eol;
        $middle[] = ' # Rewriting rules for the RSS feeds' . $eol;
        $middle[] = ' #' . $eol;
        $middle[] = $eol;
        $middle[] = ' RewriteRule   /feeds/(.+)\\.rss$ /feeds/feeds.php?type=$1' . $eol;
        $middle[] = $eol;
        $middle[] = ' #' . $eol;
        $middle[] = ' # Rewriting rule for the API documentation' . $eol;
        $middle[] = ' #' . $eol;
        $middle[] = $eol;
        $middle[] = ' RewriteRule   /package/([a-zA-Z0-9_]+)/docs/(.+)($/|$) /reference/$1-$2 [PT]' . $eol;
        $middle[] = $eol;
        $middle[] = ' #' . $eol;
        $middle[] = ' # Rewriting rule for the Bug system' . $eol;
        $middle[] = ' #' . $eol;
        $middle[] = $eol;
        $middle[] = ' RewriteRule   /bugs/([0-9]+)/*$ /bugs/bug.php?id=$1 [R]
' . $eol;
        $middle[] = $eol;
        $middle[] = ' #' . $eol;
        $middle[] = ' # Rewriting rule for the manual' . $eol;
        $middle[] = ' # throw pecl doc people to the php manual' . $eol;
        $middle[] = ' #' . $eol;
        $middle[] = $eol;
        $middle[] = '  RewriteRule   /manual/[a-z]{2}/pecl.([a-zA-Z0-9_-]+)\\.php$ http://www.php.net/$1 [R=301]' . $eol;
        $middle[] = $eol;
        $middle[] = ' SetEnvIf User-Agent "MS Search 4\\.0 Robot\\)$" badrobot' . $eol;
        $middle[] = $eol;
        $middle[] = ' <Directory />' . $eol;
        $middle[] = '  order deny,allow' . $eol;
        $middle[] = '  deny from env=badrobot' . $eol;
        $middle[] = ' </Directory>' . $eol;
        $middle[] = $eol;
        $middle[] = ' <Location /get>' . $eol;
        $middle[] = '  ForceType application/x-httpd-php' . $eol;
        $middle[] = $eol;
        $middle[] = '  Deny From 194.51.105.35' . $eol;
        $middle[] = ' </Location>' . $eol;
        $middle[] = $eol;
        $middle[] = ' <Location /manual>' . $eol;
        $middle[] = '  ErrorDocument 404 /error/404-manual.php' . $eol;
        $middle[] = ' </Location>' . $eol;
        $middle[] = $eol;
        $middle[] = ' <Location /bugs/include>' . $eol;
        $middle[] = '  deny from all' . $eol;
        $middle[] = ' </Location>' . $eol;
        $middle[] = $eol;
        $middle[] = ' <Location /trackback>' . $eol;
        $middle[] = '  DirectoryIndex trackback.php' . $eol;
        $middle[] = ' </Location>' . $eol;
        $middle[] = $eol;
        $middle[] = '</VirtualHost>' . $eol;
        $middle[] = '# inserted by pearweb #### (do not remove) end' . $eol;
        $one = array_merge($one, $middle);
        $httpdconf = array_merge($one, $two);
        $this->_ui->outputData('opening ' . $answers['path'] . ' for writing');
        $fp = fopen(realpath($answers['path']), 'w');
        $this->_ui->outputData('writing data...');
        fwrite($fp, implode('', $httpdconf));
        fclose($fp);
        $this->_ui->outputData('...done');
        return true;
    }
 /**
  * Main entry point for d51pearpkg2 task
  */
 public function main()
 {
     PEAR_Frontend::setFrontendObject(new d51PearPkg2Task_Frontend($this));
     $package = new PEAR_PackageFileManager2();
     $this->_initOptions();
     $a = $package->setOptions($this->_options);
     if (PEAR::isError($a)) {
         $this->log($a->getMessage(), Project::MSG_ERR);
         exit(-1);
     }
     $package->setPackage((string) $this->_name);
     $package->setSummary((string) $this->_summary);
     $desc = preg_replace("/^({$this->_description->indention_type}{{$this->_description->indentions_to_remove}}|\t)+/m", '', (string) $this->_description);
     $package->setDescription($desc);
     $package->setChannel((string) $this->_channel);
     $package->setAPIVersion($this->_version->api);
     $package->setReleaseVersion($this->_version->release);
     $package->setAPIStability($this->_stability->api);
     $package->setReleaseStability($this->_stability->release);
     // TODO: allow different types
     $package->setPackageType($this->_type);
     $package->addRelease();
     if (!is_null($this->_dependencies->php)) {
         $this->log('Using explicit PHP minimum version: ' . $this->_dependencies->php->minimum_version);
         $package->setPhpDep($this->_dependencies->php->minimum_version);
     } else {
         $this->log('Using current PHP version as minimum: ' . phpversion());
         $package->setPhpDep(phpversion());
     }
     if (!is_null($this->_dependencies->pear)) {
         $this->log('setting minimum PEAR version: ' . $this->_dependencies->pear->minimum_version);
         $package->setPearinstallerDep($this->_dependencies->pear->minimum_version, $this->_dependencies->pear->maximum_version, $this->_dependencies->pear->recommended_version, $this->_dependencies->pear->exclude_version);
     } else {
         $this->log('setting minimum PEAR version to currently installed version');
         $pear_version = PEAR_Config::singleton()->getRegistry()->packageInfo('PEAR', 'version');
         $this->log('minimum PEAR version: ' . $pear_version);
         $package->setPearinstallerDep(PEAR_Config::singleton()->getRegistry()->packageInfo('PEAR', 'version'));
     }
     foreach ($this->_maintainers as $maintainer) {
         $this->log("adding maintainer [{$maintainer->user}/{$maintainer->name}] with role [{$maintainer->role}]");
         $package->addMaintainer($maintainer->role, $maintainer->user, $maintainer->name, $maintainer->email, $maintainer->active);
     }
     // handle dependencies
     if (!empty($this->_dependencies)) {
         $this->log('adding dependencies');
         if (count($this->_dependencies->groups) > 0) {
             $this->log('found dependency groups');
             foreach ($this->_dependencies->groups as $group) {
                 $this->log("adding [{$group->name}] :: [{$group->hint}]");
                 $package->addDependencyGroup($group->name, $group->hint);
                 foreach ($group->packages as $sub_package) {
                     $package->addGroupPackageDepWithChannel('subpackage', $group->name, $sub_package->name, $sub_package->channel, '0.0.1');
                 }
             }
         }
         if (count($this->_dependencies->packages) > 0) {
             $this->log('found dependencies');
             foreach ($this->_dependencies->packages as $dependency) {
                 $this->log("adding following dependency: {$dependency->channel}/{$dependency->name}");
                 $package->addPackageDepWithChannel($dependency->type, $dependency->name, $dependency->channel, $dependency->minimum_version, $dependency->maximum_version, $dependency->recommended_version, $dependency->exclude_version, $dependency->providesextension, $dependency->nodefault);
             }
         }
         if (count($this->_dependencies->extensions) > 0) {
             $this->log('adding extension dependencies');
             foreach ($this->_dependencies->extensions as $extension) {
                 $this->log("adding ext dependency for: {$extension->name}");
                 $package->addExtensionDep($extension->type, $extension->name, $extension->minimum_version, $extension->maximum_version, $extension->recommended_version, $extension->extension);
             }
         }
     }
     foreach ($this->_changelogs as $changelog) {
         $this->log("adding changelog for prior release [{$changelog->version}]");
         $changelog->package = $package;
         $package->setChangelogEntry($changelog->version, $changelog->toArray());
         if (is_null($this->_notes) && $package->getVersion() == $changelog->version) {
             $this->log("no package notes specified, using changelog entry");
             $this->_notes = $changelog->contents;
         }
     }
     foreach ($this->_replacements as $replacement) {
         $replacement->isValid();
         $this->log("adding replace from [{$replacement->from}] to [{$replacement->to}]");
         $package->addReplacement($replacement->path, $replacement->type, $replacement->from, $replacement->to);
     }
     foreach ($this->_releases as $release) {
         $this->log('adding new release');
         $package->addRelease();
         foreach ($release->install as $install) {
             $this->log("installing [{$install->name}] as [{$install->as}]");
             $package->addInstallAs($install->name, $install->as);
         }
     }
     $notes = preg_replace("/^( {4}|\t)+/m", '', (string) $this->_notes);
     $package->setNotes($notes);
     $package->setLicense($this->_license->license, $this->_license->uri);
     $package->generateContents();
     $e = $package->writePackageFile();
     if (PEAR::isError($e)) {
         throw new d51PearPkg2Task_Exception('unable to write package.xml file: ' . $e->getMessage());
     }
 }
Example #16
0
 private function nativePearInstall($package, $channel)
 {
     if (!class_exists('PEAR_Command')) {
         @(include 'PEAR/command.php');
         // loads frontend, among other things
         if (!class_exists('PEAR_Command')) {
             throw new pakeException('PEAR subsystem is unavailable (not in include_path?)');
         }
     }
     $front = PEAR_Frontend::singleton('PEAR_Frontend_CLI');
     $cfg = PEAR_Config::singleton();
     $cmd = PEAR_Command::factory('install', $cfg);
     ob_start();
     $result = $cmd->doInstall('install', array(), array($channel . '/' . $package));
     ob_end_clean();
     // we don't need output
     if ($result instanceof PEAR_Error) {
         throw new pakeException($result->getMessage());
     }
 }
Example #17
0
 /**
  * Create or upgrade the database needed for pearweb
  *
  * This helper function scans for previous database versions,
  * and upgrades the database based on differences between the
  * previous version's schema and the one distributed with this
  * version.
  *
  * If the database has never been created, then it is created.
  *
  * @param array $answers
  * @return boolean
  */
 function initializeDatabase($answers)
 {
     //include_once dirname(__FILE__) . 'include/pear-config.php';
     //$a = MDB2_Schema::factory(PEAR_DATABASE_DSN,
     $this->dsn = array('phptype' => $answers['driver'], 'username' => $answers['user'], 'password' => $answers['password'], 'hostspec' => $answers['host'], 'database' => $answers['database']);
     $a = MDB2_Schema::factory($this->dsn, array('idxname_format' => '%s', 'seqname_format' => 'id', 'quote_identifier' => true));
     // for upgrade purposes
     if (!file_exists('@www-dir@' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . '.pearweb-upgrade')) {
         if (!mkdir('@www-dir@' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . '.pearweb-upgrade')) {
             $this->_ui->outputData('error - make sure we can create directories');
             return false;
         }
     }
     PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
     $c = $a->parseDatabaseDefinitionFile(realpath('@www-dir@/sql/pearweb_election.xml'));
     PEAR::staticPopErrorHandling();
     if (PEAR::isError($c)) {
         $extra = '';
         if (MDB2_Schema::isError($c) || MDB2::isError($c)) {
             $extra = "\n" . $c->getUserInfo();
         }
         $this->_ui->outputData('ERROR: ' . $c->getMessage() . $extra);
         return false;
     }
     $c['name'] = $answers['database'];
     $c['create'] = 1;
     $c['overwrite'] = 0;
     $dir = opendir('@www-dir@/sql/.pearweb-upgrade');
     $oldversion = false;
     while (false !== ($entry = readdir($dir))) {
         if ($entry[0] === '.') {
             continue;
         }
         if (strpos($entry, $answers['database']) === 0) {
             // this is one of ours
             // strip databasename-
             $entry = substr($entry, strlen($answers['database']) + 1);
             // strip ".ser"
             $entry = substr($entry, 0, strlen($entry) - 4);
             // ... and we're left with just the version
             if (!$oldversion) {
                 $oldversion = $entry;
                 continue;
             }
             if (version_compare($entry, $oldversion, '>')) {
                 $oldversion = $entry;
             }
         }
     }
     if (!file_exists('@www-dir@/sql/.pearweb-upgrade/' . $answers['database'] . '-@version@.ser')) {
         $fp = fopen('@www-dir@/sql/.pearweb-upgrade/' . $answers['database'] . '-@version@.ser', 'w');
         fwrite($fp, serialize($c));
         fclose($fp);
     }
     if ($oldversion == '@version@') {
         // this is where to change if we need to add a "force upgrade of
         // structure" option
         // we would uncomment the following line:
         //$c['overwrite'] = true;
         $oldversion = false;
     }
     if ($oldversion) {
         $curdef = unserialize(file_get_contents('@www-dir@/sql/.pearweb-upgrade/' . $answers['database'] . '-' . $oldversion . '.ser'));
         if (!is_array($curdef)) {
             $this->_ui->outputData('invalid data returned from previous version');
         }
         // get a database diff (MDB2_Schema is very useful here)
         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
         $c = $a->compareDefinitions($c, $curdef);
         if (PEAR::isError($c)) {
             $this->_ui->outputData($err->getMessage());
             $this->_ui->outputData($err->getUserInfo());
             $this->_ui->outputData('Unable to automatically update database');
             return false;
         }
         $err = $a->updateDatabase($curdef, $c);
         PEAR::staticPopErrorHandling();
     } else {
         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
         $err = $a->createDatabase($c);
         PEAR::staticPopErrorHandling();
     }
     if (PEAR::isError($err)) {
         $this->_ui->outputData($err->getUserInfo());
         $this->_ui->outputData($err->getMessage());
         return false;
     }
     return true;
 }
    } else {
        $conf_name = 'pear.conf';
    }
    $default_config_dirs = array(substr(dirname(__FILE__), 0, -strlen('PEAR/PEAR')), dirname($_SERVER['SCRIPT_FILENAME']), PEAR_CONFIG_SYSCONFDIR);
    // set the default: __FILE__ without PEAR/PEAR/
    $pear_user_config = $default_config_dirs[0] . DIRECTORY_SEPARATOR . $conf_name;
    foreach ($default_config_dirs as $confdir) {
        if (file_exists($confdir . DIRECTORY_SEPARATOR . $conf_name)) {
            $pear_user_config = $confdir . DIRECTORY_SEPARATOR . $conf_name;
            break;
        }
    }
    unset($conf_name, $default_config_dirs, $confdir);
}
// moving this here allows startup messages and errors to work properly
PEAR_Frontend::setFrontendClass('PEAR_Frontend_Web');
// Init PEAR Installer Code and WebFrontend
$GLOBALS['_PEAR_Frontend_Web_config'] =& PEAR_Config::singleton($pear_user_config, '');
$config =& $GLOBALS['_PEAR_Frontend_Web_config'];
$ui =& PEAR_Command::getFrontendObject();
$ui->setConfig($config);
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
// Cient requests an Image/Stylesheet/Javascript
// outputFrontendFile() does exit()
if (isset($_GET["css"])) {
    $ui->outputFrontendFile($_GET["css"], 'css');
}
if (isset($_GET["js"])) {
    $ui->outputFrontendFile($_GET["js"], 'js');
}
if (isset($_GET["img"])) {
Example #19
0
 function PEAR_Frontend_Web()
 {
     parent::PEAR();
     $this->config =& $GLOBALS['_PEAR_Frontend_Web_config'];
 }
Example #20
0
 /**
  * Logging method.
  *
  * @param int    $level  log level (0 is quiet, higher is noisier)
  * @param string $msg    message to write to the log
  *
  * @return void
  *
  * @access public
  * @static
  */
 function log($level, $msg, $append_crlf = true)
 {
     if ($this->debug >= $level) {
         if (!class_exists('PEAR_Frontend')) {
             require_once 'PEAR/Frontend.php';
         }
         $ui =& PEAR_Frontend::singleton();
         if (is_a($ui, 'PEAR_Frontend')) {
             $ui->log($msg, $append_crlf);
         } else {
             print "{$msg}\n";
         }
     }
 }
 private static function nativePearUpgrade($package, $channel)
 {
     pake_echo_action('pear', 'upgrading ' . $channel . '/' . $package);
     self::initPearClasses();
     $front = PEAR_Frontend::singleton('PEAR_Frontend_CLI');
     $cfg = PEAR_Config::singleton();
     $cmd = PEAR_Command::factory('upgrade', $cfg);
     ob_start();
     $result = $cmd->doInstall('upgrade', array(), array($channel . '/' . $package));
     ob_end_clean();
     // we don't need output
     if ($result instanceof PEAR_Error) {
         throw new pakeException($result->getMessage());
     }
 }