Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
ScheduledTaskDAO.inc.php
1 <?php
2 
22 import('lib.pkp.classes.scheduledTask.ScheduledTask');
23 
24 class ScheduledTaskDAO extends DAO {
28  function ScheduledTaskDAO() {
29  parent::DAO();
30  }
31 
37  function getLastRunTime($className) {
38  $result =& $this->retrieve(
39  'SELECT last_run FROM scheduled_tasks WHERE class_name = ?',
40  array($className)
41  );
42 
43  if ($result->RecordCount() == 0) {
44  $returner = 0;
45  } else {
46  $returner = strtotime($this->datetimeFromDB($result->fields[0]));
47  }
48 
49  $result->Close();
50  unset($result);
51 
52  return $returner;
53  }
54 
60  function updateLastRunTime($className, $timestamp = null) {
61  $result =& $this->retrieve(
62  'SELECT COUNT(*) FROM scheduled_tasks WHERE class_name = ?',
63  array($className)
64  );
65 
66  if (isset($result->fields[0]) && $result->fields[0] != 0) {
67  if (isset($timestamp)) {
68  $returner = $this->update(
69  'UPDATE scheduled_tasks SET last_run = ' . $this->datetimeToDB($timestamp) . ' WHERE class_name = ?',
70  array($className)
71  );
72  } else {
73  $returner = $this->update(
74  'UPDATE scheduled_tasks SET last_run = NOW() WHERE class_name = ?',
75  array($className)
76  );
77  }
78 
79  } else {
80  if (isset($timestamp)) {
81  $returner = $this->update(
82  sprintf('INSERT INTO scheduled_tasks (class_name, last_run)
83  VALUES (?, %s)', $this->datetimeToDB($timestamp)),
84  array($className)
85  );
86  } else {
87  $returner = $this->update(
88  'INSERT INTO scheduled_tasks (class_name, last_run)
89  VALUES (?, NOW())',
90  array($className)
91  );
92  }
93  }
94 
95  $result->Close();
96  unset($result);
97 
98  return $returner;
99  }
100 }
101 
102 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
Operations for retrieving and modifying Scheduled Task data.
updateLastRunTime($className, $timestamp=null)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211