Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * PEAR_Command_Install (install, upgrade, upgrade-all, uninstall, bundle, run-scripts commands)
3
 * PEAR_Command_Install (install, upgrade, upgrade-all, uninstall, bundle, run-scripts commands)
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
9
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
10
 * @author     Greg Beaver <cellog@php.net>
17
 * @copyright  1997-2006 The PHP Group
11
 * @copyright  1997-2009 The Authors
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
12
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
19
 * @version    CVS: $Id: Install.php,v 1.122 2007/02/13 04:30:05 cellog Exp $
-
 
20
 * @link       http://pear.php.net/package/PEAR
13
 * @link       http://pear.php.net/package/PEAR
21
 * @since      File available since Release 0.1
14
 * @since      File available since Release 0.1
22
 */
15
 */
Line 23... Line 16...
23
 
16
 
Line 32... Line 25...
32
 *
25
 *
33
 * @category   pear
26
 * @category   pear
34
 * @package    PEAR
27
 * @package    PEAR
35
 * @author     Stig Bakken <ssb@php.net>
28
 * @author     Stig Bakken <ssb@php.net>
36
 * @author     Greg Beaver <cellog@php.net>
29
 * @author     Greg Beaver <cellog@php.net>
37
 * @copyright  1997-2006 The PHP Group
30
 * @copyright  1997-2009 The Authors
38
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
31
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
39
 * @version    Release: 1.5.1
32
 * @version    Release: 1.10.1
40
 * @link       http://pear.php.net/package/PEAR
33
 * @link       http://pear.php.net/package/PEAR
41
 * @since      Class available since Release 0.1
34
 * @since      Class available since Release 0.1
42
 */
35
 */
