示例#1
0
 /**
  * Delete the metadata associated with the revision, deleting all
  * metadata for that revision if no metadataId is passed.
  *
  * @param ItemRevisionDao $revisiondao
  * @param null|int $metadataId
  * @throws Zend_Exception
  */
 public function deleteMetadata($revisiondao, $metadataId = null)
 {
     if (!$revisiondao instanceof ItemRevisionDao) {
         throw new Zend_Exception('Must pass a revision dao parameter');
     }
     $clause = 'itemrevision_id = ' . $revisiondao->getKey();
     if ($metadataId !== null) {
         $clause .= ' AND metadata_id = ' . $metadataId;
     }
     Zend_Registry::get('dbAdapter')->delete('metadatavalue', $clause);
     $item = $revisiondao->getItem();
     if (!$item) {
         return;
     }
     /** @var ItemModel $itemModel */
     $itemModel = MidasLoader::loadModel('Item');
     $lastrevision = $itemModel->getLastRevision($item);
     if ($lastrevision === false) {
         throw new Zend_Exception('The item must have at least one revision to have metadata', MIDAS_INVALID_POLICY);
     }
     // refresh lucene search index
     if ($lastrevision->getKey() == $revisiondao->getKey()) {
         $itemModel->save($item, true);
     }
 }