diff options
Diffstat (limited to 'refresh.php')
-rw-r--r-- | refresh.php | 184 |
1 files changed, 92 insertions, 92 deletions
diff --git a/refresh.php b/refresh.php index aebeec2..4026f68 100644 --- a/refresh.php +++ b/refresh.php @@ -96,104 +96,100 @@ try { if ($_SERVER['argc']==1 || in_array('repo', $_SERVER['argv'])) { if (in_array('empty', $_SERVER['argv'])) { $res=$db->query("SELECT * FROM repo WHERE stamp IS NULL"); + $crit = array('stamp' => null); } else if (in_array('old', $_SERVER['argv'])) { $res=$db->query("SELECT * FROM repo"); + $crit = array(); } else { $res=$db->query("SELECT * FROM repo WHERE active=1"); + $crit = array('active' => 1); } - if (!$res) { - echo date("r : ") . "SQL ERROR = " . - implode(" ", $db->errorInfo()) . "\n"; - } else { - while ($row = $res->fetchObject()) { - echo date("r : ") . "REPOSITORY " . $row->main . " " . - $row->sub . "\n"; - $TimRemote = 0; - $repomd = simplexml_load_file($row->url . "repodata/repomd.xml"); - if ($repomd) { - foreach ($repomd->data as $data) { - if ($data->attributes()=="primary") { - $TimRemote = $data->timestamp; - $UrlRemote = $row->url . $data->location->attributes(); - } + $rpmrepo = new TableRpmRepo($db); + foreach ($rpmrepo->request($crit) as $row) { + echo date("r : ") . "REPOSITORY " . $row['main'] . " " . + $row['sub'] . "\n"; + $TimRemote = 0; + $repomd = @simplexml_load_file($row['url'] . "repodata/repomd.xml"); + if ($repomd) { + foreach ($repomd->data as $data) { + if ($data->attributes()=="primary") { + $TimRemote = $data->timestamp; + $UrlRemote = $row['url'] . $data->location->attributes(); } } - if ($TimRemote > $row->stamp) { - echo date("r : ") . "Loading $UrlRemote\n"; - - //$fic=gzopen("primary.xml.gz", "r"); - $fic=gzopen($UrlRemote, "r"); - if ($fic) { - $txt=""; - while ($buf=gzread($fic, 8196)) { - $txt .= $buf; - } - echo date("r : ") . "Read " . strlen($txt) . " bytes\n"; - gzclose($fic); - - $primary = simplexml_load_string($txt); - echo date("r : ") . "Read " . $primary->attributes() . - " packages\n"; - unset($txt); - - $sql = sprintf( - "DELETE FROM rpm WHERE repo_main='%s' AND repo_sub='%s'", - $row->main, - $row->sub - ); - $nb=$db->exec($sql); - if ($nb===false) { - echo date("r : ") . "SQL ERROR = " . - implode(" ", $db->errorInfo()) . "\n"; - } else { - echo date("r : ") . "Delete $nb packages\n"; - } + } + if (!$TimRemote) { + echo date("r : ") . "Can't read $UrlRemote\n"; + + } else if ($TimRemote > $row['stamp']) { + echo date("r : ") . "Loading $UrlRemote\n"; + + //$fic=gzopen("primary.xml.gz", "r"); + $fic=gzopen($UrlRemote, "r"); + if ($fic) { + $txt=""; + while ($buf=gzread($fic, 8196)) { + $txt .= $buf; + } + echo date("r : ") . "Read " . strlen($txt) . " bytes\n"; + gzclose($fic); + + $primary = simplexml_load_string($txt); + echo date("r : ") . "Read " . $primary->attributes() . + " packages\n"; + unset($txt); + + $sql = sprintf( + "DELETE FROM rpm WHERE repo_main='%s' AND repo_sub='%s'", + $row['main'], + $row['sub'] + ); + $nb=$db->exec($sql); + if ($nb===false) { + echo date("r : ") . "SQL ERROR = " . + implode(" ", $db->errorInfo()) . "\n"; + } else { + echo date("r : ") . "Delete $nb packages\n"; + } - $tot=0; - foreach ($primary->package as $package) { - if ($package->attributes()=='rpm') { - $ver = $package->version->attributes(); - $sql = sprintf( - "INSERT INTO rpm SET repo_main='%s', repo_sub='%s', name='%s', epoch='%s', ver='%s', rel='%s', summary='%s', url='%s'", - $row->main, - $row->sub, - $package->name, - $ver['epoch'], - $ver['ver'], - $ver['rel'], - addslashes($package->summary), - $package->url - ); - $nb=$db->exec($sql); - if ($nb) { - $tot+=$nb; - } else { - echo date("r : ") . "SQL ERROR = " . - implode(" ", $db->errorInfo()) . "\n"; - } + $tot=0; + foreach ($primary->package as $package) { + if ($package->attributes()=='rpm') { + $ver = $package->version->attributes(); + $sql = sprintf( + "INSERT INTO rpm + SET repo_main='%s', repo_sub='%s', name='%s', + epoch='%s', ver='%s', rel='%s', summary='%s', + url='%s'", + $row['main'], + $row['sub'], + $package->name, + $ver['epoch'], + $ver['ver'], + $ver['rel'], + addslashes($package->summary), + $package->url + ); + $nb=$db->exec($sql); + if ($nb) { + $tot+=$nb; + } else { + echo date("r : ") . "SQL ERROR = " . + implode(" ", $db->errorInfo()) . "\n"; } } - echo date("r : ") . "Write $tot packages\n"; + } + echo date("r : ") . "Write $tot packages\n"; - $sql=sprintf( - "UPDATE repo SET stamp=%d WHERE ID=%d", - $TimRemote, - $row->ID - ); - $nb=$db->exec($sql); - if ($nb===false) { - echo date("r : ") . "SQL ERROR = " . - implode(" ", $db->errorInfo()) . "\n"; - } + $rpmrepo->update($row['id'], array('stamp' =>$TimRemote)); - unset($primary); - } else { - echo date("r : ") . "ERROR : can't read $UrlRemote\n"; - } + unset($primary); } else { - echo date("r : ") . "no update needed : $TimRemote / " . - $row->stamp . "\n"; + echo date("r : ") . "ERROR : can't read $UrlRemote\n"; } + } else { + echo date("r : ") . "no update needed : $TimRemote / " . + $row['stamp'] . "\n"; } } } // If ask @@ -233,12 +229,14 @@ try { ) ) ); - $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)"); + $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])"; + echo date("r : ") . + "ERROR xmlrpc: $stable[faultString] ($stable[faultCode])"; } else { - $sql = sprintf("DELETE FROM upstream WHERE type='pecl' AND channel='pecl'"); + $sql = "DELETE FROM upstream WHERE type='pecl' AND channel='pecl'"; $nb=$db->exec($sql); if ($nb===false) { echo date("r : ") . "SQL ERROR = " . @@ -261,7 +259,6 @@ try { ); } echo date("r : ") . "Write $nb packages\n"; - // echo date("r : ") . "saved " . file_put_contents("cache/pecl-stable", serialize($stable)) . " bytes\n"; } // ------------------------------------------------------------------- @@ -277,7 +274,8 @@ try { ) ) ); - $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)"); + $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] ". @@ -308,7 +306,7 @@ try { if ($_SERVER['argc']==1 || in_array('pear', $_SERVER['argv'])) { echo date("r : ") . "PEAR reading channels\n"; $pear = new TablePearRepo($db); - $channels = $pear->getAllRepo(); + $channels = $pear->getAllRepo(true); try { $nbtot=0; @@ -533,7 +531,8 @@ try { } } $results=array(); - if (preg_match_all('/Package: *(.*)\nVersion: *(.*)\n/i', $index, $results, PREG_SET_ORDER)) { + $pat = '/Package: *(.*)\nVersion: *(.*)\n/i'; + if (preg_match_all($pat, $index, $results, PREG_SET_ORDER)) { $tot=0; foreach ($results as $result) { //echo $result[1]." = ".$result[2]."\n"; @@ -610,7 +609,8 @@ try { $line[$i]=trim($line[$i]); } $sql=sprintf( - "INSERT INTO `acls` SET collection='%s', name='%s', summary='%s'", + "INSERT INTO `acls` + SET collection='%s', name='%s', summary='%s'", $line[0], $line[1], addslashes($line[2]) |