Open Journal Systems  3.3.0
DepositDAO.inc.php
1 <?php
2 
14 import('lib.pkp.classes.db.DAO');
15 
16 class DepositDAO extends DAO {
21  public function newDataObject() {
22  return new Deposit(null);
23  }
24 
31  public function getById($depositId, $journalId = null) {
32  $params = array((int) $depositId);
33  if ($journalId !== null) $params[] = (int) $journalId;
34  $result = $this->retrieve(
35  'SELECT *
36  FROM pln_deposits
37  WHERE deposit_id = ?'
38  . ($journalId !== null?' AND journal_id = ?':''),
39  $params
40  );
41  $returner = null;
42  if ($result->RecordCount() != 0) {
43  $returner = $this->_fromRow($result->GetRowAssoc(false));
44  }
45  $result->Close();
46  return $returner;
47  }
48 
54  public function insertObject($deposit) {
55  $this->update(
56  sprintf('
57  INSERT INTO pln_deposits
58  (journal_id,
59  uuid,
60  status,
61  date_status,
62  date_created,
63  date_modified)
64  VALUES
65  (?, ?, ?, %s, NOW(), %s)',
66  $this->datetimeToDB($deposit->getLastStatusDate()),
67  $this->datetimeToDB($deposit->getDateModified())
68  ),
69  array(
70  (int) $deposit->getJournalId(),
71  $deposit->getUUID(),
72  (int) $deposit->getStatus()
73  )
74  );
75  $deposit->setId($this->getInsertId());
76  return $deposit->getId();
77  }
78 
83  public function updateObject($deposit) {
84  $this->update(
85  sprintf('
86  UPDATE pln_deposits SET
87  journal_id = ?,
88  uuid = ?,
89  status = ?,
90  date_status = %s,
91  date_created = %s,
92  date_modified = NOW(),
93  export_deposit_error = ?
94  WHERE deposit_id = ?',
95  $this->datetimeToDB($deposit->getLastStatusDate()),
96  $this->datetimeToDB($deposit->getDateCreated())
97  ),
98  array(
99  (int) $deposit->getJournalId(),
100  $deposit->getUUID(),
101  (int) $deposit->getStatus(),
102  $deposit->getExportDepositError(),
103  (int) $deposit->getId()
104  )
105  );
106  }
107 
112  public function deleteObject($deposit) {
113  $depositObjectDao = DAORegistry::getDAO('DepositObjectDAO');
114  foreach($deposit->getDepositObjects() as $depositObject) {
115  $depositObjectDao->deleteObject($depositObject);
116  }
117 
118  $this->update(
119  'DELETE from pln_deposits WHERE deposit_id = ?',
120  (int) $deposit->getId()
121  );
122  }
123 
128  public function getInsertId() {
129  return $this->_getInsertId('pln_deposits', 'deposit_id');
130  }
131 
137  public function _fromRow($row) {
138  $deposit = $this->newDataObject();
139  $deposit->setId($row['deposit_id']);
140  $deposit->setJournalId($row['journal_id']);
141  $deposit->setUUID($row['uuid']);
142  $deposit->setStatus($row['status']);
143  $deposit->setLastStatusDate($this->datetimeFromDB($row['date_status']));
144  $deposit->setDateCreated($this->datetimeFromDB($row['date_created']));
145  $deposit->setDateModified($this->datetimeFromDB($row['date_modified']));
146  $deposit->setExportDepositError($row['export_deposit_error']);
147 
148  HookRegistry::call('DepositDAO::_fromRow', array(&$deposit, &$row));
149 
150  return $deposit;
151  }
152 
159  public function getByUUID($journalId, $depositUuid) {
160  $result = $this->retrieve(
161  'SELECT *
162  FROM pln_deposits
163  WHERE journal_id = ?
164  AND uuid = ?',
165  array (
166  (int) $journalId,
167  $depositUuid
168  )
169  );
170  $returner = null;
171  if ($result->RecordCount() != 0) {
172  $returner = $this->_fromRow($result->GetRowAssoc(false));
173  }
174  $result->Close();
175  return $returner;
176  }
177 
183  public function getByJournalId($journalId, $dbResultRange = null) {
184  $result = $this->retrieveRange(
185  'SELECT *
186  FROM pln_deposits
187  WHERE journal_id = ?
188  ORDER BY deposit_id',
189  array (
190  (int) $journalId
191  ),
192  $dbResultRange
193  );
194 
195  return new DAOResultFactory($result, $this, '_fromRow');
196  }
197 
203  public function getNew($journalId) {
204  $result = $this->retrieve(
205  'SELECT * FROM pln_deposits WHERE journal_id = ? AND status = ?',
206  array(
207  (int) $journalId,
208  (int) PLN_PLUGIN_DEPOSIT_STATUS_NEW
209  )
210  );
211 
212  return new DAOResultFactory($result, $this, '_fromRow');
213  }
214 
220  public function getNeedTransferring($journalId) {
221  $result = $this->retrieve(
222  'SELECT *
223  FROM pln_deposits AS d
224  WHERE d.journal_id = ?
225  AND d.status & ? = 0
226  AND d.status & ? = 0
227  AND d.status & ? = 0',
228  array (
229  (int) $journalId,
230  (int) PLN_PLUGIN_DEPOSIT_STATUS_PACKAGING_FAILED,
231  (int) PLN_PLUGIN_DEPOSIT_STATUS_TRANSFERRED,
232  (int) PLN_PLUGIN_DEPOSIT_STATUS_LOCKSS_AGREEMENT
233  )
234  );
235 
236  return new DAOResultFactory($result, $this, '_fromRow');
237  }
238 
244  public function getNeedPackaging($journalId) {
245  $result = $this->retrieve(
246  'SELECT *
247  FROM pln_deposits AS d
248  WHERE d.journal_id = ?
249  AND d.status & ? = 0
250  AND d.status & ? = 0
251  AND d.status & ? = 0',
252  array(
253  (int) $journalId,
254  (int) PLN_PLUGIN_DEPOSIT_STATUS_PACKAGED,
255  (int) PLN_PLUGIN_DEPOSIT_STATUS_LOCKSS_AGREEMENT,
256  (int) PLN_PLUGIN_DEPOSIT_STATUS_PACKAGING_FAILED
257  )
258  );
259 
260  return new DAOResultFactory($result, $this, '_fromRow');
261  }
262 
268  public function getNeedStagingStatusUpdate($journalId) {
269  $result = $this->retrieve(
270  'SELECT *
271  FROM pln_deposits AS d
272  WHERE d.journal_id = ?
273  AND d.status & ? <> 0
274  AND d.status & ? = 0
275  AND d.status & ? = 0',
276  array (
277  (int) $journalId,
278  (int) PLN_PLUGIN_DEPOSIT_STATUS_TRANSFERRED,
279  (int) PLN_PLUGIN_DEPOSIT_STATUS_LOCKSS_AGREEMENT,
280  (int) PLN_PLUGIN_DEPOSIT_STATUS_PACKAGING_FAILED
281  )
282  );
283 
284  return new DAOResultFactory($result, $this, '_fromRow');
285  }
286 
291  public function deleteByJournalId($journalId) {
292  $deposits = $this->getByJournalId($journalId);
293  foreach($deposits as $deposit) {
294  $this->deleteDeposit($deposit);
295  }
296  }
297 }
DepositDAO\getByUUID
getByUUID($journalId, $depositUuid)
Definition: DepositDAO.inc.php:159
DepositDAO\getInsertId
getInsertId()
Definition: DepositDAO.inc.php:128
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
DepositDAO\getById
getById($depositId, $journalId=null)
Definition: DepositDAO.inc.php:31
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
DepositDAO\getByJournalId
getByJournalId($journalId, $dbResultRange=null)
Definition: DepositDAO.inc.php:183
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
DepositDAO\getNeedTransferring
getNeedTransferring($journalId)
Definition: DepositDAO.inc.php:220
Deposit
Container for deposit objects that are submitted to a PLN.
Definition: Deposit.inc.php:14
DepositDAO\getNeedStagingStatusUpdate
getNeedStagingStatusUpdate($journalId)
Definition: DepositDAO.inc.php:268
DAO\datetimeFromDB
datetimeFromDB($dt)
Definition: DAO.inc.php:319
DepositDAO\updateObject
updateObject($deposit)
Definition: DepositDAO.inc.php:83
DepositDAO\_fromRow
_fromRow($row)
Definition: DepositDAO.inc.php:137
DepositDAO\insertObject
insertObject($deposit)
Definition: DepositDAO.inc.php:54
DepositDAO\deleteByJournalId
deleteByJournalId($journalId)
Definition: DepositDAO.inc.php:291
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
DepositDAO\deleteObject
deleteObject($deposit)
Definition: DepositDAO.inc.php:112
DAO\datetimeToDB
datetimeToDB($dt)
Definition: DAO.inc.php:299
DepositDAO\getNeedPackaging
getNeedPackaging($journalId)
Definition: DepositDAO.inc.php:244
DAO\_getInsertId
_getInsertId($table='', $id='')
Definition: DAO.inc.php:255
DepositDAO\newDataObject
newDataObject()
Definition: DepositDAO.inc.php:21
DepositDAO\getNew
getNew($journalId)
Definition: DepositDAO.inc.php:203
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
DepositDAO
Operations for adding a PLN deposit.
Definition: DepositDAO.inc.php:16
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31