From 5cd7540f6d5aa824106ab7e9171fd36ed380bacd Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 1 Nov 2010 08:05:30 +0100 Subject: Create TableRpm class and use it in refresh --- refresh.php | 54 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) (limited to 'refresh.php') 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 "
";
     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++;
                             }
                         }
                     }
-- 
cgit