Index: pear-rest.php
===================================================================
RCS file: /repository/pearweb/include/pear-rest.php,v
retrieving revision 1.56
diff -u -r1.56 pear-rest.php
--- pear-rest.php 18 May 2009 15:19:35 -0000 1.56
+++ pear-rest.php 29 Jun 2009 14:01:15 -0000
@@ -235,6 +235,71 @@
System::rm(array('-r', $dir));
}

+ public function saveAllLatestPackagesREST()
+ {
+ $info = '<?xml version="1.0" encoding="UTF-8" ?>
+<a xmlns="http://pear.php.net/dtd/rest.allpackages"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xsi:schemaLocation="http://pear.php.net/dtd/rest.latestpackages
+ http://pear.php.net/dtd/rest.latestpackages.xsd">
+<c>' . $this->channel . '</c>
+';
+
+ include_once 'pear-database-package.php';
+ foreach (package::listAllwithReleases() as $package) {
+ $info .= '<p>' . "\n";
+ $info .= '<n>' . $package['name'] . '</n>' . "\n";
+ $stable = $beta = $alpha = '';
+ foreach ($package['releases'] as $r) {
+ if ($r['state'] == 'stable' && version_compare($r['version'] > $stable, '>')) {
+ $stable = $r['version'];
+ }
+
+ if ($r['state'] == 'beta' && version_compare($r['version'] > $stable, '>')) {
+ $beta = $r['version'];
+ }
+
+ if ($r['state'] == 'alpha' &&
+ (version_compare($r['version'] > $beta, '>') && version_compare($r['version'] > $stable, '>'))
+ ) {
+ $alpha = $r['version'];
+ }
+ }
+
+ if (isset($alpha)) {
+ $info .= '<alpha><v>' . $alpha . '</v>';
+ $info .= '<f>' . filesize(PEAR_TARBALL_DIR . DIRECTORY_SEPARATOR . $package['name'] . '-' . $alpha . '.tgz') . '</f></alpha>' . "\n";
+ }
+
+ if (isset($beta)) {
+ $info .= '<beta><v>' . $beta . '</v>';
+ $info .= '<f>' . filesize(PEAR_TARBALL_DIR . DIRECTORY_SEPARATOR . $package['name'] . '-' . $beta . '.tgz') . '</f></beta>' . "\n";
+ }
+
+ if (isset($stable)) {
+ $info .= '<stable><v>' . $stable . '</v>';
+ $info .= '<f>' . filesize(PEAR_TARBALL_DIR . DIRECTORY_SEPARATOR . $package['name'] . '-' . $stable . '.tgz') . '</f></stable>' . "\n";
+ }
+
+ $info .= '</p>';
+ }
+
+ $dir = $this->_restdir . DIRECTORY_SEPARATOR . 'p' . DIRECTORY_SEPARATOR;
+ if (!is_dir($dir)) {
+ if (!mkdir($dir, 0777, true)) {
+ return PEAR::raiseError('Creating directory ' . $dir . ' failed - Check ther permissions');
+ }
+ @chmod($dir, 0777);
+ }
+
+ $file = $dir . 'latestpackages.xml';
+ if (!file_put_contents($file, $info)) {
+ return PEAR::raiseError('Writing file ' . $file . ' failed - Check the permissions');
+ }
+ @chmod($file, 0666);
+ }
+
public function saveAllPackagesREST()
{
$info = '<?xml version="1.0" encoding="UTF-8" ?>
@@ -372,8 +437,8 @@

include_once 'pear-database-package.php';
$pid = package::info($package, 'id');
- $releases = $this->db->getAll('SELECT * FROM releases WHERE package = ? ORDER BY releasedate DESC',
- array($pid), DB_FETCHMODE_ASSOC);
+ $sql = 'SELECT * FROM releases WHERE package = ? ORDER BY releasedate DESC';
+ $releases = $this->db->getAll($sql, array($pid), DB_FETCHMODE_ASSOC);
if (PEAR::isError($releases)) {
return $releases;
}
@@ -401,9 +466,9 @@

$info = $this->_getAllReleasesRESTProlog($package);
$info2 = $this->_getAllReleases2RESTProlog($package);
+ $sql = 'SELECT packagexml FROM files WHERE package = ? AND `release` = ?';
foreach ($releases as $release) {
- $packagexml = $this->db->getOne('SELECT packagexml FROM files WHERE package = ? AND
- `release` = ?', array($pid, $release['id']));
+ $packagexml = $this->db->getOne($sql, array($pid, $release['id']));
if (PEAR::isError($packagexml)) {
return $packagexml;
}
@@ -419,6 +484,7 @@
if (!isset($compat[0])) {
$compat = array($compat);
}
+
foreach ($compat as $entry) {
$extra .= '<co><c>' . $entry['channel'] . '</c>' .
'<p>' . $entry['name'] . '</p>' .
@@ -439,6 +505,7 @@
}
}
}
+
if (!isset($latest)) {
$latest = $release['version'];
}