the start of the auto-update code
authorpaulr <me@pjr.cc>
Tue, 26 Apr 2011 15:19:12 +0000 (01:19 +1000)
committerpaulr <me@pjr.cc>
Tue, 26 Apr 2011 15:19:12 +0000 (01:19 +1000)
lib/lib.php
lib/updates.php [new file with mode: 0644]
unittests/libload.php [new file with mode: 0644]

index 63462fe..dde9335 100644 (file)
@@ -4,6 +4,9 @@ require_once("config.php");
 require_once("wsdl.php");
 require_once("www.php");
 require_once("db.php");
+require_once("messages.php");
+require_once("datastore.php");
+require_once("updates.php");
 
 // first and foremost, load the plugins
 $basedir = dirname(__FILE__);
@@ -46,4 +49,7 @@ function urlInterpretter()
                }
        }
 }
+
+$db = db_getDB();
+db_createTable("options", "option_name", "option_value");
 ?>
\ No newline at end of file
diff --git a/lib/updates.php b/lib/updates.php
new file mode 100644 (file)
index 0000000..8e92481
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+$timerval_t = db_selectData("options", "option_name", "update.check.interval");
+
+//echo "timer check:\n";
+//print_r($timerval_t);
+//echo "timer endcheck\n";
+
+
+if(!isset($timerval_t[0])) {
+       //echo "likely we have no timer check value, setting to default of 3 days\n";
+       $ci = 3*24*3600;
+       db_insertData("options", "update.check.interval", "$ci");
+       $timerval = $ci;
+} else {
+       $timerval = $timerval_t[0]["option_value"];
+}
+
+$lastupdate_t = db_selectData("options", "option_name", "update.check.last");
+
+
+if(!isset($lastupdate_t[0])) {
+       db_insertData("options", "update.check.last", "0");
+       up_doUpdateCheck();
+} else {
+       // no last update, perform one now
+       $lastupdate = $lastupdate_t[0]["option_value"];
+
+       $ctime = time();
+       
+       $tdiff = $ctime - $lastupdate;
+       
+       if($tdiff > $timerval) {
+               up_doUpdateCheck();
+       }
+}
+//echo "timerval: $timerval\n";
+
+function up_doUpdateCheck()
+{
+       echo "do update check and reset interval\n";
+       
+       // db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true)
+       $ctime = time();
+       
+       db_updateData("options", "option_value", "$ctime", "option_name", "update.check.last");
+}
+?>
\ No newline at end of file
diff --git a/unittests/libload.php b/unittests/libload.php
new file mode 100644 (file)
index 0000000..bf99490
--- /dev/null
@@ -0,0 +1,5 @@
+<?php 
+require_once("../lib/lib.php");
+
+echo "and thats it\n";
+?>
\ No newline at end of file