94 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PEAR_REST_10
|
|
|
4 |
*
|
|
|
5 |
* PHP versions 4 and 5
|
|
|
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
|
|
|
14 |
* @package PEAR
|
|
|
15 |
* @author Greg Beaver <cellog@php.net>
|
|
|
16 |
* @copyright 1997-2006 The PHP Group
|
|
|
17 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
18 |
* @version CVS: $Id: 10.php,v 1.43 2006/11/01 05:09:05 cellog Exp $
|
|
|
19 |
* @link http://pear.php.net/package/PEAR
|
|
|
20 |
* @since File available since Release 1.4.0a12
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* For downloading REST xml/txt files
|
|
|
25 |
*/
|
|
|
26 |
require_once 'PEAR/REST.php';
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Implement REST 1.0
|
|
|
30 |
*
|
|
|
31 |
* @category pear
|
|
|
32 |
* @package PEAR
|
|
|
33 |
* @author Greg Beaver <cellog@php.net>
|
|
|
34 |
* @copyright 1997-2006 The PHP Group
|
|
|
35 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
36 |
* @version Release: 1.5.1
|
|
|
37 |
* @link http://pear.php.net/package/PEAR
|
|
|
38 |
* @since Class available since Release 1.4.0a12
|
|
|
39 |
*/
|
|
|
40 |
class PEAR_REST_10
|
|
|
41 |
{
|
|
|
42 |
/**
|
|
|
43 |
* @var PEAR_REST
|
|
|
44 |
*/
|
|
|
45 |
var $_rest;
|
|
|
46 |
function PEAR_REST_10($config, $options = array())
|
|
|
47 |
{
|
|
|
48 |
$this->_rest = &new PEAR_REST($config, $options);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Retrieve information about a remote package to be downloaded from a REST server
|
|
|
53 |
*
|
|
|
54 |
* @param string $base The uri to prepend to all REST calls
|
|
|
55 |
* @param array $packageinfo an array of format:
|
|
|
56 |
* <pre>
|
|
|
57 |
* array(
|
|
|
58 |
* 'package' => 'packagename',
|
|
|
59 |
* 'channel' => 'channelname',
|
|
|
60 |
* ['state' => 'alpha' (or valid state),]
|
|
|
61 |
* -or-
|
|
|
62 |
* ['version' => '1.whatever']
|
|
|
63 |
* </pre>
|
|
|
64 |
* @param string $prefstate Current preferred_state config variable value
|
|
|
65 |
* @param bool $installed the installed version of this package to compare against
|
|
|
66 |
* @return array|false|PEAR_Error see {@link _returnDownloadURL()}
|
|
|
67 |
*/
|
|
|
68 |
function getDownloadURL($base, $packageinfo, $prefstate, $installed)
|
|
|
69 |
{
|
|
|
70 |
$channel = $packageinfo['channel'];
|
|
|
71 |
$package = $packageinfo['package'];
|
|
|
72 |
$states = $this->betterStates($prefstate, true);
|
|
|
73 |
if (!$states) {
|
|
|
74 |
return PEAR::raiseError('"' . $prefstate . '" is not a valid state');
|
|
|
75 |
}
|
|
|
76 |
$state = $version = null;
|
|
|
77 |
if (isset($packageinfo['state'])) {
|
|
|
78 |
$state = $packageinfo['state'];
|
|
|
79 |
}
|
|
|
80 |
if (isset($packageinfo['version'])) {
|
|
|
81 |
$version = $packageinfo['version'];
|
|
|
82 |
}
|
|
|
83 |
$info = $this->_rest->retrieveData($base . 'r/' . strtolower($package) . '/allreleases.xml');
|
|
|
84 |
if (PEAR::isError($info)) {
|
|
|
85 |
return PEAR::raiseError('No releases available for package "' .
|
|
|
86 |
$channel . '/' . $package . '"');
|
|
|
87 |
}
|
|
|
88 |
if (!isset($info['r'])) {
|
|
|
89 |
return false;
|
|
|
90 |
}
|
|
|
91 |
$found = false;
|
|
|
92 |
$release = false;
|
|
|
93 |
if (!is_array($info['r']) || !isset($info['r'][0])) {
|
|
|
94 |
$info['r'] = array($info['r']);
|
|
|
95 |
}
|
|
|
96 |
foreach ($info['r'] as $release) {
|
|
|
97 |
if (!isset($this->_rest->_options['force']) && ($installed &&
|
|
|
98 |
version_compare($release['v'], $installed, '<'))) {
|
|
|
99 |
continue;
|
|
|
100 |
}
|
|
|
101 |
if (isset($state)) {
|
|
|
102 |
// try our preferred state first
|
|
|
103 |
if ($release['s'] == $state) {
|
|
|
104 |
$found = true;
|
|
|
105 |
break;
|
|
|
106 |
}
|
|
|
107 |
// see if there is something newer and more stable
|
|
|
108 |
// bug #7221
|
|
|
109 |
if (in_array($release['s'], $this->betterStates($state), true)) {
|
|
|
110 |
$found = true;
|
|
|
111 |
break;
|
|
|
112 |
}
|
|
|
113 |
} elseif (isset($version)) {
|
|
|
114 |
if ($release['v'] == $version) {
|
|
|
115 |
$found = true;
|
|
|
116 |
break;
|
|
|
117 |
}
|
|
|
118 |
} else {
|
|
|
119 |
if (in_array($release['s'], $states)) {
|
|
|
120 |
$found = true;
|
|
|
121 |
break;
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
return $this->_returnDownloadURL($base, $package, $release, $info, $found);
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
function getDepDownloadURL($base, $xsdversion, $dependency, $deppackage,
|
|
|
129 |
$prefstate = 'stable', $installed = false)
|
|
|
130 |
{
|
|
|
131 |
$channel = $dependency['channel'];
|
|
|
132 |
$package = $dependency['name'];
|
|
|
133 |
$states = $this->betterStates($prefstate, true);
|
|
|
134 |
if (!$states) {
|
|
|
135 |
return PEAR::raiseError('"' . $prefstate . '" is not a valid state');
|
|
|
136 |
}
|
|
|
137 |
$state = $version = null;
|
|
|
138 |
if (isset($packageinfo['state'])) {
|
|
|
139 |
$state = $packageinfo['state'];
|
|
|
140 |
}
|
|
|
141 |
if (isset($packageinfo['version'])) {
|
|
|
142 |
$version = $packageinfo['version'];
|
|
|
143 |
}
|
|
|
144 |
$info = $this->_rest->retrieveData($base . 'r/' . strtolower($package) . '/allreleases.xml');
|
|
|
145 |
if (PEAR::isError($info)) {
|
|
|
146 |
return PEAR::raiseError('Package "' . $deppackage['channel'] . '/' . $deppackage['package']
|
|
|
147 |
. '" dependency "' . $channel . '/' . $package . '" has no releases');
|
|
|
148 |
}
|
|
|
149 |
if (!is_array($info) || !isset($info['r'])) {
|
|
|
150 |
return false;
|
|
|
151 |
}
|
|
|
152 |
$exclude = array();
|
|
|
153 |
$min = $max = $recommended = false;
|
|
|
154 |
if ($xsdversion == '1.0') {
|
|
|
155 |
$pinfo['package'] = $dependency['name'];
|
|
|
156 |
$pinfo['channel'] = 'pear.php.net'; // this is always true - don't change this
|
|
|
157 |
switch ($dependency['rel']) {
|
|
|
158 |
case 'ge' :
|
|
|
159 |
$min = $dependency['version'];
|
|
|
160 |
break;
|
|
|
161 |
case 'gt' :
|
|
|
162 |
$min = $dependency['version'];
|
|
|
163 |
$exclude = array($dependency['version']);
|
|
|
164 |
break;
|
|
|
165 |
case 'eq' :
|
|
|
166 |
$recommended = $dependency['version'];
|
|
|
167 |
break;
|
|
|
168 |
case 'lt' :
|
|
|
169 |
$max = $dependency['version'];
|
|
|
170 |
$exclude = array($dependency['version']);
|
|
|
171 |
break;
|
|
|
172 |
case 'le' :
|
|
|
173 |
$max = $dependency['version'];
|
|
|
174 |
break;
|
|
|
175 |
case 'ne' :
|
|
|
176 |
$exclude = array($dependency['version']);
|
|
|
177 |
break;
|
|
|
178 |
}
|
|
|
179 |
} else {
|
|
|
180 |
$pinfo['package'] = $dependency['name'];
|
|
|
181 |
$min = isset($dependency['min']) ? $dependency['min'] : false;
|
|
|
182 |
$max = isset($dependency['max']) ? $dependency['max'] : false;
|
|
|
183 |
$recommended = isset($dependency['recommended']) ?
|
|
|
184 |
$dependency['recommended'] : false;
|
|
|
185 |
if (isset($dependency['exclude'])) {
|
|
|
186 |
if (!isset($dependency['exclude'][0])) {
|
|
|
187 |
$exclude = array($dependency['exclude']);
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
$found = false;
|
|
|
192 |
$release = false;
|
|
|
193 |
if (!is_array($info['r']) || !isset($info['r'][0])) {
|
|
|
194 |
$info['r'] = array($info['r']);
|
|
|
195 |
}
|
|
|
196 |
foreach ($info['r'] as $release) {
|
|
|
197 |
if (!isset($this->_rest->_options['force']) && ($installed &&
|
|
|
198 |
version_compare($release['v'], $installed, '<'))) {
|
|
|
199 |
continue;
|
|
|
200 |
}
|
|
|
201 |
if (in_array($release['v'], $exclude)) { // skip excluded versions
|
|
|
202 |
continue;
|
|
|
203 |
}
|
|
|
204 |
// allow newer releases to say "I'm OK with the dependent package"
|
|
|
205 |
if ($xsdversion == '2.0' && isset($release['co'])) {
|
|
|
206 |
if (!is_array($release['co']) || !isset($release['co'][0])) {
|
|
|
207 |
$release['co'] = array($release['co']);
|
|
|
208 |
}
|
|
|
209 |
foreach ($release['co'] as $entry) {
|
|
|
210 |
if (isset($entry['x']) && !is_array($entry['x'])) {
|
|
|
211 |
$entry['x'] = array($entry['x']);
|
|
|
212 |
} elseif (!isset($entry['x'])) {
|
|
|
213 |
$entry['x'] = array();
|
|
|
214 |
}
|
|
|
215 |
if ($entry['c'] == $deppackage['channel'] &&
|
|
|
216 |
strtolower($entry['p']) == strtolower($deppackage['package']) &&
|
|
|
217 |
version_compare($deppackage['version'], $entry['min'], '>=') &&
|
|
|
218 |
version_compare($deppackage['version'], $entry['max'], '<=') &&
|
|
|
219 |
!in_array($release['v'], $entry['x'])) {
|
|
|
220 |
$recommended = $release['v'];
|
|
|
221 |
break;
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
if ($recommended) {
|
|
|
226 |
if ($release['v'] != $recommended) { // if we want a specific
|
|
|
227 |
// version, then skip all others
|
|
|
228 |
continue;
|
|
|
229 |
} else {
|
|
|
230 |
if (!in_array($release['s'], $states)) {
|
|
|
231 |
// the stability is too low, but we must return the
|
|
|
232 |
// recommended version if possible
|
|
|
233 |
return $this->_returnDownloadURL($base, $package, $release, $info, true);
|
|
|
234 |
}
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
if ($min && version_compare($release['v'], $min, 'lt')) { // skip too old versions
|
|
|
238 |
continue;
|
|
|
239 |
}
|
|
|
240 |
if ($max && version_compare($release['v'], $max, 'gt')) { // skip too new versions
|
|
|
241 |
continue;
|
|
|
242 |
}
|
|
|
243 |
if ($installed && version_compare($release['v'], $installed, '<')) {
|
|
|
244 |
continue;
|
|
|
245 |
}
|
|
|
246 |
if (in_array($release['s'], $states)) { // if in the preferred state...
|
|
|
247 |
$found = true; // ... then use it
|
|
|
248 |
break;
|
|
|
249 |
}
|
|
|
250 |
}
|
|
|
251 |
return $this->_returnDownloadURL($base, $package, $release, $info, $found);
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
/**
|
|
|
255 |
* Take raw data and return the array needed for processing a download URL
|
|
|
256 |
*
|
|
|
257 |
* @param string $base REST base uri
|
|
|
258 |
* @param string $package Package name
|
|
|
259 |
* @param array $release an array of format array('v' => version, 's' => state)
|
|
|
260 |
* describing the release to download
|
|
|
261 |
* @param array $info list of all releases as defined by allreleases.xml
|
|
|
262 |
* @param bool $found determines whether the release was found or this is the next
|
|
|
263 |
* best alternative
|
|
|
264 |
* @return array|PEAR_Error
|
|
|
265 |
* @access private
|
|
|
266 |
*/
|
|
|
267 |
function _returnDownloadURL($base, $package, $release, $info, $found)
|
|
|
268 |
{
|
|
|
269 |
if (!$found) {
|
|
|
270 |
$release = $info['r'][0];
|
|
|
271 |
}
|
|
|
272 |
$pinfo = $this->_rest->retrieveCacheFirst($base . 'p/' . strtolower($package) . '/' .
|
|
|
273 |
'info.xml');
|
|
|
274 |
if (PEAR::isError($pinfo)) {
|
|
|
275 |
return PEAR::raiseError('Package "' . $package .
|
|
|
276 |
'" does not have REST info xml available');
|
|
|
277 |
}
|
|
|
278 |
$releaseinfo = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/' .
|
|
|
279 |
$release['v'] . '.xml');
|
|
|
280 |
if (PEAR::isError($releaseinfo)) {
|
|
|
281 |
return PEAR::raiseError('Package "' . $package . '" Version "' . $release['v'] .
|
|
|
282 |
'" does not have REST xml available');
|
|
|
283 |
}
|
|
|
284 |
$packagexml = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/' .
|
|
|
285 |
'deps.' . $release['v'] . '.txt', false, true);
|
|
|
286 |
if (PEAR::isError($packagexml)) {
|
|
|
287 |
return PEAR::raiseError('Package "' . $package . '" Version "' . $release['v'] .
|
|
|
288 |
'" does not have REST dependency information available');
|
|
|
289 |
}
|
|
|
290 |
$packagexml = unserialize($packagexml);
|
|
|
291 |
if (!$packagexml) {
|
|
|
292 |
$packagexml = array();
|
|
|
293 |
}
|
|
|
294 |
$allinfo = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
|
|
|
295 |
'/allreleases.xml');
|
|
|
296 |
if (!is_array($allinfo['r']) || !isset($allinfo['r'][0])) {
|
|
|
297 |
$allinfo['r'] = array($allinfo['r']);
|
|
|
298 |
}
|
|
|
299 |
$compatible = false;
|
|
|
300 |
foreach ($allinfo['r'] as $release) {
|
|
|
301 |
if ($release['v'] != $releaseinfo['v']) {
|
|
|
302 |
continue;
|
|
|
303 |
}
|
|
|
304 |
if (!isset($release['co'])) {
|
|
|
305 |
break;
|
|
|
306 |
}
|
|
|
307 |
$compatible = array();
|
|
|
308 |
if (!is_array($release['co']) || !isset($release['co'][0])) {
|
|
|
309 |
$release['co'] = array($release['co']);
|
|
|
310 |
}
|
|
|
311 |
foreach ($release['co'] as $entry) {
|
|
|
312 |
$comp = array();
|
|
|
313 |
$comp['name'] = $entry['p'];
|
|
|
314 |
$comp['channel'] = $entry['c'];
|
|
|
315 |
$comp['min'] = $entry['min'];
|
|
|
316 |
$comp['max'] = $entry['max'];
|
|
|
317 |
if (isset($entry['x']) && !is_array($entry['x'])) {
|
|
|
318 |
$comp['exclude'] = $entry['x'];
|
|
|
319 |
}
|
|
|
320 |
$compatible[] = $comp;
|
|
|
321 |
}
|
|
|
322 |
if (count($compatible) == 1) {
|
|
|
323 |
$compatible = $compatible[0];
|
|
|
324 |
}
|
|
|
325 |
break;
|
|
|
326 |
}
|
|
|
327 |
if (isset($pinfo['dc']) && isset($pinfo['dp'])) {
|
|
|
328 |
$deprecated = array('channel' => (string) $pinfo['dc'],
|
|
|
329 |
'package' => trim($pinfo['dp']['_content']));
|
|
|
330 |
} else {
|
|
|
331 |
$deprecated = false;
|
|
|
332 |
}
|
|
|
333 |
if ($found) {
|
|
|
334 |
return
|
|
|
335 |
array('version' => $releaseinfo['v'],
|
|
|
336 |
'info' => $packagexml,
|
|
|
337 |
'package' => $releaseinfo['p']['_content'],
|
|
|
338 |
'stability' => $releaseinfo['st'],
|
|
|
339 |
'url' => $releaseinfo['g'],
|
|
|
340 |
'compatible' => $compatible,
|
|
|
341 |
'deprecated' => $deprecated,
|
|
|
342 |
);
|
|
|
343 |
} else {
|
|
|
344 |
return
|
|
|
345 |
array('version' => $releaseinfo['v'],
|
|
|
346 |
'package' => $releaseinfo['p']['_content'],
|
|
|
347 |
'stability' => $releaseinfo['st'],
|
|
|
348 |
'info' => $packagexml,
|
|
|
349 |
'compatible' => $compatible,
|
|
|
350 |
'deprecated' => $deprecated,
|
|
|
351 |
);
|
|
|
352 |
}
|
|
|
353 |
}
|
|
|
354 |
|
|
|
355 |
function listPackages($base)
|
|
|
356 |
{
|
|
|
357 |
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml');
|
|
|
358 |
if (PEAR::isError($packagelist)) {
|
|
|
359 |
return $packagelist;
|
|
|
360 |
}
|
|
|
361 |
if (!is_array($packagelist) || !isset($packagelist['p'])) {
|
|
|
362 |
return array();
|
|
|
363 |
}
|
|
|
364 |
if (!is_array($packagelist['p'])) {
|
|
|
365 |
$packagelist['p'] = array($packagelist['p']);
|
|
|
366 |
}
|
|
|
367 |
return $packagelist['p'];
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
function listAll($base, $dostable, $basic = true, $searchpackage = false, $searchsummary = false)
|
|
|
371 |
{
|
|
|
372 |
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml');
|
|
|
373 |
if (PEAR::isError($packagelist)) {
|
|
|
374 |
return $packagelist;
|
|
|
375 |
}
|
|
|
376 |
if ($this->_rest->config->get('verbose') > 0) {
|
|
|
377 |
$ui = &PEAR_Frontend::singleton();
|
|
|
378 |
$ui->log('Retrieving data...0%', false);
|
|
|
379 |
}
|
|
|
380 |
$ret = array();
|
|
|
381 |
if (!is_array($packagelist) || !isset($packagelist['p'])) {
|
|
|
382 |
return $ret;
|
|
|
383 |
}
|
|
|
384 |
if (!is_array($packagelist['p'])) {
|
|
|
385 |
$packagelist['p'] = array($packagelist['p']);
|
|
|
386 |
}
|
|
|
387 |
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
|
|
|
388 |
$next = .1;
|
|
|
389 |
foreach ($packagelist['p'] as $progress => $package) {
|
|
|
390 |
if ($this->_rest->config->get('verbose') > 0) {
|
|
|
391 |
if ($progress / count($packagelist['p']) >= $next) {
|
|
|
392 |
if ($next == .5) {
|
|
|
393 |
$ui->log('50%', false);
|
|
|
394 |
} else {
|
|
|
395 |
$ui->log('.', false);
|
|
|
396 |
}
|
|
|
397 |
$next += .1;
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
if ($basic) { // remote-list command
|
|
|
401 |
if ($dostable) {
|
|
|
402 |
$latest = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
|
|
|
403 |
'/stable.txt');
|
|
|
404 |
} else {
|
|
|
405 |
$latest = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
|
|
|
406 |
'/latest.txt');
|
|
|
407 |
}
|
|
|
408 |
if (PEAR::isError($latest)) {
|
|
|
409 |
$latest = false;
|
|
|
410 |
}
|
|
|
411 |
$info = array('stable' => $latest);
|
|
|
412 |
} else { // list-all command
|
|
|
413 |
$inf = $this->_rest->retrieveData($base . 'p/' . strtolower($package) . '/info.xml');
|
|
|
414 |
if (PEAR::isError($inf)) {
|
|
|
415 |
PEAR::popErrorHandling();
|
|
|
416 |
return $inf;
|
|
|
417 |
}
|
|
|
418 |
if ($searchpackage) {
|
|
|
419 |
$found = (!empty($searchpackage) && stristr($package, $searchpackage) !== false);
|
|
|
420 |
if (!$found && !(isset($searchsummary) && !empty($searchsummary)
|
|
|
421 |
&& (stristr($inf['s'], $searchsummary) !== false
|
|
|
422 |
|| stristr($inf['d'], $searchsummary) !== false)))
|
|
|
423 |
{
|
|
|
424 |
continue;
|
|
|
425 |
};
|
|
|
426 |
}
|
|
|
427 |
$releases = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
|
|
|
428 |
'/allreleases.xml');
|
|
|
429 |
if (PEAR::isError($releases)) {
|
|
|
430 |
continue;
|
|
|
431 |
}
|
|
|
432 |
if (!isset($releases['r'][0])) {
|
|
|
433 |
$releases['r'] = array($releases['r']);
|
|
|
434 |
}
|
|
|
435 |
unset($latest);
|
|
|
436 |
unset($unstable);
|
|
|
437 |
unset($stable);
|
|
|
438 |
unset($state);
|
|
|
439 |
foreach ($releases['r'] as $release) {
|
|
|
440 |
if (!isset($latest)) {
|
|
|
441 |
if ($dostable && $release['s'] == 'stable') {
|
|
|
442 |
$latest = $release['v'];
|
|
|
443 |
$state = 'stable';
|
|
|
444 |
}
|
|
|
445 |
if (!$dostable) {
|
|
|
446 |
$latest = $release['v'];
|
|
|
447 |
$state = $release['s'];
|
|
|
448 |
}
|
|
|
449 |
}
|
|
|
450 |
if (!isset($stable) && $release['s'] == 'stable') {
|
|
|
451 |
$stable = $release['v'];
|
|
|
452 |
if (!isset($unstable)) {
|
|
|
453 |
$unstable = $stable;
|
|
|
454 |
}
|
|
|
455 |
}
|
|
|
456 |
if (!isset($unstable) && $release['s'] != 'stable') {
|
|
|
457 |
$latest = $unstable = $release['v'];
|
|
|
458 |
$state = $release['s'];
|
|
|
459 |
}
|
|
|
460 |
if (isset($latest) && !isset($state)) {
|
|
|
461 |
$state = $release['s'];
|
|
|
462 |
}
|
|
|
463 |
if (isset($latest) && isset($stable) && isset($unstable)) {
|
|
|
464 |
break;
|
|
|
465 |
}
|
|
|
466 |
}
|
|
|
467 |
$deps = array();
|
|
|
468 |
if (!isset($unstable)) {
|
|
|
469 |
$unstable = false;
|
|
|
470 |
$state = 'stable';
|
|
|
471 |
if (isset($stable)) {
|
|
|
472 |
$latest = $unstable = $stable;
|
|
|
473 |
}
|
|
|
474 |
} else {
|
|
|
475 |
$latest = $unstable;
|
|
|
476 |
}
|
|
|
477 |
if (!isset($latest)) {
|
|
|
478 |
$latest = false;
|
|
|
479 |
}
|
|
|
480 |
if ($latest) {
|
|
|
481 |
$d = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/deps.' .
|
|
|
482 |
$latest . '.txt');
|
|
|
483 |
if (!PEAR::isError($d)) {
|
|
|
484 |
$d = unserialize($d);
|
|
|
485 |
if ($d) {
|
|
|
486 |
if (isset($d['required'])) {
|
|
|
487 |
if (!class_exists('PEAR_PackageFile_v2')) {
|
|
|
488 |
require_once 'PEAR/PackageFile/v2.php';
|
|
|
489 |
}
|
|
|
490 |
if (!isset($pf)) {
|
|
|
491 |
$pf = new PEAR_PackageFile_v2;
|
|
|
492 |
}
|
|
|
493 |
$pf->setDeps($d);
|
|
|
494 |
$tdeps = $pf->getDeps();
|
|
|
495 |
} else {
|
|
|
496 |
$tdeps = $d;
|
|
|
497 |
}
|
|
|
498 |
foreach ($tdeps as $dep) {
|
|
|
499 |
if ($dep['type'] !== 'pkg') {
|
|
|
500 |
continue;
|
|
|
501 |
}
|
|
|
502 |
$deps[] = $dep;
|
|
|
503 |
}
|
|
|
504 |
}
|
|
|
505 |
}
|
|
|
506 |
}
|
|
|
507 |
if (!isset($stable)) {
|
|
|
508 |
$stable = '-n/a-';
|
|
|
509 |
}
|
|
|
510 |
if (!$searchpackage) {
|
|
|
511 |
$info = array('stable' => $latest, 'summary' => $inf['s'], 'description' =>
|
|
|
512 |
$inf['d'], 'deps' => $deps, 'category' => $inf['ca']['_content'],
|
|
|
513 |
'unstable' => $unstable, 'state' => $state);
|
|
|
514 |
} else {
|
|
|
515 |
$info = array('stable' => $stable, 'summary' => $inf['s'], 'description' =>
|
|
|
516 |
$inf['d'], 'deps' => $deps, 'category' => $inf['ca']['_content'],
|
|
|
517 |
'unstable' => $unstable, 'state' => $state);
|
|
|
518 |
}
|
|
|
519 |
}
|
|
|
520 |
$ret[$package] = $info;
|
|
|
521 |
}
|
|
|
522 |
PEAR::popErrorHandling();
|
|
|
523 |
return $ret;
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
function listLatestUpgrades($base, $state, $installed, $channel, &$reg)
|
|
|
527 |
{
|
|
|
528 |
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml');
|
|
|
529 |
if (PEAR::isError($packagelist)) {
|
|
|
530 |
return $packagelist;
|
|
|
531 |
}
|
|
|
532 |
$ret = array();
|
|
|
533 |
if (!is_array($packagelist) || !isset($packagelist['p'])) {
|
|
|
534 |
return $ret;
|
|
|
535 |
}
|
|
|
536 |
if (!is_array($packagelist['p'])) {
|
|
|
537 |
$packagelist['p'] = array($packagelist['p']);
|
|
|
538 |
}
|
|
|
539 |
if ($state) {
|
|
|
540 |
$states = $this->betterStates($state, true);
|
|
|
541 |
}
|
|
|
542 |
foreach ($packagelist['p'] as $package) {
|
|
|
543 |
if (!isset($installed[strtolower($package)])) {
|
|
|
544 |
continue;
|
|
|
545 |
}
|
|
|
546 |
$inst_version = $reg->packageInfo($package, 'version', $channel);
|
|
|
547 |
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
|
|
|
548 |
$info = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
|
|
|
549 |
'/allreleases.xml');
|
|
|
550 |
PEAR::popErrorHandling();
|
|
|
551 |
if (PEAR::isError($info)) {
|
|
|
552 |
continue; // no remote releases
|
|
|
553 |
}
|
|
|
554 |
if (!isset($info['r'])) {
|
|
|
555 |
continue;
|
|
|
556 |
}
|
|
|
557 |
$found = false;
|
|
|
558 |
$release = false;
|
|
|
559 |
if (!is_array($info['r']) || !isset($info['r'][0])) {
|
|
|
560 |
$info['r'] = array($info['r']);
|
|
|
561 |
}
|
|
|
562 |
foreach ($info['r'] as $release) {
|
|
|
563 |
if ($inst_version && version_compare($release['v'], $inst_version, '<=')) {
|
|
|
564 |
continue;
|
|
|
565 |
}
|
|
|
566 |
if ($state) {
|
|
|
567 |
if (in_array($release['s'], $states)) {
|
|
|
568 |
$found = true;
|
|
|
569 |
break;
|
|
|
570 |
}
|
|
|
571 |
} else {
|
|
|
572 |
$found = true;
|
|
|
573 |
break;
|
|
|
574 |
}
|
|
|
575 |
}
|
|
|
576 |
if (!$found) {
|
|
|
577 |
continue;
|
|
|
578 |
}
|
|
|
579 |
$relinfo = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/' .
|
|
|
580 |
$release['v'] . '.xml');
|
|
|
581 |
if (PEAR::isError($relinfo)) {
|
|
|
582 |
return $relinfo;
|
|
|
583 |
}
|
|
|
584 |
$ret[$package] = array(
|
|
|
585 |
'version' => $release['v'],
|
|
|
586 |
'state' => $release['s'],
|
|
|
587 |
'filesize' => $relinfo['f'],
|
|
|
588 |
);
|
|
|
589 |
}
|
|
|
590 |
return $ret;
|
|
|
591 |
}
|
|
|
592 |
|
|
|
593 |
function packageInfo($base, $package)
|
|
|
594 |
{
|
|
|
595 |
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
|
|
|
596 |
$pinfo = $this->_rest->retrieveData($base . 'p/' . strtolower($package) . '/info.xml');
|
|
|
597 |
if (PEAR::isError($pinfo)) {
|
|
|
598 |
PEAR::popErrorHandling();
|
|
|
599 |
return PEAR::raiseError('Unknown package: "' . $package . '" (Debug: ' .
|
|
|
600 |
$pinfo->getMessage() . ')');
|
|
|
601 |
}
|
|
|
602 |
$releases = array();
|
|
|
603 |
$allreleases = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
|
|
|
604 |
'/allreleases.xml');
|
|
|
605 |
if (!PEAR::isError($allreleases)) {
|
|
|
606 |
if (!class_exists('PEAR_PackageFile_v2')) {
|
|
|
607 |
require_once 'PEAR/PackageFile/v2.php';
|
|
|
608 |
}
|
|
|
609 |
if (!is_array($allreleases['r']) || !isset($allreleases['r'][0])) {
|
|
|
610 |
$allreleases['r'] = array($allreleases['r']);
|
|
|
611 |
}
|
|
|
612 |
$pf = new PEAR_PackageFile_v2;
|
|
|
613 |
foreach ($allreleases['r'] as $release) {
|
|
|
614 |
$ds = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/deps.' .
|
|
|
615 |
$release['v'] . '.txt');
|
|
|
616 |
if (PEAR::isError($ds)) {
|
|
|
617 |
continue;
|
|
|
618 |
}
|
|
|
619 |
if (!isset($latest)) {
|
|
|
620 |
$latest = $release['v'];
|
|
|
621 |
}
|
|
|
622 |
$pf->setDeps(unserialize($ds));
|
|
|
623 |
$ds = $pf->getDeps();
|
|
|
624 |
$info = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package)
|
|
|
625 |
. '/' . $release['v'] . '.xml');
|
|
|
626 |
if (PEAR::isError($info)) {
|
|
|
627 |
continue;
|
|
|
628 |
}
|
|
|
629 |
$releases[$release['v']] = array(
|
|
|
630 |
'doneby' => $info['m'],
|
|
|
631 |
'license' => $info['l'],
|
|
|
632 |
'summary' => $info['s'],
|
|
|
633 |
'description' => $info['d'],
|
|
|
634 |
'releasedate' => $info['da'],
|
|
|
635 |
'releasenotes' => $info['n'],
|
|
|
636 |
'state' => $release['s'],
|
|
|
637 |
'deps' => $ds ? $ds : array(),
|
|
|
638 |
);
|
|
|
639 |
}
|
|
|
640 |
} else {
|
|
|
641 |
$latest = '';
|
|
|
642 |
}
|
|
|
643 |
PEAR::popErrorHandling();
|
|
|
644 |
if (isset($pinfo['dc']) && isset($pinfo['dp'])) {
|
|
|
645 |
$deprecated = array('channel' => (string) $pinfo['dc'],
|
|
|
646 |
'package' => trim($pinfo['dp']['_content']));
|
|
|
647 |
} else {
|
|
|
648 |
$deprecated = false;
|
|
|
649 |
}
|
|
|
650 |
return array(
|
|
|
651 |
'name' => $pinfo['n'],
|
|
|
652 |
'channel' => $pinfo['c'],
|
|
|
653 |
'category' => $pinfo['ca']['_content'],
|
|
|
654 |
'stable' => $latest,
|
|
|
655 |
'license' => $pinfo['l'],
|
|
|
656 |
'summary' => $pinfo['s'],
|
|
|
657 |
'description' => $pinfo['d'],
|
|
|
658 |
'releases' => $releases,
|
|
|
659 |
'deprecated' => $deprecated,
|
|
|
660 |
);
|
|
|
661 |
}
|
|
|
662 |
|
|
|
663 |
/**
|
|
|
664 |
* Return an array containing all of the states that are more stable than
|
|
|
665 |
* or equal to the passed in state
|
|
|
666 |
*
|
|
|
667 |
* @param string Release state
|
|
|
668 |
* @param boolean Determines whether to include $state in the list
|
|
|
669 |
* @return false|array False if $state is not a valid release state
|
|
|
670 |
*/
|
|
|
671 |
function betterStates($state, $include = false)
|
|
|
672 |
{
|
|
|
673 |
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
|
|
|
674 |
$i = array_search($state, $states);
|
|
|
675 |
if ($i === false) {
|
|
|
676 |
return false;
|
|
|
677 |
}
|
|
|
678 |
if ($include) {
|
|
|
679 |
$i--;
|
|
|
680 |
}
|
|
|
681 |
return array_slice($states, $i + 1);
|
|
|
682 |
}
|
|
|
683 |
}
|
|
|
684 |
?>
|