Commit:    855410761a6c1fb934b9bd1616d4902283dd8e49
Author:    Anatol Belski <a...@php.net>         Tue, 24 Sep 2013 15:42:45 +0200
Parents:   44c4acc059b4c868f6783d646bbfb4c01ee4bfb2
Branches:  master

Link:       
http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=855410761a6c1fb934b9bd1616d4902283dd8e49

Log:
some improvements so we set the ts after a pkg was built

worky but has room for improvement

Changed paths:
  M  client/include/PeclDb.php
  M  client/script/pecl.php
  M  client/script/pecl_rss.php


Diff:
diff --git a/client/include/PeclDb.php b/client/include/PeclDb.php
index 108b691..1597abb 100644
--- a/client/include/PeclDb.php
+++ b/client/include/PeclDb.php
@@ -54,11 +54,16 @@ class PeclDb extends \SQLite3 {
                $this->exec($sql);
        }
 
-       public function exists($name, $version)
+       public function exists($name, $version, $where = '')
        {
+               /* cant check such thing, so trust :) */
+               if ($where) {
+                       $where = "AND $where";
+               }
+
                $name = $this->escapeString($name);
                $version = $this->escapeString($version);
-               $sql = "SELECT ts_built FROM ext_release WHERE ext_name = 
'$name' AND ext_version = '$version';";
+               $sql = "SELECT ts_built FROM ext_release WHERE ext_name = 
'$name' AND ext_version = '$version' $where;";
 
                $res = $this->query($sql);
 
@@ -70,9 +75,21 @@ class PeclDb extends \SQLite3 {
                return $ret;
        }
 
-       public function dump()
+       public function done($name, $version)
+       {
+               /* XXX That's an assumption as the latest timestamp should be 
about 30 mit old. 
+                  Need to extend pecl.php to set the real statuses when in't 
really done */
+               return $this->exists($name, $version, "ts_built - " . time() . 
" > 1800");
+       }
+
+       public function dump($where = '')
        {
-               $res = $this->query("SELECT * FROM ext_release ORDER BY 
ext_name, ext_version ASC");
+               /* cant check such thing, so trust :) */
+               if ($where) {
+                       $where = "WHERE $where";
+               }
+
+               $res = $this->query("SELECT * FROM ext_release $where ORDER BY 
ext_name, ext_version ASC");
                echo "DUMP ext_release " . PHP_EOL . PHP_EOL;
                while(false !== ($row = $res->fetchArray(SQLITE3_ASSOC))) {
                        foreach ($row as $col => $val) {
@@ -82,5 +99,18 @@ class PeclDb extends \SQLite3 {
                }
                $res->finalize();
        }
+
+       public function dumpQueue()
+       {
+               $this->dump("ts_built <= 0");
+       }
+
+       public function touch($name, $version) 
+       {
+               $name = $this->escapeString($name);
+               $version = $this->escapeString($version);
+               $sql = "UPDATE ext_release SET ts_built=" . time() . " WHERE 
lower(ext_name) = lower('$name') AND lower(ext_version) = lower('$version');";
+               $this->exec($sql);
+       }
 }
 
diff --git a/client/script/pecl.php b/client/script/pecl.php
index 7e5b6b1..353cd13 100644
--- a/client/script/pecl.php
+++ b/client/script/pecl.php
@@ -3,6 +3,7 @@ include __DIR__ . '/../data/config.php';
 include __DIR__ . '/../include/PeclBranch.php';
 include __DIR__ . '/../include/Tools.php';
 include __DIR__ . '/../include/PeclExt.php';
+include __DIR__ . '/../include/PeclDb.php';
 
 use rmtools as rm;
 
@@ -278,12 +279,23 @@ foreach ($builds as $build_name) {
                }
        } 
 
+       try {
+               $db_path = __DIR__ . '/../data/pecl.sqlite';
+               $db = new rm\PeclDb($db_path);
+               $db->touch($ext->getName(), $ext->getVersion());
+       } catch (Exception $e) {
+                       echo 'Error: ' . $e->getMessage() . PHP_EOL;
+       }
+
        $build->clean();
        $ext->cleanup($upload && $upload_success);
        rm\rmdir_rf($toupload_dir);
 
        unset($ext);
        unset($build);
+       if (isset($db)) {
+               unset($db);
+       }
 
        echo "Done." . PHP_EOL . PHP_EOL;
 
diff --git a/client/script/pecl_rss.php b/client/script/pecl_rss.php
index 263db0a..7ac7ad5 100644
--- a/client/script/pecl_rss.php
+++ b/client/script/pecl_rss.php
@@ -5,12 +5,13 @@ include __DIR__ . '/../include/PeclDb.php';
 
 use rmtools as rm;
 
-$longopts = array("help", "refresh", "dump-queue", "no-fetch", "force-fetch");
+$longopts = array("help", "refresh", "dump-queue", "dump-all", "no-fetch", 
"force-fetch");
 
 $options = getopt(NULL, $longopts);
 
 $refresh_db = isset($options['refresh']);
 $dump_queue = isset($options['dump-queue']);
+$dump_all = isset($options['dump-all']);
 $help = isset($options['help']);
 $no_fetch = isset($options['no-fetch']);
 $force_fetch = isset($options['force-fetch']);
@@ -20,6 +21,7 @@ if ($_SERVER['argc'] <= 1 || $help) {
        echo "Usage: pecl_rss.php [OPTION] ..." . PHP_EOL;
        echo "  --refresh       Read new data from the PECL RSS feed and save 
it to db, optional." . PHP_EOL;
        echo "  --dump-queue    Dump the db rows with zero built timestamp and 
exit, optional." . PHP_EOL;
+       echo "  --dump-all      Dump all the db rows, optional." . PHP_EOL;
        echo "  --no-fetch      Only update db, don't fetch. Only used with 
--refresh, optional." . PHP_EOL;
        echo "  --force-fetch   Fetch all the items and reupdate db. Only used 
with --refresh, optional." . PHP_EOL;
        echo "  --help          Show help and exit, optional." . PHP_EOL;
@@ -42,10 +44,15 @@ $db = new rm\PeclDb($db_path);
 
 /* --dump-queue */
 if ($dump_queue) {
-       $db->dump();
+       $db->dumpQueue();
        exit(0);
 }
 
+/* --dump-all */
+if ($dump_all) {
+       $db->dump();
+       exit(0);
+}
 
 /* --refresh, need to wrap it all with ifs maybe*/
 echo "Refreshing the data" . PHP_EOL;
@@ -99,6 +106,13 @@ foreach($latest->item as $item) {
                                        unlink($f);
                                }
                        }
+               } else if ($db->done($name, $version)) {
+                       echo "<$name-$version> is already done" . PHP_EOL;
+                       continue;
+               } else if ($db->exists($name, $version)) {
+                       /* XXX no check if file exists here, but should be */
+                       echo "<$name-$version> is already in the queue" . 
PHP_EOL;
+                       continue;
                }
 
                if (!$suspects) {


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to