Open Journal Systems  3.0.0
 All Data Structures 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 
61  function updateLastRunTime($className, $timestamp = null) {
62  $result = $this->retrieve(
63  'SELECT COUNT(*) FROM scheduled_tasks WHERE class_name = ?',
64  array($className)
65  );
66 
67  if (isset($result->fields[0]) && $result->fields[0] != 0) {
68  if (isset($timestamp)) {
69  $this->update(
70  'UPDATE scheduled_tasks SET last_run = ' . $this->datetimeToDB($timestamp) . ' WHERE class_name = ?',
71  array($className)
72  );
73  } else {
74  $this->update(
75  'UPDATE scheduled_tasks SET last_run = NOW() WHERE class_name = ?',
76  array($className)
77  );
78  }
79 
80  } else {
81  if (isset($timestamp)) {
82  $this->update(
83  sprintf('INSERT INTO scheduled_tasks (class_name, last_run)
84  VALUES (?, %s)', $this->datetimeToDB($timestamp)),
85  array($className)
86  );
87  } else {
88  $this->update(
89  'INSERT INTO scheduled_tasks (class_name, last_run)
90  VALUES (?, NOW())',
91  array($className)
92  );
93  }
94  }
95 
96  $result->Close();
97  return $this->getAffectedRows();
98  }
99 }
100 
101 ?>
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
getAffectedRows()
Definition: DAO.inc.php:258
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208