43
class PEAR_Command_Install extends PEAR_Command_Common
36
class PEAR_Command_Install extends PEAR_Command_Common
44
{
37
{
Line 138... Line 131...
138
        'upgrade' => array(
131
        'upgrade' => array(
139
            'summary' => 'Upgrade Package',
132
            'summary' => 'Upgrade Package',
140
            'function' => 'doInstall',
133
            'function' => 'doInstall',
141
            'shortcut' => 'up',
134
            'shortcut' => 'up',
142
            'options' => array(
135
            'options' => array(
-
 
136
                'channel' => array(
-
 
137
                    'shortopt' => 'c',
-
 
138
                    'doc' => 'upgrade packages from a specific channel',
-
 
139
                    'arg' => 'CHAN',
-
 
140
                    ),
143
                'force' => array(
141
                'force' => array(
144
                    'shortopt' => 'f',
142
                    'shortopt' => 'f',
145
                    'doc' => 'overwrite newer installed packages',
143
                    'doc' => 'overwrite newer installed packages',
146
                    ),
144
                    ),
147
                'loose' => array(
145
                'loose' => array(
Line 165... Line 163...
165
                    'doc' => 'request uncompressed files when downloading',
163
                    'doc' => 'request uncompressed files when downloading',
166
                    ),
164
                    ),
167
                'installroot' => array(
165
                'installroot' => array(
168
                    'shortopt' => 'R',
166
                    'shortopt' => 'R',
169
                    'arg' => 'DIR',
167
                    'arg' => 'DIR',
170
                    'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT), use packagingroot for RPM',
168
                    'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
171
                    ),
-
 
172
                'packagingroot' => array(
-
 
173
                    'shortopt' => 'P',
-
 
174
                    'arg' => 'DIR',
-
 
175
                    'doc' => 'root directory used when packaging files, like RPM packaging',
-
 
176
                    ),
169
                    ),
177
                'ignore-errors' => array(
170
                'ignore-errors' => array(
178
                    'doc' => 'force install even if there were errors',
171
                    'doc' => 'force install even if there were errors',
179
                    ),
172
                    ),
180
                'alldeps' => array(
173
                'alldeps' => array(
Line 203... Line 196...
203
upgrade anyway).
196
upgrade anyway).
Line 204... Line 197...
204
 
197
 
205
More than one package may be specified at once.
198
More than one package may be specified at once.
206
'),
199
'),
207
        'upgrade-all' => array(
200
        'upgrade-all' => array(
208
            'summary' => 'Upgrade All Packages',
201
            'summary' => 'Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters]',
209
            'function' => 'doInstall',
202
            'function' => 'doUpgradeAll',
210
            'shortcut' => 'ua',
203
            'shortcut' => 'ua',
-
 
204
            'options' => array(
-
 
205
                'channel' => array(
-
 
206
                    'shortopt' => 'c',
-
 
207
                    'doc' => 'upgrade packages from a specific channel',
-
 
208
                    'arg' => 'CHAN',
211
            'options' => array(
209
                    ),
212
                'nodeps' => array(
210
                'nodeps' => array(
213
                    'shortopt' => 'n',
211
                    'shortopt' => 'n',
214
                    'doc' => 'ignore dependencies, upgrade anyway',
212
                    'doc' => 'ignore dependencies, upgrade anyway',
215
                    ),
213
                    ),
Line 236... Line 234...
236
                'loose' => array(
234
                'loose' => array(
237
                    'doc' => 'do not check for recommended dependency version',
235
                    'doc' => 'do not check for recommended dependency version',
238
                    ),
236
                    ),
239
                ),
237
                ),
240
            'doc' => '
238
            'doc' => '
-
 
239
WARNING: This function is deprecated in favor of using the upgrade command with no params
-
 
240
 
241
Upgrades all packages that have a newer release available.  Upgrades are
241
Upgrades all packages that have a newer release available.  Upgrades are
242
done only if there is a release available of the state specified in
242
done only if there is a release available of the state specified in
243
"preferred_state" (currently {config preferred_state}), or a state considered
243
"preferred_state" (currently {config preferred_state}), or a state considered
244
more stable.
244
more stable.
245
'),
245
'),
Line 310... Line 310...
310
    /**
310
    /**
311
     * PEAR_Command_Install constructor.
311
     * PEAR_Command_Install constructor.
312
     *
312
     *
313
     * @access public
313
     * @access public
314
     */
314
     */
315
    function PEAR_Command_Install(&$ui, &$config)
315
    function __construct(&$ui, &$config)
316
    {
316
    {
317
        parent::PEAR_Command_Common($ui, $config);
317
        parent::__construct($ui, $config);
318
    }
318
    }
Line 319... Line 319...
319
 
319
 
Line 320... Line 320...
320
    // }}}
320
    // }}}
Line 325... Line 325...
325
    function &getDownloader(&$ui, $options, &$config)
325
    function &getDownloader(&$ui, $options, &$config)
326
    {
326
    {
327
        if (!class_exists('PEAR_Downloader')) {
327
        if (!class_exists('PEAR_Downloader')) {
328
            require_once 'PEAR/Downloader.php';
328
            require_once 'PEAR/Downloader.php';
329
        }
329
        }
330
        $a = &new PEAR_Downloader($ui, $options, $config);
330
        $a = new PEAR_Downloader($ui, $options, $config);
331
        return $a;
331
        return $a;
332
    }
332
    }
Line 333... Line 333...
333
 
333
 
334
    /**
334
    /**
Line 337... Line 337...
337
    function &getInstaller(&$ui)
337
    function &getInstaller(&$ui)
338
    {
338
    {
339
        if (!class_exists('PEAR_Installer')) {
339
        if (!class_exists('PEAR_Installer')) {
340
            require_once 'PEAR/Installer.php';
340
            require_once 'PEAR/Installer.php';
341
        }
341
        }
342
        $a = &new PEAR_Installer($ui);
342
        $a = new PEAR_Installer($ui);
343
        return $a;
343
        return $a;
344
    }
344
    }
Line 345... Line 345...
345
 
345
 
346
    function enableExtension($binaries, $type)
346
    function enableExtension($binaries, $type)
Line 350... Line 350...
350
        }
350
        }
351
        $ini = $this->_parseIni($phpini);
351
        $ini = $this->_parseIni($phpini);
352
        if (PEAR::isError($ini)) {
352
        if (PEAR::isError($ini)) {
353
            return $ini;
353
            return $ini;
354
        }
354
        }
355
        $fp = @fopen($phpini, 'wb');
-
 
356
        if (!$fp) {
-
 
357
            return PEAR::raiseError('cannot open php.ini "' . $phpini . '" for writing');
-
 
358
        }
-
 
359
        $line = 0;
355
        $line = 0;
360
        if ($type == 'extsrc' || $type == 'extbin') {
356
        if ($type == 'extsrc' || $type == 'extbin') {
361
            $search = 'extensions';
357
            $search = 'extensions';
362
            $enable = 'extension';
358
            $enable = 'extension';
363
        } else {
359
        } else {
Line 365... Line 361...
365
            ob_start();
361
            ob_start();
366
            phpinfo(INFO_GENERAL);
362
            phpinfo(INFO_GENERAL);
367
            $info = ob_get_contents();
363
            $info = ob_get_contents();
368
            ob_end_clean();
364
            ob_end_clean();
369
            $debug = function_exists('leak') ? '_debug' : '';
365
            $debug = function_exists('leak') ? '_debug' : '';
370
            $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
366
            $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
371
            $enable = 'zend_extension' . $debug . $ts;
367
            $enable = 'zend_extension' . $debug . $ts;
372
        }
368
        }
373
        foreach ($ini[$search] as $line => $extension) {
369
        foreach ($ini[$search] as $line => $extension) {
374
            if (in_array($extension, $binaries, true) || in_array(
370
            if (in_array($extension, $binaries, true) || in_array(
375
                  $ini['extension_dir'] . DIRECTORY_SEPARATOR . $extension, $binaries, true)) {
371
                  $ini['extension_dir'] . DIRECTORY_SEPARATOR . $extension, $binaries, true)) {
Line 387... Line 383...
387
                $binary = basename($binary);
383
                $binary = basename($binary);
388
            }
384
            }
389
            $newini[] = $enable . '="' . $binary . '"' . (OS_UNIX ? "\n" : "\r\n");
385
            $newini[] = $enable . '="' . $binary . '"' . (OS_UNIX ? "\n" : "\r\n");
390
        }
386
        }
391
        $newini = array_merge($newini, array_slice($ini['all'], $line));
387
        $newini = array_merge($newini, array_slice($ini['all'], $line));
-
 
388
        $fp = @fopen($phpini, 'wb');
-
 
389
        if (!$fp) {
-
 
390
            return PEAR::raiseError('cannot open php.ini "' . $phpini . '" for writing');
-
 
391
        }
392
        foreach ($newini as $line) {
392
        foreach ($newini as $line) {
393
            fwrite($fp, $line);
393
            fwrite($fp, $line);
394
        }
394
        }
395
        fclose($fp);
395
        fclose($fp);
396
        return true;
396
        return true;
Line 414... Line 414...
414
            ob_start();
414
            ob_start();
415
            phpinfo(INFO_GENERAL);
415
            phpinfo(INFO_GENERAL);
416
            $info = ob_get_contents();
416
            $info = ob_get_contents();
417
            ob_end_clean();
417
            ob_end_clean();
418
            $debug = function_exists('leak') ? '_debug' : '';
418
            $debug = function_exists('leak') ? '_debug' : '';
419
            $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
419
            $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
420
            $enable = 'zend_extension' . $debug . $ts;
420
            $enable = 'zend_extension' . $debug . $ts;
421
        }
421
        }
422
        $found = false;
422
        $found = false;
423
        foreach ($ini[$search] as $line => $extension) {
423
        foreach ($ini[$search] as $line => $extension) {
424
            if (in_array($extension, $binaries, true) || in_array(
424
            if (in_array($extension, $binaries, true) || in_array(
Line 449... Line 449...
449
        return true;
449
        return true;
450
    }
450
    }
Line 451... Line 451...
451
 
451
 
452
    function _parseIni($filename)
452
    function _parseIni($filename)
453
    {
453
    {
-
 
454
        if (!file_exists($filename)) {
-
 
455
            return PEAR::raiseError('php.ini "' . $filename . '" does not exist');
-
 
456
        }
454
        if (file_exists($filename)) {
457
 
455
            if (filesize($filename) > 300000) {
458
        if (filesize($filename) > 300000) {
-
 
459
            return PEAR::raiseError('php.ini "' . $filename . '" is too large, aborting');
-
 
460
        }
-
 
461
 
-
 
462
        ob_start();
-
 
463
        phpinfo(INFO_GENERAL);
-
 
464
        $info = ob_get_contents();
-
 
465
        ob_end_clean();
-
 
466
        $debug = function_exists('leak') ? '_debug' : '';
-
 
467
        $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
-
 
468
        $zend_extension_line = 'zend_extension' . $debug . $ts;
-
 
469
        $all = @file($filename);
-
 
470
        if ($all === false) {
-
 
471
            return PEAR::raiseError('php.ini "' . $filename .'" could not be read');
-
 
472
        }
-
 
473
        $zend_extensions = $extensions = array();
-
 
474
        // assume this is right, but pull from the php.ini if it is found
-
 
475
        $extension_dir = ini_get('extension_dir');
-
 
476
        foreach ($all as $linenum => $line) {
-
 
477
            $line = trim($line);
-
 
478
            if (!$line) {
456
                return PEAR::raiseError('php.ini "' . $filename . '" is too large, aborting');
479
                continue;
457
            }
-
 
458
            ob_start();
-
 
459
            phpinfo(INFO_GENERAL);
-
 
460
            $info = ob_get_contents();
-
 
461
            ob_end_clean();
-
 
462
            $debug = function_exists('leak') ? '_debug' : '';
-
 
463
            $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
-
 
464
            $zend_extension_line = 'zend_extension' . $debug . $ts;
480
            }
465
            $all = @file($filename);
481
            if ($line[0] == ';') {
466
            if (!$all) {
-
 
467
                return PEAR::raiseError('php.ini "' . $filename .'" could not be read');
482
                continue;
468
            }
483
            }
469
            $zend_extensions = $extensions = array();
484
            if (strtolower(substr($line, 0, 13)) == 'extension_dir') {
470
            // assume this is right, but pull from the php.ini if it is found
485
                $line = trim(substr($line, 13));
471
            $extension_dir = ini_get('extension_dir');
486
                if ($line[0] == '=') {
472
            foreach ($all as $linenum => $line) {
487
                    $x = trim(substr($line, 1));
473
                $line = trim($line);
488
                    $x = explode(';', $x);
474
                if (!$line) {
489
                    $extension_dir = str_replace('"', '', array_shift($x));
475
                    continue;
490
                    continue;
-
 
491
                }
-
 
492
            }
-
 
493
            if (strtolower(substr($line, 0, 9)) == 'extension') {
476
                }
494
                $line = trim(substr($line, 9));
-
 
495
                if ($line[0] == '=') {
-
 
496
                    $x = trim(substr($line, 1));
-
 
497
                    $x = explode(';', $x);
477
                if ($line[0] == ';') {
498
                    $extensions[$linenum] = str_replace('"', '', array_shift($x));
478
                    continue;
499
                    continue;
479
                }
-
 
480
                if (strtolower(substr($line, 0, 13)) == 'extension_dir') {
-
 
481
                    $line = trim(substr($line, 13));
-
 
482
                    if ($line[0] == '=') {
-
 
483
                        $x = trim(substr($line, 1));
-
 
484
                        $x = explode(';', $x);
-
 
485
                        $extension_dir = str_replace('"', '', array_shift($x));
-
 
486
                        continue;
-
 
487
                    }
500
                }
488
                }
-
 
489
                if (strtolower(substr($line, 0, 9)) == 'extension') {
-
 
490
                    $line = trim(substr($line, 9));
-
 
491
                    if ($line[0] == '=') {
-
 
492
                        $x = trim(substr($line, 1));
-
 
493
                        $x = explode(';', $x);
-
 
494
                        $extensions[$linenum] = str_replace('"', '', array_shift($x));
-
 
495
                        continue;
-
 
496
                    }
-
 
497
                }
501
            }
498
                if (strtolower(substr($line, 0, strlen($zend_extension_line))) ==
502
            if (strtolower(substr($line, 0, strlen($zend_extension_line))) ==
499
                      $zend_extension_line) {
503
                  $zend_extension_line) {
500
                    $line = trim(substr($line, strlen($zend_extension_line)));
504
                $line = trim(substr($line, strlen($zend_extension_line)));
501
                    if ($line[0] == '=') {
505
                if ($line[0] == '=') {
502
                        $x = trim(substr($line, 1));
506
                    $x = trim(substr($line, 1));
503
                        $x = explode(';', $x);
507
                    $x = explode(';', $x);
504
                        $zend_extensions[$linenum] = str_replace('"', '', array_shift($x));
508
                    $zend_extensions[$linenum] = str_replace('"', '', array_shift($x));
505
                        continue;
-
 
506
                    }
509
                    continue;
507
                }
510
                }
508
            }
-
 
509
            return array(
-
 
510
                'extensions' => $extensions,
-
 
511
                'zend_extensions' => $zend_extensions,
-
 
512
                'extension_dir' => $extension_dir,
-
 
513
                'all' => $all,
-
 
514
            );
-
 
515
        } else {
-
 
516
            return PEAR::raiseError('php.ini "' . $filename . '" does not exist');
511
            }
-
 
512
        }
-
 
513
        return array(
-
 
514
            'extensions' => $extensions,
-
 
515
            'zend_extensions' => $zend_extensions,
-
 
516
            'extension_dir' => $extension_dir,
-
 
517
            'all' => $all,
517
        }
518
        );
Line 518... Line 519...
518
    }
519
    }
Line 519... Line 520...
519
 
520
 
520
    // {{{ doInstall()
521
    // {{{ doInstall()
521
 
522
 
522
    function doInstall($command, $options, $params)
-
 
523
    {
-
 
524
        if (empty($this->installer)) {
-
 
525
            $this->installer = &$this->getInstaller($this->ui);
523
    function doInstall($command, $options, $params)
526
        }
524
    {
-
 
525
        if (!class_exists('PEAR_PackageFile')) {
527
        if ($command == 'upgrade') {
526
            require_once 'PEAR/PackageFile.php';
528
            $options['upgrade'] = true;
527
        }
529
        }
528
 
530
        if (isset($options['installroot']) && isset($options['packagingroot'])) {
-
 
531
            return $this->raiseError('ERROR: cannot use both --installroot and --packagingroot');
-
 
532
        }
529
        if (isset($options['installroot']) && isset($options['packagingroot'])) {
533
        if (isset($options['packagingroot']) && $this->config->get('verbose') > 2) {
530
            return $this->raiseError('ERROR: cannot use both --installroot and --packagingroot');
-
 
531
        }
-
 
532
 
-
 
533
        $reg = &$this->config->getRegistry();
-
 
534
        $channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
-
 
535
        if (!$reg->channelExists($channel)) {
-
 
536
            return $this->raiseError('Channel "' . $channel . '" does not exist');
-
 
537
        }
-
 
538
 
-
 
539
        if (empty($this->installer)) {
-
 
540
            $this->installer = &$this->getInstaller($this->ui);
-
 
541
        }
534
            $this->ui->outputData('using package root: ' . $options['packagingroot']);
542
 
-
 
543
        if ($command == 'upgrade' || $command == 'upgrade-all') {
-
 
544
            // If people run the upgrade command but pass nothing, emulate a upgrade-all
535
        }
545
            if ($command == 'upgrade' && empty($params)) {
-
 
546
                return $this->doUpgradeAll($command, $options, $params);
-
 
547
            }
-
 
548
            $options['upgrade'] = true;
-
 
549
        } else {
-
 
550
            $packages = $params;
-
 
551
        }
-
 
552
 
536
        $reg = &$this->config->getRegistry();
553
        $instreg = &$reg; // instreg used to check if package is installed
-
 
554
        if (isset($options['packagingroot']) && !isset($options['upgrade'])) {
537
        if ($command == 'upgrade-all') {
555
            $packrootphp_dir = $this->installer->_prependPath(
-
 
556
                $this->config->get('php_dir', null, 'pear.php.net'),
-
 
557
                $options['packagingroot']);
-
 
558
            $metadata_dir = $this->config->get('metadata_dir', null, 'pear.php.net');
-
 
559
            if ($metadata_dir) {
-
 
560
                $metadata_dir = $this->installer->_prependPath(
-
 
561
                    $metadata_dir,
-
 
562
                    $options['packagingroot']);
-
 
563
            }
-
 
564
            $instreg = new PEAR_Registry($packrootphp_dir, false, false, $metadata_dir); // other instreg!
-
 
565
 
-
 
566
            if ($this->config->get('verbose') > 2) {
-
 
567
                $this->ui->outputData('using package root: ' . $options['packagingroot']);
-
 
568
            }
538
            $options['upgrade'] = true;
569
        }
-
 
570
 
-
 
571
        $abstractpackages = $otherpackages = array();
539
            $reg = &$this->config->getRegistry();
572
        // parse params
-
 
573
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
574
 
-
 
575
        foreach ($params as $param) {
-
 
576
            if (strpos($param, 'http://') === 0) {
-
 
577
                $otherpackages[] = $param;
-
 
578
                continue;
540
            $savechannel = $this->config->get('default_channel');
579
            }
-
 
580
 
541
            $params = array();
581
            if (strpos($param, 'channel://') === false && @file_exists($param)) {
542
            foreach ($reg->listChannels() as $channel) {
582
                if (isset($options['force'])) {
-
 
583
                    $otherpackages[] = $param;
543
                if ($channel == '__uri') {
584
                    continue;
544
                    continue;
585
                }
545
                }
586
 
546
                $this->config->set('default_channel', $channel);
-
 
547
                $chan = &$reg->getChannel($channel);
-
 
548
                if (PEAR::isError($chan)) {
-
 
549
                    return $this->raiseError($chan);
-
 
550
                }
587
                $pkg = new PEAR_PackageFile($this->config);
551
                if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
-
 
552
                      $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
-
 
553
                    $dorest = true;
588
                $pf  = $pkg->fromAnyFile($param, PEAR_VALIDATE_DOWNLOADING);
554
                    unset($remote);
-
 
555
                } else {
589
                if (PEAR::isError($pf)) {
-
 
590
                    $otherpackages[] = $param;
556
                    $dorest = false;
591
                    continue;
557
                    $remote = &$this->config->getRemote($this->config);
592
                }
558
                }
593
 
559
                $state = $this->config->get('preferred_state');
594
                $exists   = $reg->packageExists($pf->getPackage(), $pf->getChannel());
560
                $installed = array_flip($reg->listPackages($channel));
595
                $pversion = $reg->packageInfo($pf->getPackage(), 'version', $pf->getChannel());
561
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
596
                $version_compare = version_compare($pf->getVersion(), $pversion, '<=');
562
                if ($dorest) {
-
 
563
                    $rest = &$this->config->getREST('1.0', array());
597
                if ($exists && $version_compare) {
564
                    $latest = $rest->listLatestUpgrades($base, $state, $installed, $channel, $reg);
598
                    if ($this->config->get('verbose')) {
565
                } else {
-
 
566
                    if (empty($state) || $state == 'any') {
599
                        $this->ui->outputData('Ignoring installed package ' .
567
                        $latest = $remote->call("package.listLatestReleases");
600
                            $reg->parsedPackageNameToString(
568
                    } else {
-
 
569
                        $latest = $remote->call("package.listLatestReleases", $state);
-
 
570
                    }
-
 
571
                }
601
                            array('package' => $pf->getPackage(),
572
                PEAR::staticPopErrorHandling();
602
                                  'channel' => $pf->getChannel()), true));
-
 
603
                    }
-
 
604
                    continue;
-
 
605
                }
-
 
606
                $otherpackages[] = $param;
-
 
607
                continue;
-
 
608
            }
-
 
609
 
-
 
610
            $e = $reg->parsePackageName($param, $channel);
573
                if (PEAR::isError($latest) || !is_array($latest)) {
611
            if (PEAR::isError($e)) {
-
 
612
                $otherpackages[] = $param;
-
 
613
            } else {
-
 
614
                $abstractpackages[] = $e;
-
 
615
            }
-
 
616
        }
-
 
617
        PEAR::staticPopErrorHandling();
-
 
618
 
-
 
619
        // if there are any local package .tgz or remote static url, we can't
-
 
620
        // filter.  The filter only works for abstract packages
-
 
621
        if (count($abstractpackages) && !isset($options['force'])) {
-
 
622
            // when not being forced, only do necessary upgrades/installs
574
                    continue;
623
            if (isset($options['upgrade'])) {
-
 
624
                $abstractpackages = $this->_filterUptodatePackages($abstractpackages, $command);
575
                }
625
            } else {
576
                foreach ($latest as $package => $info) {
626
                $count = count($abstractpackages);
577
                    $package = strtolower($package);
627
                foreach ($abstractpackages as $i => $package) {
578
                    if (!isset($installed[$package])) {
628
                    if (isset($package['group'])) {
-
 
629
                        // do not filter out install groups
579
                        // skip packages we don't have installed
630
                        continue;
-
 
631
                    }
580
                        continue;
632
 
-
 
633
                    if ($instreg->packageExists($package['package'], $package['channel'])) {
-
 
634
                        if ($count > 1) {
-
 
635
                            if ($this->config->get('verbose')) {
581
                    }
636
                                $this->ui->outputData('Ignoring installed package ' .
-
 
637
                                    $reg->parsedPackageNameToString($package, true));
-
 
638
                            }
-
 
639
                            unset($abstractpackages[$i]);
582
                    $inst_version = $reg->packageInfo($package, 'version', $channel);
640
                        } elseif ($count === 1) {
583
                    if (version_compare("$info[version]", "$inst_version", "le")) {
641
                            // Lets try to upgrade it since it's already installed
584
                        // installed version is up-to-date
-
 
585
                        continue;
-
 
586
                    }
-
 
587
                    $params[] = $a = $reg->parsedPackageNameToString(array('package' => $package,
642
                            $options['upgrade'] = true;
588
                        'channel' => $channel));
643
                        }
-
 
644
                    }
-
 
645
                }
-
 
646
            }
-
 
647
            $abstractpackages =
589
                    $this->ui->outputData(array('data' => "Will upgrade $a"), $command);
648
                array_map(array($reg, 'parsedPackageNameToString'), $abstractpackages);
590
                }
649
        } elseif (count($abstractpackages)) {
-
 
650
            $abstractpackages =
-
 
651
                array_map(array($reg, 'parsedPackageNameToString'), $abstractpackages);
-
 
652
        }
-
 
653
 
-
 
654
        $packages = array_merge($abstractpackages, $otherpackages);
-
 
655
        if (!count($packages)) {
-
 
656
            $c = '';
-
 
657
            if (isset($options['channel'])){
-
 
658
                $c .= ' in channel "' . $options['channel'] . '"';
-
 
659
            }
-
 
660
            $this->ui->outputData('Nothing to ' . $command . $c);
591
            }
661
            return true;
592
            $this->config->set('default_channel', $savechannel);
-
 
593
        }
662
        }
594
        $this->downloader = &$this->getDownloader($this->ui, $options, $this->config);
663
 
595
        $errors = array();
664
        $this->downloader = &$this->getDownloader($this->ui, $options, $this->config);
596
        $downloaded = array();
665
        $errors = $downloaded = $binaries = array();
597
        $downloaded = &$this->downloader->download($params);
666
        $downloaded = &$this->downloader->download($packages);
-
 
667
        if (PEAR::isError($downloaded)) {
598
        if (PEAR::isError($downloaded)) {
668
            return $this->raiseError($downloaded);
599
            return $this->raiseError($downloaded);
669
        }
-
 
670
 
600
        }
671
        $errors = $this->downloader->getErrorMsgs();
601
        $errors = $this->downloader->getErrorMsgs();
672
        if (count($errors)) {
-
 
673
            $err = array();
602
        if (count($errors)) {
674
            $err['data'] = array();
-
 
675
            foreach ($errors as $error) {
603
            $err['data'] = array();
676
                if ($error !== null) {
-
 
677
                    $err['data'][] = array($error);
-
 
678
                }
604
            foreach ($errors as $error) {
679
            }
605
                $err['data'][] = array($error);
680
 
-
 
681
            if (!empty($err['data'])) {
-
 
682
                $err['headline'] = 'Install Errors';
606
            }
683
                $this->ui->outputData($err);
607
            $err['headline'] = 'Install Errors';
684
            }
608
            $this->ui->outputData($err);
685
 
609
            if (!count($downloaded)) {
686
            if (!count($downloaded)) {
-
 
687
                return $this->raiseError("$command failed");
610
                return $this->raiseError("$command failed");
688
            }
611
            }
689
        }
612
        }
690
 
-
 
691
        $data = array(
613
        $data = array(
692
            'headline' => 'Packages that would be Installed'
614
            'headline' => 'Packages that would be Installed'
693
        );
615
        );
694
 
616
        if (isset($options['pretend'])) {
695
        if (isset($options['pretend'])) {
617
            foreach ($downloaded as $package) {
696
            foreach ($downloaded as $package) {
618
                $data['data'][] = array($reg->parsedPackageNameToString($package->getParsedPackage()));
697
                $data['data'][] = array($reg->parsedPackageNameToString($package->getParsedPackage()));
619
            }
698
            }
-
 
699
            $this->ui->outputData($data, 'pretend');
620
            $this->ui->outputData($data, 'pretend');
700
            return true;
621
            return true;
701
        }
622
        }
702
 
623
        $this->installer->setOptions($options);
703
        $this->installer->setOptions($options);
624
        $this->installer->sortPackagesForInstall($downloaded);
704
        $this->installer->sortPackagesForInstall($downloaded);
625
        if (PEAR::isError($err = $this->installer->setDownloadedPackages($downloaded))) {
705
        if (PEAR::isError($err = $this->installer->setDownloadedPackages($downloaded))) {
-
 
706
            $this->raiseError($err->getMessage());
626
            $this->raiseError($err->getMessage());
707
            return true;
627
            return true;
-
 
628
        }
-
 
629
        $extrainfo = array();
-
 
630
        if (isset($options['packagingroot'])) {
-
 
631
            $packrootphp_dir = $this->installer->_prependPath(
-
 
632
                $this->config->get('php_dir', null, 'pear.php.net'),
-
 
633
                $options['packagingroot']);
-
 
634
            $instreg = new PEAR_Registry($packrootphp_dir);
-
 
635
        } else {
708
        }
636
            $instreg = $reg;
709
 
637
        }
710
        $binaries = $extrainfo = array();
638
        foreach ($downloaded as $param) {
711
        foreach ($downloaded as $param) {
639
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
712
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
Line 645... Line 718...
645
                if ($info->getCode() != PEAR_INSTALLER_NOBINARY) {
718
                if ($info->getCode() != PEAR_INSTALLER_NOBINARY) {
646
                    if (!($info = $pkg->installBinary($this->installer))) {
719
                    if (!($info = $pkg->installBinary($this->installer))) {
647
                        $this->ui->outputData('ERROR: ' .$oldinfo->getMessage());
720
                        $this->ui->outputData('ERROR: ' .$oldinfo->getMessage());
648
                        continue;
721
                        continue;
649
                    }
722
                    }
-
 
723
 
650
                    // we just installed a different package than requested,
724
                    // we just installed a different package than requested,
651
                    // let's change the param and info so that the rest of this works
725
                    // let's change the param and info so that the rest of this works
652
                    $param = $info[0];
726
                    $param = $info[0];
653
                    $info = $info[1];
727
                    $info  = $info[1];
654
                }
728
                }
655
            }
729
            }
-
 
730
 
656
            if (is_array($info)) {
731
            if (!is_array($info)) {
-
 
732
                return $this->raiseError("$command failed");
-
 
733
            }
-
 
734
 
657
                if ($param->getPackageType() == 'extsrc' ||
735
            if ($param->getPackageType() == 'extsrc' ||
658
                      $param->getPackageType() == 'extbin' ||
736
                  $param->getPackageType() == 'extbin' ||
659
                      $param->getPackageType() == 'zendextsrc' ||
737
                  $param->getPackageType() == 'zendextsrc' ||
660
                      $param->getPackageType() == 'zendextbin') {
738
                  $param->getPackageType() == 'zendextbin'
-
 
739
            ) {
661
                    $pkg = &$param->getPackageFile();
740
                $pkg = &$param->getPackageFile();
662
                    if ($instbin = $pkg->getInstalledBinary()) {
741
                if ($instbin = $pkg->getInstalledBinary()) {
663
                        $instpkg = &$instreg->getPackage($instbin, $pkg->getChannel());
742
                    $instpkg = &$instreg->getPackage($instbin, $pkg->getChannel());
664
                    } else {
743
                } else {
665
                        $instpkg = &$instreg->getPackage($pkg->getPackage(), $pkg->getChannel());
744
                    $instpkg = &$instreg->getPackage($pkg->getPackage(), $pkg->getChannel());
-
 
745
                }
-
 
746
 
-
 
747
                foreach ($instpkg->getFilelist() as $name => $atts) {
-
 
748
                    $pinfo = pathinfo($atts['installed_as']);
-
 
749
                    if (!isset($pinfo['extension']) ||
-
 
750
                          in_array($pinfo['extension'], array('c', 'h'))
-
 
751
                    ) {
-
 
752
                        continue; // make sure we don't match php_blah.h
666
                    }
753
                    }
667
                    foreach ($instpkg->getFilelist() as $name => $atts) {
-
 
668
                        $pinfo = pathinfo($atts['installed_as']);
-
 
669
                        if (!isset($pinfo['extension']) ||
-
 
670
                              in_array($pinfo['extension'], array('c', 'h'))) {
-
 
671
                            continue; // make sure we don't match php_blah.h
-
 
672
                        }
-
 
-
 
754
 
673
                        if ((strpos($pinfo['basename'], 'php_') === 0 &&
755
                    if ((strpos($pinfo['basename'], 'php_') === 0 &&
674
                              $pinfo['extension'] == 'dll') ||
756
                          $pinfo['extension'] == 'dll') ||
675
                              // most unices
757
                          // most unices
676
                              $pinfo['extension'] == 'so' ||
758
                          $pinfo['extension'] == 'so' ||
677
                              // hp-ux
759
                          // hp-ux
678
                              $pinfo['extension'] == 'sl') {
760
                          $pinfo['extension'] == 'sl') {
679
                            $binaries[] = array($atts['installed_as'], $pinfo);
761
                        $binaries[] = array($atts['installed_as'], $pinfo);
680
                            break;
762
                        break;
681
                        }
-
 
682
                    }
763
                    }
-
 
764
                }
-
 
765
 
-
 
766
                if (count($binaries)) {
683
                    foreach ($binaries as $pinfo) {
767
                    foreach ($binaries as $pinfo) {
684
                        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
768
                        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
685
                        $ret = $this->enableExtension(array($pinfo[0]), $param->getPackageType());
769
                        $ret = $this->enableExtension(array($pinfo[0]), $param->getPackageType());
686
                        PEAR::staticPopErrorHandling();
770
                        PEAR::staticPopErrorHandling();
687
                        if (PEAR::isError($ret)) {
771
                        if (PEAR::isError($ret)) {
688
                            $extrainfo[] = $ret->getMessage();
772
                            $extrainfo[] = $ret->getMessage();
689
                            if ($param->getPackageType() == 'extsrc' ||
773
                            if ($param->getPackageType() == 'extsrc' ||
690
                                  $param->getPackageType() == 'extbin') {
774
                                  $param->getPackageType() == 'extbin') {
691
                                $exttype = 'extension';
775
                                $exttype = 'extension';
-
 
776
                                $extpath = $pinfo[1]['basename'];
692
                            } else {
777
                            } else {
693
                                ob_start();
-
 
694
                                phpinfo(INFO_GENERAL);
-
 
695
                                $info = ob_get_contents();
778
                                $exttype = 'zend_extension';
696
                                ob_end_clean();
-
 
697
                                $debug = function_exists('leak') ? '_debug' : '';
-
 
698
                                $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
-
 
699
                                $exttype = 'zend_extension' . $debug . $ts;
779
                                $extpath = $atts['installed_as'];
700
                            }
780
                            }
701
                            $extrainfo[] = 'You should add "' . $exttype . '=' .
781
                            $extrainfo[] = 'You should add "' . $exttype . '=' .
702
                                $pinfo[1]['basename'] . '" to php.ini';
782
                                $extpath . '" to php.ini';
703
                        } else {
783
                        } else {
704
                            $extrainfo[] = 'Extension ' . $instpkg->getProvidesExtension() .
784
                            $extrainfo[] = 'Extension ' . $instpkg->getProvidesExtension() .
705
                                ' enabled in php.ini';
785
                                ' enabled in php.ini';
706
                        }
786
                        }
707
                    }
787
                    }
708
                }
788
                }
-
 
789
            }
-
 
790
 
709
                if ($this->config->get('verbose') > 0) {
791
            if ($this->config->get('verbose') > 0) {
710
                    $channel = $param->getChannel();
792
                $chan = $param->getChannel();
711
                    $label = $reg->parsedPackageNameToString(
793
                $label = $reg->parsedPackageNameToString(
712
                        array(
794
                    array(
713
                            'channel' => $channel,
795
                        'channel' => $chan,
714
                            'package' => $param->getPackage(),
796
                        'package' => $param->getPackage(),
715
                            'version' => $param->getVersion(),
797
                        'version' => $param->getVersion(),
716
                        ));
798
                    ));
717
                    $out = array('data' => "$command ok: $label");
799
                $out = array('data' => "$command ok: $label");
718
                    if (isset($info['release_warnings'])) {
800
                if (isset($info['release_warnings'])) {
719
                        $out['release_warnings'] = $info['release_warnings'];
801
                    $out['release_warnings'] = $info['release_warnings'];
720
                    }
802
                }
721
                    $this->ui->outputData($out, $command);
803
                $this->ui->outputData($out, $command);
-
 
804
 
722
                    if (!isset($options['register-only']) && !isset($options['offline'])) {
805
                if (!isset($options['register-only']) && !isset($options['offline'])) {
723
                        if ($this->config->isDefinedLayer('ftp')) {
806
                    if ($this->config->isDefinedLayer('ftp')) {
724
                            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
807
                        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
725
                            $info = $this->installer->ftpInstall($param);
808
                        $info = $this->installer->ftpInstall($param);
726
                            PEAR::staticPopErrorHandling();
809
                        PEAR::staticPopErrorHandling();
727
                            if (PEAR::isError($info)) {
810
                        if (PEAR::isError($info)) {
728
                                $this->ui->outputData($info->getMessage());
811
                            $this->ui->outputData($info->getMessage());
729
                                $this->ui->outputData("remote install failed: $label");
812
                            $this->ui->outputData("remote install failed: $label");
730
                            } else {
813
                        } else {
731
                                $this->ui->outputData("remote install ok: $label");
814
                            $this->ui->outputData("remote install ok: $label");
732
                            }
-
 
733
                        }
815
                        }
734
                    }
816
                    }
735
                }
817
                }
-
 
818
            }
-
 
819
 
736
                $deps = $param->getDeps();
820
            $deps = $param->getDeps();
737
                if ($deps) {
821
            if ($deps) {
738
                    if (isset($deps['group'])) {
822
                if (isset($deps['group'])) {
739
                        $groups = $deps['group'];
823
                    $groups = $deps['group'];
740
                        if (!isset($groups[0])) {
824
                    if (!isset($groups[0])) {
741
                            $groups = array($groups);
825
                        $groups = array($groups);
742
                        }
826
                    }
-
 
827
 
743
                        foreach ($groups as $group) {
828
                    foreach ($groups as $group) {
744
                            if ($group['attribs']['name'] == 'default') {
829
                        if ($group['attribs']['name'] == 'default') {
745
                                // default group is always installed, unless the user
830
                            // default group is always installed, unless the user
746
                                // explicitly chooses to install another group
831
                            // explicitly chooses to install another group
747
                                continue;
832
                            continue;
748
                            }
-
 
749
                            $this->ui->outputData($param->getPackage() . ': Optional feature ' .
-
 
750
                                $group['attribs']['name'] . ' available (' .
-
 
751
                                $group['attribs']['hint'] . ')');
-
 
752
                        }
833
                        }
753
                        $extrainfo[] = 'To install use "pear install ' .
834
                        $extrainfo[] = $param->getPackage() . ': Optional feature ' .
754
                            $reg->parsedPackageNameToString(
-
 
755
                                array('package' => $param->getPackage(),
835
                            $group['attribs']['name'] . ' available (' .
756
                                      'channel' => $param->getChannel()), true) .
-
 
757
                                  '#featurename"';
836
                            $group['attribs']['hint'] . ')';
758
                    }
837
                    }
-
 
838
 
-
 
839
                    $extrainfo[] = $param->getPackage() .
-
 
840
                        ': To install optional features use "pear install ' .
-
 
841
                        $reg->parsedPackageNameToString(
-
 
842
                            array('package' => $param->getPackage(),
-
 
843
                                  'channel' => $param->getChannel()), true) .
-
 
844
                              '#featurename"';
759
                }
845
                }
760
                if (isset($options['installroot'])) {
-
 
761
                    $reg = &$this->config->getRegistry();
-
 
762
                }
846
            }
763
                if (isset($options['packagingroot'])) {
-
 
764
                    $instreg = new PEAR_Registry($packrootphp_dir);
-
 
765
                } else {
-
 
766
                    $instreg = $reg;
-
 
767
                }
-
 
-
 
847
 
768
                $pkg = &$instreg->getPackage($param->getPackage(), $param->getChannel());
848
            $pkg = &$instreg->getPackage($param->getPackage(), $param->getChannel());
769
                // $pkg may be NULL if install is a 'fake' install via --packagingroot
849
            // $pkg may be NULL if install is a 'fake' install via --packagingroot
770
                if (is_object($pkg)) {
850
            if (is_object($pkg)) {
771
                    $pkg->setConfig($this->config);
851
                $pkg->setConfig($this->config);
772
                    if ($list = $pkg->listPostinstallScripts()) {
852
                if ($list = $pkg->listPostinstallScripts()) {
773
                        $pn = $reg->parsedPackageNameToString(array('channel' =>
853
                    $pn = $reg->parsedPackageNameToString(array('channel' =>
774
                           $param->getChannel(), 'package' => $param->getPackage()), true);
854
                       $param->getChannel(), 'package' => $param->getPackage()), true);
775
                        $extrainfo[] = $pn . ' has post-install scripts:';
855
                    $extrainfo[] = $pn . ' has post-install scripts:';
776
                        foreach ($list as $file) {
856
                    foreach ($list as $file) {
777
                            $extrainfo[] = $file;
857
                        $extrainfo[] = $file;
778
                        }
-
 
779
                        $extrainfo[] = 'Use "pear run-scripts ' . $pn . '" to run';
-
 
780
                        $extrainfo[] = 'DO NOT RUN SCRIPTS FROM UNTRUSTED SOURCES';
-
 
781
                    }
858
                    }
-
 
859
                    $extrainfo[] = $param->getPackage() .
-
 
860
                        ': Use "pear run-scripts ' . $pn . '" to finish setup.';
-
 
861
                    $extrainfo[] = 'DO NOT RUN SCRIPTS FROM UNTRUSTED SOURCES';
782
                }
862
                }
783
            } else {
-
 
784
                return $this->raiseError("$command failed");
-
 
785
            }
863
            }
786
        }
864
        }
-
 
865
 
787
        if (count($extrainfo)) {
866
        if (count($extrainfo)) {
788
            foreach ($extrainfo as $info) {
867
            foreach ($extrainfo as $info) {
789
                $this->ui->outputData($info);
868
                $this->ui->outputData($info);
790
            }
869
            }
791
        }
870
        }
-
 
871
 
792
        return true;
872
        return true;
793
    }
873
    }
Line 794... Line 874...
794
 
874
 
-
 
875
    // }}}
-
 
876
    // {{{ doUpgradeAll()
-
 
877
 
-
 
878
    function doUpgradeAll($command, $options, $params)
-
 
879
    {
-
 
880
        $reg = &$this->config->getRegistry();
-
 
881
        $upgrade = array();
-
 
882
 
-
 
883
        if (isset($options['channel'])) {
-
 
884
            $channels = array($options['channel']);
-
 
885
        } else {
-
 
886
            $channels = $reg->listChannels();
-
 
887
        }
-
 
888
 
-
 
889
        foreach ($channels as $channel) {
-
 
890
            if ($channel == '__uri') {
-
 
891
                continue;
-
 
892
            }
-
 
893
 
-
 
894
            // parse name with channel
-
 
895
            foreach ($reg->listPackages($channel) as $name) {
-
 
896
                $upgrade[] = $reg->parsedPackageNameToString(array(
-
 
897
                        'channel' => $channel,
-
 
898
                        'package' => $name
-
 
899
                    ));
-
 
900
            }
-
 
901
        }
-
 
902
 
-
 
903
        $err = $this->doInstall($command, $options, $upgrade);
-
 
904
        if (PEAR::isError($err)) {
-
 
905
            $this->ui->outputData($err->getMessage(), $command);
-
 
906
        }
-
 
907
   }
-
 
908
 
795
    // }}}
909
    // }}}
Line 796... Line 910...
796
    // {{{ doUninstall()
910
    // {{{ doUninstall()
797
 
911
 
-
 
912
    function doUninstall($command, $options, $params)
-
 
913
    {
-
 
914
        if (count($params) < 1) {
-
 
915
            return $this->raiseError("Please supply the package(s) you want to uninstall");
798
    function doUninstall($command, $options, $params)
916
        }
799
    {
917
 
800
        if (empty($this->installer)) {
918
        if (empty($this->installer)) {
-
 
919
            $this->installer = &$this->getInstaller($this->ui);
801
            $this->installer = &$this->getInstaller($this->ui);
920
        }
802
        }
921
 
803
        if (isset($options['remoteconfig'])) {
922
        if (isset($options['remoteconfig'])) {
804
            $e = $this->config->readFTPConfigFile($options['remoteconfig']);
923
            $e = $this->config->readFTPConfigFile($options['remoteconfig']);
805
            if (!PEAR::isError($e)) {
924
            if (!PEAR::isError($e)) {
806
                $this->installer->setConfig($this->config);
925
                $this->installer->setConfig($this->config);
807
            }
-
 
808
        }
-
 
809
        if (sizeof($params) < 1) {
926
            }
810
            return $this->raiseError("Please supply the package(s) you want to uninstall");
927
        }
811
        }
928
 
-
 
929
        $reg = &$this->config->getRegistry();
812
        $reg = &$this->config->getRegistry();
930
        $newparams = array();
813
        $newparams = array();
931
        $binaries = array();
814
        $badparams = array();
932
        $badparams = array();
815
        foreach ($params as $pkg) {
933
        foreach ($params as $pkg) {
816
            $channel = $this->config->get('default_channel');
934
            $channel = $this->config->get('default_channel');
Line 847... Line 965...
847
                }
965
                }
848
                // add the contents of a dependency group to the list of installed packages
966
                // add the contents of a dependency group to the list of installed packages
849
                if (isset($parsed['group'])) {
967
                if (isset($parsed['group'])) {
850
                    $group = $info->getDependencyGroup($parsed['group']);
968
                    $group = $info->getDependencyGroup($parsed['group']);
851
                    if ($group) {
969
                    if ($group) {
852
                        $installed = &$reg->getInstalledGroup($group);
970
                        $installed = $reg->getInstalledGroup($group);
853
                        if ($installed) {
971
                        if ($installed) {
854
                            foreach ($installed as $i => $p) {
972
                            foreach ($installed as $i => $p) {
855
                                $newparams[] = &$installed[$i];
973
                                $newparams[] = &$installed[$i];
856
                            }
974
                            }
857
                        }
975
                        }
Line 867... Line 985...
867
        $params = $newparams;
985
        $params = $newparams;
868
        // twist this to use it to check on whether dependent packages are also being uninstalled
986
        // twist this to use it to check on whether dependent packages are also being uninstalled
869
        // for circular dependencies like subpackages
987
        // for circular dependencies like subpackages
870
        $this->installer->setUninstallPackages($newparams);
988
        $this->installer->setUninstallPackages($newparams);
871
        $params = array_merge($params, $badparams);
989
        $params = array_merge($params, $badparams);
-
 
990
        $binaries = array();
872
        foreach ($params as $pkg) {
991
        foreach ($params as $pkg) {
873
            $this->installer->pushErrorHandling(PEAR_ERROR_RETURN);
992
            $this->installer->pushErrorHandling(PEAR_ERROR_RETURN);
874
            if ($err = $this->installer->uninstall($pkg, $options)) {
993
            if ($err = $this->installer->uninstall($pkg, $options)) {
875
                $this->installer->popErrorHandling();
994
                $this->installer->popErrorHandling();
876
                if (PEAR::isError($err)) {
995
                if (PEAR::isError($err)) {
Line 882... Line 1001...
882
                      $pkg->getPackageType() == 'zendextsrc' ||
1001
                      $pkg->getPackageType() == 'zendextsrc' ||
883
                      $pkg->getPackageType() == 'zendextbin') {
1002
                      $pkg->getPackageType() == 'zendextbin') {
884
                    if ($instbin = $pkg->getInstalledBinary()) {
1003
                    if ($instbin = $pkg->getInstalledBinary()) {
885
                        continue; // this will be uninstalled later
1004
                        continue; // this will be uninstalled later
886
                    }
1005
                    }
-
 
1006
 
887
                    foreach ($pkg->getFilelist() as $name => $atts) {
1007
                    foreach ($pkg->getFilelist() as $name => $atts) {
888
                        $pinfo = pathinfo($atts['installed_as']);
1008
                        $pinfo = pathinfo($atts['installed_as']);
889
                        if (!isset($pinfo['extension']) ||
1009
                        if (!isset($pinfo['extension']) ||
890
                              in_array($pinfo['extension'], array('c', 'h'))) {
1010
                              in_array($pinfo['extension'], array('c', 'h'))) {
891
                            continue; // make sure we don't match php_blah.h
1011
                            continue; // make sure we don't match php_blah.h
Line 898... Line 1018...
898
                              $pinfo['extension'] == 'sl') {
1018
                              $pinfo['extension'] == 'sl') {
899
                            $binaries[] = array($atts['installed_as'], $pinfo);
1019
                            $binaries[] = array($atts['installed_as'], $pinfo);
900
                            break;
1020
                            break;
901
                        }
1021
                        }
902
                    }
1022
                    }
-
 
1023
                    if (count($binaries)) {
903
                    foreach ($binaries as $pinfo) {
1024
                        foreach ($binaries as $pinfo) {
904
                        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
1025
                            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
905
                        $ret = $this->disableExtension(array($pinfo[0]), $pkg->getPackageType());
1026
                            $ret = $this->disableExtension(array($pinfo[0]), $pkg->getPackageType());
906
                        PEAR::staticPopErrorHandling();
1027
                            PEAR::staticPopErrorHandling();
907
                        if (PEAR::isError($ret)) {
1028
                            if (PEAR::isError($ret)) {
908
                            $extrainfo[] = $ret->getMessage();
1029
                                $extrainfo[] = $ret->getMessage();
909
                            if ($pkg->getPackageType() == 'extsrc' ||
1030
                                if ($pkg->getPackageType() == 'extsrc' ||
910
                                  $pkg->getPackageType() == 'extbin') {
1031
                                      $pkg->getPackageType() == 'extbin') {
911
                                $exttype = 'extension';
1032
                                    $exttype = 'extension';
-
 
1033
                                } else {
-
 
1034
                                    ob_start();
-
 
1035
                                    phpinfo(INFO_GENERAL);
-
 
1036
                                    $info = ob_get_contents();
-
 
1037
                                    ob_end_clean();
-
 
1038
                                    $debug = function_exists('leak') ? '_debug' : '';
-
 
1039
                                    $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
-
 
1040
                                    $exttype = 'zend_extension' . $debug . $ts;
-
 
1041
                                }
-
 
1042
                                $this->ui->outputData('Unable to remove "' . $exttype . '=' .
-
 
1043
                                    $pinfo[1]['basename'] . '" from php.ini', $command);
912
                            } else {
1044
                            } else {
913
                                ob_start();
-
 
914
                                phpinfo(INFO_GENERAL);
-
 
915
                                $info = ob_get_contents();
-
 
916
                                ob_end_clean();
-
 
917
                                $debug = function_exists('leak') ? '_debug' : '';
-
 
918
                                $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
1045
                                $this->ui->outputData('Extension ' . $pkg->getProvidesExtension() .
919
                                $exttype = 'zend_extension' . $debug . $ts;
1046
                                    ' disabled in php.ini', $command);
920
                            }
1047
                            }
921
                            $this->ui->outputData('Unable to remove "' . $exttype . '=' .
-
 
922
                                $pinfo[1]['basename'] . '" from php.ini', $command);
-
 
923
                        } else {
-
 
924
                            $this->ui->outputData('Extension ' . $pkg->getProvidesExtension() .
-
 
925
                                ' disabled in php.ini', $command);
-
 
926
                        }
1048
                        }
927
                    }
1049
                    }
928
                }
1050
                }
929
                $savepkg = $pkg;
1051
                $savepkg = $pkg;
930
                if ($this->config->get('verbose') > 0) {
1052
                if ($this->config->get('verbose') > 0) {
Line 947... Line 1069...
947
                        }
1069
                        }
948
                    }
1070
                    }
949
                }
1071
                }
950
            } else {
1072
            } else {
951
                $this->installer->popErrorHandling();
1073
                $this->installer->popErrorHandling();
952
                if (is_object($pkg)) {
1074
                if (!is_object($pkg)) {
953
                    $pkg = $reg->parsedPackageNameToString($pkg);
1075
                    return $this->raiseError("uninstall failed: $pkg");
954
                }
1076
                }
955
                return $this->raiseError("uninstall failed: $pkg");
1077
                $pkg = $reg->parsedPackageNameToString($pkg);
956
            }
1078
            }
957
        }
1079
        }
-
 
1080
 
958
        return true;
1081
        return true;
959
    }
1082
    }
Line 960... Line 1083...
960
 
1083
 
Line 968... Line 1091...
968
            any check that the PEAR_Installer::_installFile() does.
1091
            any check that the PEAR_Installer::_installFile() does.
969
    */
1092
    */
Line 970... Line 1093...
970
 
1093
 
971
    function doBundle($command, $options, $params)
1094
    function doBundle($command, $options, $params)
-
 
1095
    {
972
    {
1096
        $opts = array(
-
 
1097
            'force'        => true,
-
 
1098
            'nodeps'       => true,
-
 
1099
            'soft'         => true,
-
 
1100
            'downloadonly' => true
973
        $downloader = &$this->getDownloader($this->ui, array('force' => true, 'nodeps' => true,
1101
        );
974
            'soft' => true, 'downloadonly' => true), $this->config);
1102
        $downloader = &$this->getDownloader($this->ui, $opts, $this->config);
975
        $reg = &$this->config->getRegistry();
1103
        $reg = &$this->config->getRegistry();
976
        if (sizeof($params) < 1) {
1104
        if (count($params) < 1) {
977
            return $this->raiseError("Please supply the package you want to bundle");
1105
            return $this->raiseError("Please supply the package you want to bundle");
Line 978... Line 1106...
978
        }
1106
        }
979
 
1107
 
980
        if (isset($options['destination'])) {
1108
        if (isset($options['destination'])) {
981
            if (!is_dir($options['destination'])) {
1109
            if (!is_dir($options['destination'])) {
982
                System::mkdir('-p ' . $options['destination']);
1110
                System::mkdir('-p ' . $options['destination']);
983
            }
1111
            }
984
            $dest = realpath($options['destination']);
1112
            $dest = realpath($options['destination']);
985
        } else {
1113
        } else {
986
            $pwd = getcwd();
1114
            $pwd  = getcwd();
987
            if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) {
1115
            $dir  = $pwd . DIRECTORY_SEPARATOR . 'ext';
-
 
1116
            $dest = is_dir($dir) ? $dir : $pwd;
-
 
1117
        }
-
 
1118
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
988
                $dest = $pwd . DIRECTORY_SEPARATOR . 'ext';
1119
        $err = $downloader->setDownloadDir($dest);
-
 
1120
        PEAR::staticPopErrorHandling();
989
            } else {
1121
        if (PEAR::isError($err)) {
990
                $dest = $pwd;
1122
            return PEAR::raiseError('download directory "' . $dest .
991
            }
-
 
992
        }
1123
                '" is not writeable.');
993
        $downloader->setDownloadDir($dest);
1124
        }
994
        $result = &$downloader->download(array($params[0]));
1125
        $result = &$downloader->download(array($params[0]));
995
        if (PEAR::isError($result)) {
1126
        if (PEAR::isError($result)) {
-
 
1127
            return $result;
-
 
1128
        }
-
 
1129
        if (!isset($result[0])) {
996
            return $result;
1130
            return $this->raiseError('unable to unpack ' . $params[0]);
997
        }
1131
        }
998
        $pkgfile = &$result[0]->getPackageFile();
1132
        $pkgfile = &$result[0]->getPackageFile();
Line 999... Line 1133...
999
        $pkgname = $pkgfile->getName();
1133
        $pkgname = $pkgfile->getName();
1000
        $pkgversion = $pkgfile->getVersion();
1134
        $pkgversion = $pkgfile->getVersion();
1001
 
1135
 
Line 1002... Line 1136...
1002
        // Unpacking -------------------------------------------------
1136
        // Unpacking -------------------------------------------------
1003
        $dest .= DIRECTORY_SEPARATOR . $pkgname;
1137
        $dest .= DIRECTORY_SEPARATOR . $pkgname;
1004
        $orig = $pkgname . '-' . $pkgversion;
1138
        $orig = $pkgname . '-' . $pkgversion;
1005
 
1139
 
1006
        $tar = &new Archive_Tar($pkgfile->getArchiveFile());
1140
        $tar = new Archive_Tar($pkgfile->getArchiveFile());
1007
        if (!$tar->extractModify($dest, $orig)) {
1141
        if (!$tar->extractModify($dest, $orig)) {
Line 1016... Line 1150...
1016
    function doRunScripts($command, $options, $params)
1150
    function doRunScripts($command, $options, $params)
1017
    {
1151
    {
1018
        if (!isset($params[0])) {
1152
        if (!isset($params[0])) {
1019
            return $this->raiseError('run-scripts expects 1 parameter: a package name');
1153
            return $this->raiseError('run-scripts expects 1 parameter: a package name');
1020
        }
1154
        }
-
 
1155
 
1021
        $reg = &$this->config->getRegistry();
1156
        $reg = &$this->config->getRegistry();
1022
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
1157
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
1023
        $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
1158
        $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
1024
        PEAR::staticPopErrorHandling();
1159
        PEAR::staticPopErrorHandling();
1025
        if (PEAR::isError($parsed)) {
1160
        if (PEAR::isError($parsed)) {
1026
            return $this->raiseError($parsed);
1161
            return $this->raiseError($parsed);
1027
        }
1162
        }
-
 
1163
 
1028
        $package = &$reg->getPackage($parsed['package'], $parsed['channel']);
1164
        $package = &$reg->getPackage($parsed['package'], $parsed['channel']);
1029
        if (is_object($package)) {
1165
        if (!is_object($package)) {
1030
            $package->setConfig($this->config);
-
 
1031
            $package->runPostinstallScripts();
-
 
1032
        } else {
-
 
1033
            return $this->raiseError('Could not retrieve package "' . $params[0] . '" from registry');
1166
            return $this->raiseError('Could not retrieve package "' . $params[0] . '" from registry');
1034
        }
1167
        }
-
 
1168
 
-
 
1169
        $package->setConfig($this->config);
-
 
1170
        $package->runPostinstallScripts();
1035
        $this->ui->outputData('Install scripts complete', $command);
1171
        $this->ui->outputData('Install scripts complete', $command);
1036
        return true;
1172
        return true;
1037
    }
1173
    }
-
 
1174
 
-
 
1175
    /**
-
 
1176
     * Given a list of packages, filter out those ones that are already up to date
-
 
1177
     *
-
 
1178
     * @param $packages: packages, in parsed array format !
-
 
1179
     * @return list of packages that can be upgraded
-
 
1180
     */
-
 
1181
    function _filterUptodatePackages($packages, $command)
-
 
1182
    {
-
 
1183
        $reg = &$this->config->getRegistry();
-
 
1184
        $latestReleases = array();
-
 
1185
 
-
 
1186
        $ret = array();
-
 
1187
        foreach ($packages as $package) {
-
 
1188
            if (isset($package['group'])) {
-
 
1189
                $ret[] = $package;
-
 
1190
                continue;
-
 
1191
            }
-
 
1192
 
-
 
1193
            $channel = $package['channel'];
-
 
1194
            $name    = $package['package'];
-
 
1195
            if (!$reg->packageExists($name, $channel)) {
-
 
1196
                $ret[] = $package;
-
 
1197
                continue;
-
 
1198
            }
-
 
1199
 
-
 
1200
            if (!isset($latestReleases[$channel])) {
-
 
1201
                // fill in cache for this channel
-
 
1202
                $chan = $reg->getChannel($channel);
-
 
1203
                if (PEAR::isError($chan)) {
-
 
1204
                    return $this->raiseError($chan);
-
 
1205
                }
-
 
1206
 
-
 
1207
                $base2 = false;
-
 
1208
                $preferred_mirror = $this->config->get('preferred_mirror', null, $channel);
-
 
1209
                if ($chan->supportsREST($preferred_mirror) &&
-
 
1210
                    (
-
 
1211
                       //($base2 = $chan->getBaseURL('REST1.4', $preferred_mirror)) ||
-
 
1212
                       ($base  = $chan->getBaseURL('REST1.0', $preferred_mirror))
-
 
1213
                    )
-
 
1214
                ) {
-
 
1215
                    $dorest = true;
-
 
1216
                }
-
 
1217
 
-
 
1218
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
1219
                if (!isset($package['state'])) {
-
 
1220
                    $state = $this->config->get('preferred_state', null, $channel);
-
 
1221
                } else {
-
 
1222
                    $state = $package['state'];
-
 
1223
                }
-
 
1224
 
-
 
1225
                if ($dorest) {
-
 
1226
                    if ($base2) {
-
 
1227
                        $rest = &$this->config->getREST('1.4', array());
-
 
1228
                        $base = $base2;
-
 
1229
                    } else {
-
 
1230
                        $rest = &$this->config->getREST('1.0', array());
-
 
1231
                    }
-
 
1232
 
-
 
1233
                    $installed = array_flip($reg->listPackages($channel));
-
 
1234
                    $latest    = $rest->listLatestUpgrades($base, $state, $installed, $channel, $reg);
-
 
1235
                }
-
 
1236
 
-
 
1237
                PEAR::staticPopErrorHandling();
-
 
1238
                if (PEAR::isError($latest)) {
-
 
1239
                    $this->ui->outputData('Error getting channel info from ' . $channel .
-
 
1240
                        ': ' . $latest->getMessage());
-
 
1241
                    continue;
-
 
1242
                }
-
 
1243
 
-
 
1244
                $latestReleases[$channel] = array_change_key_case($latest);
-
 
1245
            }
-
 
1246
 
-
 
1247
            // check package for latest release
-
 
1248
            $name_lower = strtolower($name);
-
 
1249
            if (isset($latestReleases[$channel][$name_lower])) {
-
 
1250
                // if not set, up to date
-
 
1251
                $inst_version    = $reg->packageInfo($name, 'version', $channel);
-
 
1252
                $channel_version = $latestReleases[$channel][$name_lower]['version'];
-
 
1253
                if (version_compare($channel_version, $inst_version, 'le')) {
-
 
1254
                    // installed version is up-to-date
-
 
1255
                    continue;
-
 
1256
                }
-
 
1257
 
-
 
1258
                // maintain BC
-
 
1259
                if ($command == 'upgrade-all') {
-
 
1260
                    $this->ui->outputData(array('data' => 'Will upgrade ' .
-
 
1261
                        $reg->parsedPackageNameToString($package)), $command);
-
 
1262
                }
-
 
1263
                $ret[] = $package;
-
 
1264
            }
-
 
1265
        }
-
 
1266
 
-
 
1267
        return $ret;
-
 
1268
    }
1038
}
1269
}
1039
?>
-