summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2010-11-01 10:37:34 +0100
committerRemi Collet <fedora@famillecollet.com>2010-11-01 10:37:34 +0100
commitdce8f805bb2d7b46e51449086e35cb0b2af37daf (patch)
tree497338145ff4df10c59149d9f13bef07b356731e
parentda00c9df1bf03fe3989c9cc34f0007f285a1ad5e (diff)
use Parser::readPecl()
-rw-r--r--class/Parser.php97
-rw-r--r--refresh.php79
2 files changed, 99 insertions, 77 deletions
diff --git a/class/Parser.php b/class/Parser.php
index ee052e2..3113718 100644
--- a/class/Parser.php
+++ b/class/Parser.php
@@ -43,6 +43,7 @@ class Parser
{
echo date("r : ") . $msg ."\n";
}
+
/**
* Parse the Bugzilla ACL list from pkgdb
*
@@ -266,5 +267,101 @@ class Parser
}
return $tot;
}
+
+ /**
+ * Parse the PECL webservices
+ *
+ * @param TableUpstream $uptable the table to write to
+ * @param string $url the URL to read from
+ *
+ * @return integer number of parsed line
+ */
+ static public function readPecl(TableUpstream $uptable, $url)
+ {
+ self::log("PECL listLatestReleases - stable");
+
+ $request = xmlrpc_encode_request("package.listLatestReleases", "stable");
+ $context = stream_context_create(
+ array(
+ 'http' => array(
+ 'method' => "POST",
+ 'header' => "Content-Type: text/xml",
+ 'content' => $request
+ )
+ )
+ );
+ $file = file_get_contents($url, false, $context);
+ if (!$file) {
+ self::log("Can't file_get_contents($url)");
+ return 0;
+ }
+
+ $stable = xmlrpc_decode($file);
+ if (xmlrpc_is_fault($stable)) {
+ self::log("ERROR xmlrpc: $stable[faultString] ($stable[faultCode])");
+ } else {
+ $nb = $uptable->delete(array('type'=>'pecl', 'channel'=>'pecl'));
+ self::log("Delete $nb packages");
+
+ $nb=0;
+ foreach ($stable as $name => $info) {
+ $rpmname="php-pecl-".str_replace("_", "-", $name);
+
+ $id = $uptable->record(
+ 'pecl',
+ 'pecl',
+ $rpmname,
+ $info["version"],
+ true
+ );
+ if ($id) {
+ $nb++;
+ }
+ }
+ self::log("Write $nb packages");
+ }
+
+ // -------------------------------------------------------------------
+ self::log("PECL listLatestReleases - unstable");
+
+ $request = xmlrpc_encode_request("package.listLatestReleases", array());
+ $context = stream_context_create(
+ array(
+ 'http' => array(
+ 'method' => "POST",
+ 'header' => "Content-Type: text/xml",
+ 'content' => $request
+ )
+ )
+ );
+ $file = file_get_contents($url, false, $context);
+ if (!$file) {
+ self::log("Can't file_get_contents($url)");
+ return 0;
+ }
+ $unstable = xmlrpc_decode($file);
+ if (xmlrpc_is_fault($unstable)) {
+ self::log("ERROR xmlrpc: $stable[faultString] ($stable[faultCode])");
+ } else {
+ $nb=0;
+ foreach ($unstable as $name => $info) {
+ $rpmname="php-pecl-".str_replace("_", "-", $name);
+
+ $id = $uptable->record(
+ 'pecl',
+ 'pecl',
+ $rpmname,
+ $info["version"],
+ true,
+ $info["state"]
+ );
+ if ($id) {
+ $nb++;
+ }
+ }
+ self::log("Write $nb packages");
+ }
+ return $nb;
+ }
}
?> \ No newline at end of file
diff --git a/refresh.php b/refresh.php
index 9603c78..14b0020 100644
--- a/refresh.php
+++ b/refresh.php
@@ -81,84 +81,9 @@ try {
// -------------------------------------------------------------------
if ($_SERVER['argc']==1 || in_array('pecl', $_SERVER['argv'])) {
- echo date("r : ") . "PECL listLatestReleases - stable\n";
-
- $request = xmlrpc_encode_request("package.listLatestReleases", "stable");
- $context = stream_context_create(
- array(
- 'http' => array(
- 'method' => "POST",
- 'header' => "Content-Type: text/xml",
- 'content' => $request
- )
- )
- );
- $file = file_get_contents("http://pecl.php.net/xmlrpc.php", false, $context)
- or die ("Can't file_get_contents(http://pecl.php.net/xmlrpc.php)");
- $stable = xmlrpc_decode($file);
- if (xmlrpc_is_fault($stable)) {
- echo date("r : ") .
- "ERROR xmlrpc: $stable[faultString] ($stable[faultCode])";
- } else {
- $nb = $uptable->delete(array('type'=>'pecl', 'channel'=>'pecl'));
- echo date("r : ") . "Delete $nb packages\n";
-
- $nb=0;
- foreach ($stable as $name => $info) {
- $rpmname="php-pecl-".str_replace("_", "-", $name);
-
- $id = $uptable->record(
- 'pecl',
- 'pecl',
- $rpmname,
- $info["version"],
- true
- );
- if ($id) {
- $nb++;
- }
- }
- echo date("r : ") . "Write $nb packages\n";
- }
- // -------------------------------------------------------------------
- echo date("r : ") . "PECL listLatestReleases - unstable\n";
-
- $request = xmlrpc_encode_request("package.listLatestReleases", array());
- $context = stream_context_create(
- array(
- 'http' => array(
- 'method' => "POST",
- 'header' => "Content-Type: text/xml",
- 'content' => $request
- )
- )
- );
- $file = file_get_contents("http://pecl.php.net/xmlrpc.php", false, $context)
- or die ("Can't file_get_contents(http://pecl.php.net/xmlrpc.php)");
- $unstable = xmlrpc_decode($file);
- if (xmlrpc_is_fault($unstable)) {
- echo date("r : ") . "ERROR xmlrpc: $stable[faultString] ".
- "($stable[faultCode])";
- } else {
- $nb=0;
- foreach ($unstable as $name => $info) {
- $rpmname="php-pecl-".str_replace("_", "-", $name);
-
- $id = $uptable->record(
- 'pecl',
- 'pecl',
- $rpmname,
- $info["version"],
- true,
- $info["state"]
- );
- if ($id) {
- $nb++;
- }
- }
- echo date("r : ") . "Write $nb packages\n";
- }
+ Parser::readPecl($uptable, 'http://pecl.php.net/xmlrpc.php');
+
} // if in options
// -------------------------------------------------------------------