diff options
Diffstat (limited to 'refresh.php')
-rw-r--r-- | refresh.php | 172 |
1 files changed, 47 insertions, 125 deletions
diff --git a/refresh.php b/refresh.php index 4026f68..539e1a5 100644 --- a/refresh.php +++ b/refresh.php @@ -46,39 +46,6 @@ if (isset($_SERVER["SERVER_NAME"])) { require "include/main.php"; require "class/CommonTable.php"; -/** -* To document -* -* @param Object $db Database reference -* @param string $type type -* @param string $channel channel -* @param string $name name -* @param string $state state -* @param string $ver version -* @param string $statename state name -* -* @return rows updated -*/ -function addUpstream ($db, $type, $channel, $name, $state, $ver, $statename="") -{ - - $sql1 = "INSERT INTO `upstream` SET type='$type', name='$name'"; - $db->exec($sql1); - - $sql2 = "UPDATE `upstream` SET channel='$channel', $state='$ver'"; - if ($statename) { - $sql2 .= ", state='$statename'"; - } - $sql2 .= " WHERE type='$type' AND name='$name'"; - $nb = $db->exec($sql2); - if ($nb===false) { - echo date("r : ") . "SQL ERROR($sql2) = " . - implode(" ", $db->errorInfo()) . "\n"; - } - - return $nb; -} - if ($_SERVER['argc']>1 && in_array('help', $_SERVER['argv'])) { echo "Options in: repo owner R pear pecl old\n"; echo "Defaults: repo owner R pear pecl\n"; @@ -197,23 +164,7 @@ try { // ------------------------------------------------------------------- // Upstream Version // ------------------------------------------------------------------- - $sql="CREATE TABLE IF NOT EXISTS `upstream` ( - `name` varchar(100) NOT NULL, - `type` varchar(20) NOT NULL, - `channel` varchar(20) NOT NULL, - `stable` varchar(20) DEFAULT NULL, - `unstable` varchar(20) DEFAULT NULL, - `state` varchar(20) DEFAULT NULL, - PRIMARY KEY (`name`,`type`), - KEY `name` (`name`), - KEY `type` (`type`), - KEY `channel` (`channel`))"; - - if ($db->exec($sql)!==false) { - echo date("r : ") . "Check table 'upstream' ok\n"; - } else { - echo date("r : ") . "SQL ERROR = " . implode(" ", $db->errorInfo()) . "\n"; - } + $uptable = new TableUpstream($db); // ------------------------------------------------------------------- if ($_SERVER['argc']==1 || in_array('pecl', $_SERVER['argv'])) { @@ -236,27 +187,23 @@ try { echo date("r : ") . "ERROR xmlrpc: $stable[faultString] ($stable[faultCode])"; } else { - $sql = "DELETE FROM upstream WHERE type='pecl' AND channel='pecl'"; - $nb=$db->exec($sql); - if ($nb===false) { - echo date("r : ") . "SQL ERROR = " . - implode(" ", $db->errorInfo()) . "\n"; - } else { - echo date("r : ") . "Delete $nb packages\n"; - } + $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); - $nb += addUpstream( - $db, - "pecl", - "pecl", + $id = $uptable->record( + 'pecl', + 'pecl', $rpmname, - "stable", - $info["version"] + $info["version"], + true ); + if ($id) { + $nb++; + } } echo date("r : ") . "Write $nb packages\n"; } @@ -285,20 +232,19 @@ try { foreach ($unstable as $name => $info) { $rpmname="php-pecl-".str_replace("_", "-", $name); - $nb += addUpstream( - $db, - "pecl", - "pecl", + $id = $uptable->record( + 'pecl', + 'pecl', $rpmname, - "unstable", $info["version"], + true, $info["state"] ); + if ($id) { + $nb++; + } } echo date("r : ") . "Write $nb packages\n"; - //echo date("r : ") . "saved " . - // file_put_contents("cache/pecl-unstable", serialize($unstable)) . - // " bytes\n"; } } // if in options @@ -327,17 +273,9 @@ try { throw new Exception("can't read PEAR site (categories)"); } - $sql = "DELETE FROM upstream WHERE type='pear' AND channel='". - $channelname."'"; - $nb=$db->exec($sql); - if ($nb===false) { - echo date("r : ") . "SQL ERROR = " . implode( - " ", - $db->errorInfo() - ) . "\n"; - } else { - echo date("r : ") . "Delete $nb packages\n"; - } + $crit = array('type'=>'pear', 'channel'=>$channelname); + $nb = $uptable->delete($crit); + echo date("r : ") . "Delete $nb packages\n"; $nb=0; if (!isset($categories->c[0])) { @@ -367,43 +305,39 @@ try { //echo $rpmname ."/".(string)$pi->r[0]->v."/". // (string)$pi->r[0]->s."\n"; - addUpstream( - $db, + $uptable->record( "pear", $channelname, $rpmname1, - "unstable", (string)$pi->r[0]->v, + false, (string)$pi->r[0]->s ); - addUpstream( - $db, + $uptable->record( "pear", $channelname, $rpmname2, - "unstable", (string)$pi->r[0]->v, + false, (string)$pi->r[0]->s ); foreach ($pi->r as $rev) { if ($rev->s=='stable') { //echo $rpmname ."/".(string)$rev->v."/". // (string)$rev->s."\n"; - addUpstream( - $db, + $uptable->record( "pear", $channelname, $rpmname1, - "stable", - (string)$rev->v + (string)$rev->v, + true ); - addUpstream( - $db, + $uptable->record( "pear", $channelname, $rpmname2, - "stable", - (string)$rev->v + (string)$rev->v, + true ); break; } @@ -450,40 +384,37 @@ try { } $rpmname2="php-".$channelname."-".$name; - addUpstream( - $db, + $uptable->record( "pear", $channelname, $rpmname1, - "unstable", (string)$ps->a->r[0]->v, + false, (string)$ps->a->r[0]->s ); - addUpstream( - $db, + $uptable->record( "pear", $channelname, $rpmname2, - "unstable", (string)$ps->a->r[0]->v, + false, (string)$ps->a->r[0]->s ); foreach ($ps->a->r as $rev) { if ($rev->s=='stable') { - addUpstream( - $db, "pear", + $uptable->record( + "pear", $channelname, $rpmname1, - "stable", - (string)$rev->v + (string)$rev->v, + true ); - addUpstream( - $db, + $uptable->record( "pear", $channelname, $rpmname2, - "stable", - (string)$rev->v + (string)$rev->v, + true ); break; } @@ -518,17 +449,9 @@ try { continue; } if ($repo["state"]=="stable") { - $sql = sprintf( - "DELETE FROM upstream WHERE type='R' AND channel='%s'", - $repo["name"] - ); - $nb=$db->exec($sql); - if ($nb===false) { - echo date("r : ") . "SQL ERROR = " . - implode(" ", $db->errorInfo()) . "\n"; - } else { - echo date("r : ") . "Delete $nb packages\n"; - } + $crit = array('type'=>'R', 'channel'=>$repo['name']); + $nb = $uptable->delete($crit); + echo date("r : ") . "Delete $nb packages\n"; } $results=array(); $pat = '/Package: *(.*)\nVersion: *(.*)\n/i'; @@ -538,13 +461,12 @@ try { //echo $result[1]." = ".$result[2]."\n"; $rpmname = "R-".$result[1]; $ver = str_replace('-', '.', $result[2]); - $add_upstream = addUpstream( - $db, + $add_upstream = $uptable->record( "R", $repo["name"], $rpmname, - $repo["state"], $ver, + $repo["state"]=='stable', ($repo["state"]=="stable"?"":"devel") ); |