summaryrefslogtreecommitdiffstats
path: root/class/FedoraPkgdb.php
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2013-11-17 17:46:48 +0100
committerRemi Collet <fedora@famillecollet.com>2013-11-17 17:46:48 +0100
commitbe9f96e74ef96c85ef0b9c11c30f220c140ad48a (patch)
tree81105b8299b8f71fadb7a294d9157ee352180e7f /class/FedoraPkgdb.php
parent267655746e046f63a26cba2c57439fd9469db51a (diff)
WIP for pkgdb2
Diffstat (limited to 'class/FedoraPkgdb.php')
-rw-r--r--class/FedoraPkgdb.php147
1 files changed, 98 insertions, 49 deletions
diff --git a/class/FedoraPkgdb.php b/class/FedoraPkgdb.php
index 15ddf50..da43986 100644
--- a/class/FedoraPkgdb.php
+++ b/class/FedoraPkgdb.php
@@ -7,7 +7,7 @@
*
* PHP version 5
*
- * Copyright (C) 2010 Remi Collet
+ * Copyright (C) 2010-2013 Remi Collet
* http://github.com/remicollet/rpmphp.
*
* Inspired from python-fedora
@@ -29,7 +29,7 @@
*
* @author Remi Collet <unknown@unknwown.com>
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2010 Remi Collet
+ * @copyright 2010-2013 Remi Collet
* @license http://www.gnu.org/licenses/lgpl-2.1.txt LGPL License 2.1 or (at your option) any later version
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
@@ -37,41 +37,65 @@
class FedoraPkgdb extends FedoraClient
{
- private $_suburl;
+ private $_version = 0;
function __construct (array $options=array())
{
- parent::__construct('https://admin.fedoraproject.org/pkgdb/', $options);
- $this->_suburl = 'acls/name/';
+ if (isset($options['server']) && ($options['server'])) {
+ $server = $options['server'];
+ } else {
+ $server = 'admin.fedoraproject.org';
+ }
+ parent::__construct("http://$server/api/", $options);
+
+ $rep = $this->cache->get(__METHOD__, $this->url);
+ if ($rep!==false) {
+ $this->logDebug(2, __METHOD__."() get from cache");
+ } else {
+ $rep =$this->sendRequest('version');
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache"
+ );
+ }
+
+ if (isset($rep['version'])) {
+ /* Pkgdb2 */
+ $this->_version = $rep['version'];
+ } else {
+ /* Pkgdb */
+ $this->setUrl("https://$server/pkgdb/");
+ }
+ }
- $this->logDebug(
- 3,
- __CLASS__."::".__FUNCTION__
- );
+ function getVersion()
+ {
+ return $this->_version;
}
function getBranches($refresh=false)
{
- $rep = ($refresh ? false : $this->cache->get(__FUNCTION__, __CLASS__));
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."() get from cache"
- );
+ $this->logDebug(2, __METHOD__."() get from cache");
} else {
$rep =$this->sendRequest('collections');
- $this->cache->save($rep, __FUNCTION__, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."() save to cache"
- );
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache");
}
$branches = array();
if (isset($rep['collections'])) {
- foreach ($rep['collections'] as $coll) {
- if (isset($coll[0]['branchname'])) {
- $branches[$coll[0]['branchname']] = $coll[0];
+ if ($this->_version > 0) {
+ foreach ($rep['collections'] as $coll) {
+ if (isset($coll['branchname'])) { /* pkgdb version 2 */
+ $branches[$coll['branchname']] = $coll;
+ }
+ }
+ } else {
+ foreach ($rep['collections'] as $coll) {
+ if (isset($coll[0]['branchname'])) { /* pkgdb version 1 */
+ $branches[$coll[0]['branchname']] = $coll[0];
+ }
}
}
}
@@ -80,32 +104,37 @@ class FedoraPkgdb extends FedoraClient
function getPackageURL($name)
{
- return $this->url.$this->_suburl.$name;
+ return $this->url.'acls/name/'.$name;
}
function getPackageInfo($name, $refresh=false)
{
- $url=$this->_suburl.urlencode($name);
- $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
+ if ($this->_version > 0) {
+ $url='package/acl/get/'.urlencode($name);
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."($name) get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
+ }
+ $this->logDebug(8, print_r($rep, true));
+ return false;
+ }
+
+ $url='acls/name/'.urlencode($name);
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."($name) get from cache"
- );
+ $this->logDebug(2, __METHOD__."($name) get from cache");
} else {
$rep =$this->sendRequest($url);
- $this->cache->save($rep, $url, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."($name) save to cache"
- );
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
}
if (isset($rep['status']) && !$rep['status']) {
- $this->logDebug(
- 1,
- __CLASS__."::".__FUNCTION__."($name) ".$rep['message']
- );
+ $this->logDebug(1, __METHOD__."($name) ".$rep['message']);
return false;
}
$this->logDebug(8, print_r($rep, true));
@@ -119,6 +148,18 @@ class FedoraPkgdb extends FedoraClient
function getBranch($name, $refresh=false)
{
+ if ($this->_version > 0) {
+ $url='collections/'.urlencode($name).'/';
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."($name) get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
+ }
+ return (isset($rep['collections'][0]) ? $rep['collections'][0] : array());
+ }
$branches = $this->getBranches($refresh);
if (isset($branches[$name])) {
@@ -129,22 +170,30 @@ class FedoraPkgdb extends FedoraClient
function getCritPath($refresh=false)
{
+ if ($this->_version > 0) {
+ $url="critpath";
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."() get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache");
+ }
+ return (isset($rep['pkgs']) ? $rep['pkgs'] : NULL);
+ }
+
$url="lists/critpath";
- $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__." get from cache"
- );
+ $this->logDebug(2, __METHOD__."() get from cache");
} else {
$rep =$this->sendRequest($url);
- $this->cache->save($rep, $url, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__." save to cache"
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache"
);
}
- return $rep['pkgs'];
+ return (isset($rep['pkgs']) ? $rep['pkgs'] : NULL);
}
}
-?> \ No newline at end of file
+