summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2010-11-01 08:46:05 +0100
committerRemi Collet <fedora@famillecollet.com>2010-11-01 08:46:05 +0100
commitc28b13eaeca04574994d5a7c2320bbce4c63450f (patch)
treebabb19b528e46b85bbbdc59a78313d422f5bcd5a
parent1421a2207c0130030233e901d6f5055f54417e68 (diff)
add new TableRpmRepo->getMaxStamp() method and use it
-rw-r--r--all.php7
-rw-r--r--class/CommonTable.php4
-rw-r--r--class/TableRpmRepo.php12
-rw-r--r--rpm.php7
-rw-r--r--testdb.php4
5 files changed, 24 insertions, 10 deletions
diff --git a/all.php b/all.php
index 4a5a5ab..26283de 100644
--- a/all.php
+++ b/all.php
@@ -211,11 +211,8 @@ try {
$smarty->assign('owners', $owners);
}
- $sql='SELECT MAX(stamp) AS stamp FROM repo';
- $res=$db->query($sql);
- if ($res && $row=$res->fetchObject()) {
- $smarty->assign('repositories_update', date("r", $row->stamp));
- }
+ $rpmrepo = new TableRpmRepo($db);
+ $smarty->assign('repositories_update', date("r", $rpmrepo->getMaxStamp()));
$smarty->assign('packages', report($db));
} catch(PDOException $e) {
diff --git a/class/CommonTable.php b/class/CommonTable.php
index ba3f7ad..0aeeb29 100644
--- a/class/CommonTable.php
+++ b/class/CommonTable.php
@@ -262,6 +262,10 @@ abstract class CommonTable
**/
public function request ($crit='')
{
+ if (is_string($crit) && strpos($crit,' ')) {
+ // $crit is a full SQL command
+ return new TableIterator ($this->db, $crit);
+ }
return new TableIterator ($this->db, $this->table, $crit);
}
diff --git a/class/TableRpmRepo.php b/class/TableRpmRepo.php
index a8ae44f..3144abe 100644
--- a/class/TableRpmRepo.php
+++ b/class/TableRpmRepo.php
@@ -108,6 +108,18 @@ class TableRpmRepo extends CommonTable
}
return $res;
}
+
+ /**
+ * Retrieve the greater update date
+ */
+ function getMaxStamp() {
+
+ $sql='SELECT MAX(stamp) AS stamp FROM '.$this->table;
+ foreach ($this->request($sql) as $res) {
+ return $res['stamp'];
+ }
+ return 0;
+ }
}
?> \ No newline at end of file
diff --git a/rpm.php b/rpm.php
index 5b298e8..798cb29 100644
--- a/rpm.php
+++ b/rpm.php
@@ -244,11 +244,8 @@ try {
$smarty->assign('owners', $owners);
}
- $sql='SELECT MAX(stamp) AS stamp FROM repo';
- $res=$db->query($sql);
- if ($res && $row=$res->fetchObject()) {
- $smarty->assign('repositories_update', date("r", $row->stamp));
- }
+ $rpmrepo = new TableRpmRepo($db);
+ $smarty->assign('repositories_update', date("r", $rpmrepo->getMaxStamp()));
$smarty->assign('packages', report($db, $type));
} catch(PDOException $e) {
diff --git a/testdb.php b/testdb.php
index cc7c301..d27e24f 100644
--- a/testdb.php
+++ b/testdb.php
@@ -2,6 +2,8 @@
require "include/main.php";
require "class/CommonTable.php";
+date_default_timezone_set('Europe/Paris');
+
$db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS);
$pear = new TableRRepo($db);
@@ -66,6 +68,8 @@ if ($row = $rpm->get(888)) {
} else {
echo "not found\n";
}
+echo "Last update : ".date("r", $rpm->getMaxStamp())."\n";
+
$up = new TableUpstream($db);
$up->delete(array('name'=>'foo','type'=>'test'));
$rec = $up->record('test','bar','foo','1.0',true);