Open Journal Systems  2.4.4
 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 
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  unset($result);
98 
99  return $this->getAffectedRows();
100  }
101 }
102 
103 ?>
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
getAffectedRows()
Definition: DAO.inc.php:261
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211