} echo "get(999):"; if ($row = $rpm->get(999)) { print_r($row); } else { echo "not found\n"; } echo "get(888):"; if ($row = $rpm->get(888)) { print_r($row); } else { echo "not found\n"; } echo "Last update : " . date("r", $rpm->getMaxStamp()) . "\n"; $up = new TableUpstream($db); $up->delete(array('name' => 'foo', 'type' => 'test')); $rec = $up->record('test', 'bar', 'foo', '1.0', true); echo "record(foo-1.0) : {$rec}\n"; echo "find(foo,test):"; if ($row = $up->find(array('name' => 'foo', 'type' => 'test'))) { print_r($row); } else { echo "not found\n"; } $up->record('test', 'bar', 'foo', '1.2', false, 'beta'); echo "record(foo-1.2) : {$rec}\n"; echo "find(foo,test):"; if ($row = $up->find(array('name' => 'foo', 'type' => 'test'))) { print_r($row); } else { echo "not found\n";
/** * Parse the content of all PEAR repository * * @param TableUpstream $uptable the table to write to * @param string $channelname the channel name * @param string $channelurl the channel URL * * @return integer number of parsed line */ public static function readOnePear(TableUpstream $uptable, $channelname, $channelurl) { $type = $channelname == 'pecl' ? 'pecl' : 'pear'; $channel = @simplexml_load_file("http://{$channelurl}/channel.xml"); if (!$channel) { self::log("can't read PEAR site (channel of {$channelname})"); return 0; } $rest = $channel->servers->primary->rest->baseurl[0]; self::log("PEAR reading channel={$channelname}, baseurl = {$rest}"); $categories = @simplexml_load_file($rest . "c/categories.xml"); if (!$categories) { self::log("can't read PEAR site (categories)"); return 0; } $crit = array('type' => $type, 'channel' => $channelname); $nb = $uptable->delete($crit); self::log("Delete {$nb} packages"); $nb = 0; if (!isset($categories->c[0])) { self::log("Reading ALL"); // ezc only $pitxt = @file_get_contents($rest . "p/packages.xml"); if (!$pitxt) { self::log("can't read PEAR site (" . $rest . "p/packagesinfo.xml)"); return 0; } $allpi = @simplexml_load_string($pitxt); foreach ($allpi->p as $name) { $pitxt = @file_get_contents($rest . "r/" . strtolower($name) . "/allreleases.xml"); if (!$pitxt) { self::log("can't read PEAR site (" . $rest . "r/" . strtolower($name) . "/allreleases.xml"); continue; } $pi = @simplexml_load_string($pitxt); $rpmname1 = "php-" . $channelname . "-" . str_replace("_", "-", $name); $rpmname2 = "php-" . $channelname . "-" . $name; $uptable->record($type, $channelname, $rpmname1, (string) $pi->r[0]->v, false, (string) $pi->r[0]->s); $uptable->record($type, $channelname, $rpmname2, (string) $pi->r[0]->v, false, (string) $pi->r[0]->s); foreach ($pi->r as $rev) { if ($rev->s == 'stable') { $uptable->record($type, $channelname, $rpmname1, (string) $rev->v, true); $uptable->record($type, $channelname, $rpmname2, (string) $rev->v, true); break; } } $nb++; } } else { foreach ($categories->c as $cat) { self::log("Reading {$cat}"); $pitxt = @file_get_contents($rest . "c/" . urlencode($cat) . "/packagesinfo.xml"); if (!$pitxt) { self::log("can't read PEAR site (" . $rest . "c/" . urlencode($cat) . "/packagesinfo.xml)"); continue; } $pitxt = "<?" . preg_replace("/<\\?xml.*?>/U", "", str_replace("\r\n", "\n", substr($pitxt, 2))); $pitxt = str_replace(" ", "", $pitxt); $pi = @simplexml_load_string($pitxt); if (!$pi) { self::log("can't read response ({$cat})"); continue; } foreach ($pi->pi as $ps) { if (isset($ps->p->n) && isset($ps->a->r)) { $name = (string) $ps->p->n; if ($channelname == 'phing' && $name == 'phing') { $rpmname1 = "php-pear-phing"; } else { if ($channelname == 'phpunit' && $name == 'PHPUnit') { $rpmname1 = "php-pear-PHPUnit"; } else { if ($channelname == 'pecl' && $name == 'pecl_http') { $rpmname1 = "php-pecl-http"; } else { $rpmname1 = "php-" . $channelname . "-" . str_replace("_", "-", $name); } } } $rpmname2 = "php-" . $channelname . "-" . $name; $uptable->record($type, $channelname, $rpmname1, (string) $ps->a->r[0]->v, false, (string) $ps->a->r[0]->s); $uptable->record($type, $channelname, $rpmname2, (string) $ps->a->r[0]->v, false, (string) $ps->a->r[0]->s); foreach ($ps->a->r as $rev) { if ($rev->s == 'stable') { $uptable->record($type, $channelname, $rpmname1, (string) $rev->v, true); $uptable->record($type, $channelname, $rpmname2, (string) $rev->v, true); break; } } $nb++; } } } } self::log("read {$nb} packages in {$channelname}"); return $nb; }