diff options
-rw-r--r-- | class/TableRpm.php | 66 | ||||
-rw-r--r-- | refresh.php | 54 | ||||
-rw-r--r-- | testdb.php | 2 |
3 files changed, 89 insertions, 33 deletions
diff --git a/class/TableRpm.php b/class/TableRpm.php new file mode 100644 index 0000000..8a6b39b --- /dev/null +++ b/class/TableRpm.php @@ -0,0 +1,66 @@ +<?php + +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * Class for "repo" Table management + * + * PHP version 5 + * + * Copyright © 2010 Remi Collet + * + * This file is part of rpmphp. + * + * rpmphp is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * rpmphp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with rpmphp. If not, see <http://www.gnu.org/licenses/>. + * + * @category Main + * @package RPMPHP + * + * @author Remi Collet <unknown@unknwown.com> + * @author Johan Cwiklinski <johan@x-tnd.be> + * @copyright 2010 Remi Collet + * @license http://www.gnu.org/licenses/agpl-3.0-standalone.html AGPL License 3.0 or (at your option) any later version + * @link http://github.com/remicollet/rpmphp/ + * @since The begining of times. +*/ +class TableRpm extends CommonTable +{ + /** + * Create the table and populate it with known repo + * + * @return void + */ + protected function createTable() + { + // Table schema + $sql = "CREATE TABLE IF NOT EXISTS `rpm` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `arch` varchar(20) DEFAULT NULL, + `epoch` varchar(20) NOT NULL, + `ver` varchar(20) NOT NULL, + `rel` varchar(40) NOT NULL, + `summary` varchar(200) NOT NULL, + `url` varchar(200) NOT NULL, + `location` varchar(200) DEFAULT NULL, + `repo_main` varchar(16) NOT NULL, + `repo_sub` varchar(16) NOT NULL, + PRIMARY KEY (`id`), + KEY `name` (`name`), + KEY `repo` (`repo_main`, `repo_sub`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; + $this->exec($sql); + } +} +?>
\ No newline at end of file diff --git a/refresh.php b/refresh.php index 539e1a5..4ab482a 100644 --- a/refresh.php +++ b/refresh.php @@ -36,6 +36,8 @@ */ chdir(dirname($_SERVER["SCRIPT_FILENAME"])); +date_default_timezone_set('Europe/Paris'); + if (isset($_SERVER["SERVER_NAME"])) { echo "<pre>"; ini_set("max_execution_time", "0"); @@ -62,16 +64,15 @@ 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); } $rpmrepo = new TableRpmRepo($db); + $rpmtable = new TableRpm($db); + foreach ($rpmrepo->request($crit) as $row) { echo date("r : ") . "REPOSITORY " . $row['main'] . " " . $row['sub'] . "\n"; @@ -106,43 +107,30 @@ try { " packages\n"; unset($txt); - $sql = sprintf( - "DELETE FROM rpm WHERE repo_main='%s' AND repo_sub='%s'", - $row['main'], - $row['sub'] + $crit = array( + 'repo_main' => $row['main'], + 'repo_sub' => $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"; - } + $nb = $rpmtable->delete($crit); + 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 + + $input = array( + 'repo_main' => $row['main'], + 'repo_sub' => $row['sub'], + 'name' => $package->name, + 'epoch' => $ver['epoch'], + 'ver' => $ver['ver'], + 'rel' => $ver['rel'], + 'summary' => $package->summary, + 'url' => $package->url ); - $nb=$db->exec($sql); - if ($nb) { - $tot+=$nb; - } else { - echo date("r : ") . "SQL ERROR = " . - implode(" ", $db->errorInfo()) . "\n"; + if ($rpmtable->add($input)) { + $tot++; } } } @@ -88,4 +88,6 @@ echo "request(test) : "; foreach($up->request(array('type'=>'test', 'ORDER'=>'name')) as $upstr) { print_r($upstr); } + +$rpm = new TableRpm($db); ?> |