Esempio n. 1
0
 /**
  * Duplicate an item in destination folder/community.
  *
  * Create a new item (same as old one) in destination folder/community. The new item
  * have the same metadata and revisions with the old one, but its owner is set as the
  * input userDao parameter (who run this operation) and access policy is based on
  * the input folderDao parameter (destination folder)
  *
  * @param ItemDao $itemDao the item to be duplicated
  * @param UserDao $userDao the user who run this operation
  * @param FolderDao $folderDao destination folder
  * @return ItemDao
  * @throws Zend_Exception on invalid input parameters (itemDao, userDao and folderDao)
  */
 public function duplicateItem($itemDao, $userDao, $folderDao)
 {
     if (!$itemDao instanceof ItemDao || !$folderDao instanceof FolderDao) {
         throw new Zend_Exception('Error in ItemDao or FolderDao when duplicating item');
     }
     if (!$userDao instanceof UserDao) {
         throw new Zend_Exception('Should be an user.');
     }
     /** @var BitstreamModel $BitstreamModel */
     $BitstreamModel = MidasLoader::loadModel('Bitstream');
     $name = $itemDao->getName();
     $description = $itemDao->getDescription();
     $newItem = $this->createItem($name, $description, $folderDao);
     $newItem->setType($itemDao->getType());
     $newItem->setSizebytes($itemDao->getSizebytes());
     $newItem->setDateCreation(date('Y-m-d H:i:s'));
     $newItem->setDateUpdate(date('Y-m-d H:i:s'));
     $thumbnailId = $itemDao->getThumbnailId();
     if ($thumbnailId !== null) {
         $oldThumb = $BitstreamModel->load($thumbnailId);
         $newThumb = new BitstreamDao();
         $newThumb->setItemrevisionId(-1);
         $newThumb->setName($oldThumb->getName());
         $newThumb->setMimetype($oldThumb->getMimetype());
         $newThumb->setSizebytes($oldThumb->getSizebytes());
         $newThumb->setChecksum($oldThumb->getChecksum());
         $newThumb->setPath($oldThumb->getPath());
         $newThumb->setAssetstoreId($oldThumb->getAssetstoreId());
         $newThumb->setDate($oldThumb->getDate());
         $BitstreamModel->save($newThumb);
         $newItem->setThumbnailId($newThumb->getKey());
     }
     /** @var ItemRevisionModel $ItemRevisionModel */
     $ItemRevisionModel = MidasLoader::loadModel('ItemRevision');
     /** @var BitstreamModel $BitstreamModel */
     $BitstreamModel = MidasLoader::loadModel('Bitstream');
     /** @var MetadataModel $MetadataModel */
     $MetadataModel = MidasLoader::loadModel('Metadata');
     /** @var ItempolicygroupModel $ItemPolicyGroupModel */
     $ItemPolicyGroupModel = MidasLoader::loadModel('Itempolicygroup');
     $ItemPolicyGroupModel->computePolicyStatus($newItem);
     foreach ($itemDao->getRevisions() as $revision) {
         $dupItemRevision = new ItemRevisionDao();
         $dupItemRevision->setItemId($newItem->getItemId());
         $dupItemRevision->setRevision($revision->getRevision());
         $dupItemRevision->setDate($revision->getDate());
         $dupItemRevision->setChanges($revision->getChanges());
         $dupItemRevision->setUserId($userDao->getUserId());
         $dupItemRevision->setLicenseId($revision->getLicenseId());
         $ItemRevisionModel->save($dupItemRevision);
         // duplicate metadata value
         $metadatavalues = $ItemRevisionModel->getMetadata($revision);
         foreach ($metadatavalues as $metadata) {
             $MetadataModel->addMetadataValue($dupItemRevision, $metadata->getMetadatatype(), $metadata->getElement(), $metadata->getQualifier(), $metadata->getValue(), false);
         }
         // duplicate bitstream
         foreach ($revision->getBitstreams() as $bitstream) {
             $dupBitstream = new BitstreamDao();
             $dupBitstream->setItemrevisionId($dupItemRevision->getItemrevisionId());
             $dupBitstream->setName($bitstream->getName());
             $dupBitstream->setMimetype($bitstream->getMimetype());
             $dupBitstream->setSizebytes($bitstream->getSizebytes());
             $dupBitstream->setChecksum($bitstream->getChecksum());
             $dupBitstream->setPath($bitstream->getPath());
             $dupBitstream->setAssetstoreId($bitstream->getAssetstoreId());
             $dupBitstream->setDate($bitstream->getDate());
             $BitstreamModel->save($dupBitstream);
         }
     }
     $this->save($newItem, true);
     // call save with metadata changed flag
     return $newItem;
 }