Пример #1
0
 function testPurgeDeletedVersion()
 {
     $versionFactory = new Docman_VersionFactoryTestVersionDeleteFile($this);
     $dao = new MockDocman_VersionDao($this);
     $dao->setReturnValue('setPurgeDate', true);
     $versionFactory->setReturnValue('_getVersionDao', $dao);
     $version = new Docman_Version(array('id' => null, 'user_id' => null, 'item_id' => null, 'number' => null, 'label' => null, 'changelog' => null, 'date' => null, 'filename' => 'fileToPurge.txt', 'filesize' => null, 'filetype' => null, 'path' => dirname(__FILE__) . '/_fixtures/fileToPurge_txt'));
     $fp = fopen($version->getPath(), 'w');
     $this->assertTrue($versionFactory->PurgeDeletedVersion($version));
     $this->assertFalse(file_exists($version->getPath()));
 }
 /**
  *  method to check if the current item is a pdf using the item mime type
  *  @param  void
  *  @return boolean (true when pdf will be watermarked, false when it will be not watermarked)
  */
 public function check()
 {
     if ($this->version->getFiletype() == 'application/pdf') {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Index a new document with permissions
  *
  * @param Docman_Item    $item    The docman item
  * @param Docman_Version $version The version to index
  *
  * @throws FullTextSearchDocmanIndexFileTooBigException
  */
 public function indexNewVersion(Docman_Item $item, Docman_Version $version)
 {
     try {
         $this->client->getIndexedElement($item->getGroupId(), $item->getId());
         $this->logger->debug('index new version #' . $version->getId() . ' for document #' . $item->getId());
         $update_data = array();
         if (filesize($version->getPath()) > $this->max_indexed_file_size) {
             throw new FullTextSearchDocmanIndexFileTooBigException($item->getId());
         }
         $this->request_data_factory->updateFile($update_data, $version->getPath());
         $this->client->update($item->getGroupId(), $item->getId(), $update_data);
     } catch (ElasticSearch_ElementNotIndexed $exception) {
         $this->indexNewDocument($item, $version);
         return;
     }
 }
 public function queueNewDocumentVersion(Docman_Item $item, Docman_Version $version)
 {
     if ($this->plugin->isAllowed($item->getGroupId()) && $version->getNumber() > 1) {
         // will be done in plugin_docman_after_new_document since we
         // receive both event for a new document
         $this->system_event_manager->createEvent(SystemEvent_FULLTEXTSEARCH_DOCMAN_UPDATE::NAME, $this->getDocmanSerializedParameters($item, array($version->getNumber())), SystemEvent::PRIORITY_MEDIUM, SystemEvent::OWNER_APP);
     }
 }
 public function getFileContent(Docman_Version $version)
 {
     return array('file' => $this->fileContentEncode($version->getPath()));
 }
Пример #6
0
 private function getIndexedData(Docman_Item $item, Docman_Version $version)
 {
     return array('id' => $item->getId(), 'group_id' => $item->getGroupId(), 'title' => $item->getTitle(), 'description' => $item->getDescription(), 'permissions' => $this->permissions_manager->exportPermissions($item), 'file' => $this->fileContentEncode($version->getPath()));
 }
 function createItemFromUserInput()
 {
     $new_item = null;
     if ($this->request->exist('item')) {
         $item_factory =& $this->_getItemFactory();
         $mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']);
         $i = $this->request->get('item');
         $new_item = $item_factory->getItemFromRow($i);
         $new_item->setGroupId($this->_viewParams['group_id']);
         // Build metadata list (from db) ...
         $mdFactory->appendItemMetadataList($new_item);
         // ... and set the value (from user input)
         $this->setMetadataValuesFromUserInput($new_item, $i, $this->request->get('metadata'));
         if ($i['item_type'] == PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE) {
             $tmp_path = tempnam($GLOBALS['tmp_dir'], 'embedded_file');
             $f = fopen($tmp_path, 'w');
             fwrite($f, $this->request->get('content'));
             fclose($f);
             $v = new Docman_Version();
             $v->setPath($tmp_path);
             $new_item->setCurrentVersion($v);
         }
     }
     return $new_item;
 }
 /**
  * Delete a version of a file
  * 
  * @param Docman_File    $item
  * @param Docman_Version $version
  * @param PFUser           $user
  * 
  * @return Boolean
  */
 function _deleteVersion(Docman_File $item, Docman_Version $version, PFUser $user)
 {
     // Proceed to deletion
     $version_factory = $this->_getVersionFactory();
     return $version_factory->deleteSpecificVersion($item, $version->getNumber());
 }
 /**
  * Restore one version
  * 
  * @param Docman_Version $version
  * 
  * @return Boolean
  */
 public function restore($version)
 {
     $dao = $this->_getVersionDao();
     $dar = $dao->searchDeletedVersion($version->getItemId(), $version->getNumber());
     if ($dar && !$dar->isError()) {
         $row = $dar->getRow();
         if (!$row['purge_date'] && file_exists($row['path'])) {
             if ($dao->restore($version->getItemId(), $version->getNumber())) {
                 // Log the event
                 // Take into account deleted items because, when we restore a deleted item
                 // the versions are restored before the item (because we restore the item
                 // only if at least one version was restored successfully
                 $item = $this->_getItemFactory()->getItemFromDb($version->getItemId(), array('ignore_deleted' => true));
                 $user = $this->_getUserManager()->getCurrentUser();
                 $value = $version->getNumber();
                 if ($row['label'] !== '') {
                     $value .= ' (' . $row['label'] . ')';
                 }
                 $this->_getEventManager()->processEvent('plugin_docman_event_restore_version', array('group_id' => $item->getGroupId(), 'item' => $item, 'old_value' => $value, 'user' => $user));
                 return true;
             }
         }
     }
     return false;
 }
Пример #10
0
 /**
  * Downloads the file
  *
  * @param Docman_Version $version
  *
  * @return void
  */
 function download($version)
 {
     $version->preDownload($this->getItem(), $this->getUser());
     // Download the file
     parent::download($version->getFiletype(), $version->getFilesize(), $version->getPath());
 }