Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ScheduledTaskDAO.inc.php
1 <?php
2 
24 import('lib.pkp.classes.scheduledTask.ScheduledTask');
25 
26 class ScheduledTaskDAO extends DAO {
30  function ScheduledTaskDAO() {
31  parent::DAO();
32  }
33 
39  function getLastRunTime($className) {
40  $result = $this->retrieve(
41  'SELECT last_run FROM scheduled_tasks WHERE class_name = ?',
42  array($className)
43  );
44 
45  if ($result->RecordCount() == 0) {
46  $returner = 0;
47  } else {
48  $returner = strtotime($this->datetimeFromDB($result->fields[0]));
49  }
50 
51  $result->Close();
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  return $returner;
97  }
98 }
99 
100 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
Operations for retrieving and modifying Scheduled Task data.
updateLastRunTime($className, $timestamp=null)
datetimeFromDB($dt)
Definition: DAO.inc.php:313
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208