8e9248110ccaff5f2b0d6c42fb83854f5e681865
[glcas.git] / lib / updates.php
1 <?php
2
3 $timerval_t = db_selectData("options", "option_name", "update.check.interval");
4
5 //echo "timer check:\n";
6 //print_r($timerval_t);
7 //echo "timer endcheck\n";
8
9
10 if(!isset($timerval_t[0])) {
11         //echo "likely we have no timer check value, setting to default of 3 days\n";
12         $ci = 3*24*3600;
13         db_insertData("options", "update.check.interval", "$ci");
14         $timerval = $ci;
15 } else {
16         $timerval = $timerval_t[0]["option_value"];
17 }
18
19 $lastupdate_t = db_selectData("options", "option_name", "update.check.last");
20
21
22 if(!isset($lastupdate_t[0])) {
23         db_insertData("options", "update.check.last", "0");
24         up_doUpdateCheck();
25 } else {
26         // no last update, perform one now
27         $lastupdate = $lastupdate_t[0]["option_value"];
28
29         $ctime = time();
30         
31         $tdiff = $ctime - $lastupdate;
32         
33         if($tdiff > $timerval) {
34                 up_doUpdateCheck();
35         }
36 }
37 //echo "timerval: $timerval\n";
38
39 function up_doUpdateCheck()
40 {
41         echo "do update check and reset interval\n";
42         
43         // db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true)
44         $ctime = time();
45         
46         db_updateData("options", "option_value", "$ctime", "option_name", "update.check.last");
47 }
48 ?>