00001 <?php
00002
00021
00022
00023
00024 import('scheduledTask.ScheduledTask');
00025
00026 class ScheduledTaskDAO extends DAO {
00032 function getLastRunTime($className) {
00033 $result = &$this->retrieve(
00034 'SELECT last_run FROM scheduled_tasks WHERE class_name = ?',
00035 $className
00036 );
00037
00038 if ($result->RecordCount() == 0) {
00039 $returner = 0;
00040 } else {
00041 $returner = strtotime($this->datetimeFromDB($result->fields[0]));
00042 }
00043
00044 $result->Close();
00045 unset($result);
00046
00047 return $returner;
00048 }
00049
00055 function updateLastRunTime($className, $timestamp = null) {
00056 $result = &$this->retrieve(
00057 'SELECT COUNT(*) FROM scheduled_tasks WHERE class_name = ?',
00058 $className
00059 );
00060
00061 if (isset($result->fields[0]) && $result->fields[0] != 0) {
00062 if (isset($timestamp)) {
00063 $returner = $this->update(
00064 'UPDATE scheduled_tasks SET last_run = ' . $this->datetimeToDB($timestamp) . ' WHERE class_name = ?',
00065 array($className)
00066 );
00067 } else {
00068 $returner = $this->update('UPDATE scheduled_tasks SET last_run = NOW() WHERE class_name = ?', array($className));
00069 }
00070
00071 } else {
00072 if (isset($timestamp)) {
00073 $returner = $this->update(
00074 sprintf('INSERT INTO scheduled_tasks (class_name, last_run)
00075 VALUES (?, %s)', $this->datetimeToDB($timestamp)),
00076 array($className)
00077 );
00078 } else {
00079 $returner = $this->update(
00080 'INSERT INTO scheduled_tasks (class_name, last_run)
00081 VALUES (?, NOW())',
00082 $className
00083 );
00084 }
00085 }
00086
00087 $result->Close();
00088 unset($result);
00089
00090 return $returner;
00091 }
00092 }
00093
00094 ?>