/** * Return the latest bitstream from the given item revision. * * @param ItemRevisionDao $itemRevisionDao item revision DAO * @return BitstreamDao * @throws Zend_Exception */ public function getLatestBitstream($itemRevisionDao) { $bitstreamDaos = $itemRevisionDao->getBitstreams(); if (count($bitstreamDaos) === 0) { throw new Zend_Exception('Item revision does not contain any bitstreams'); } return $bitstreamDaos[0]; }
/** Delete a revision. Calling this will delete: * -The revision itself * -All bitstreams of the revision * -The feed for the creation of the revision * -The metadata associated with the revision. * * @param ItemRevisionDao $revisiondao * @throws Zend_Exception */ public function delete($revisiondao) { if (!$revisiondao instanceof ItemRevisionDao) { throw new Zend_Exception('Error in param revisiondao when deleting an ItemRevision.'); } $bitstreams = $revisiondao->getBitstreams(); /** @var BitstreamModel $bitstream_model */ $bitstream_model = MidasLoader::loadModel('Bitstream'); foreach ($bitstreams as $bitstream) { $bitstream_model->delete($bitstream); } // explicitly typecast the id to a string, for postgres $deleteType = array(MIDAS_FEED_CREATE_REVISION); $sql = $this->database->select()->setIntegrityCheck(false)->from(array('p' => 'feed'))->where('resource = ?', (string) $revisiondao->getKey()); $rowset = $this->database->fetchAll($sql); /** @var FeedModel $feed_model */ $feed_model = MidasLoader::loadModel('Feed'); foreach ($rowset as $row) { $feed = $this->initDao('Feed', $row); if (in_array($feed->getType(), $deleteType)) { $feed_model->delete($feed); } } // Delete metadata values for this revision $this->deleteMetadata($revisiondao); parent::delete($revisiondao); $revisiondao->saved = false; unset($revisiondao->itemrevision_id); }