/**
  * Display list of metadata versions to compare with the selected version
  *
  * @return unknown
  */
 function do_startComparison()
 {
     $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion');
     $oDocument =& Document::get($this->oDocument->getId(), $comparison_version);
     if (PEAR::isError($oDocument)) {
         return $this->redirectToMain(_kt('The document you selected was invalid'));
     }
     if (!Permission::userHasDocumentReadPermission($oDocument)) {
         return $this->errorRedirectToMain(_kt('You are not allowed to view this document'));
     }
     $this->oDocument =& $oDocument;
     $this->oPage->setSecondaryTitle($oDocument->getName());
     $this->oPage->setBreadcrumbDetails(_kt('Select Document Version to compare against'));
     $aMetadataVersions = KTDocumentMetadataVersion::getByDocument($oDocument);
     $aVersions = array();
     foreach ($aMetadataVersions as $oVersion) {
         $aVersions[] = Document::get($oDocument->getId(), $oVersion->getId());
     }
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate('ktcore/document/comparison_version_select');
     $aTemplateData = array('context' => $this, 'document_id' => $this->oDocument->getId(), 'document' => $oDocument, 'versions' => $aVersions, 'downloadaction' => $oAction);
     return $oTemplate->render($aTemplateData);
 }
示例#2
0
 function _fieldValues()
 {
     static $lastFolder = null;
     if (is_null($lastFolder) || $lastFolder->getID() !== $this->iFolderId) {
         $lastFolder = Folder::get($this->iFolderId);
         if (PEAR::isError($lastFolder)) {
             $lastFolder = null;
         }
     }
     if (!is_null($lastFolder)) {
         $this->sFullPath = 'pending';
         if (!is_null($this->getMetadataVersionId())) {
             $metadata = KTDocumentMetadataVersion::get($this->getMetadataVersionId());
             $name = $metadata->getName();
             if ($lastFolder->getId() == 1) {
                 $this->sFullPath = $name;
             } else {
                 $this->sFullPath = $lastFolder->getFullPath() . '/' . $name;
             }
         }
         $this->sParentFolderIds = $lastFolder->getParentFolderIDs();
     }
     return parent::_fieldValues();
 }
 function getFieldsToSelect()
 {
     if (self::$_versionFields == null) {
         $sTable = KTUtil::getTableName('document_metadata_version');
         $aFields = DBUtil::getResultArray(array("DESCRIBE {$sTable}"));
         $result = array();
         for ($i = 0; $i < count($aFields); $i++) {
             $result[KTDocumentMetaDataVersion::getFieldType($aFields[$i]['Type']) . KTUtil::camelize($aFields[$i]['Field'])] = $aFields[$i]['Field'];
         }
         self::$_versionFields = $result;
     }
     return self::$_versionFields;
 }
 /**
  * This returns the version history on the document.
  *
  * @author KnowledgeTree Team
  * @access public
  * @return array The version history
  */
 function get_version_history()
 {
     $metadata_versions = KTDocumentMetadataVersion::getByDocument($this->document);
     $config = KTConfig::getSingleton();
     $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
     $versions = array();
     foreach ($metadata_versions as $version) {
         $document =& Document::get($this->documentid, $version->getId());
         $version = array();
         $userid = $document->getModifiedUserId();
         $user = User::get($userid);
         $username = '******';
         if (!PEAR::isError($user)) {
             $username = is_null($user) ? 'n/a' : $user->getName();
         }
         $version['user'] = $username;
         $version['metadata_version'] = $document->getMetadataVersion();
         $version['content_version'] = $document->getVersion();
         if ($wsversion >= 2) {
             $version['metadata_version'] = (int) $version['metadata_version'];
             $version['content_version'] = (double) $version['content_version'];
         }
         $versions[] = $version;
     }
     return $versions;
 }
 /**
  * Delete a selected version of the document.
  */
 function deleteVersion($oDocument, $iVersionID, $sReason)
 {
     $oDocument =& KTUtil::getObject('Document', $oDocument);
     $oVersion =& KTDocumentMetadataVersion::get($iVersionID);
     $oStorageManager =& KTStorageManagerUtil::getSingleton();
     global $default;
     if (empty($sReason)) {
         return PEAR::raiseError(_kt('Deletion requires a reason'));
     }
     if (PEAR::isError($oDocument) || $oDocument == false) {
         return PEAR::raiseError(_kt('Invalid document object.'));
     }
     if (PEAR::isError($oVersion) || $oVersion == false) {
         return PEAR::raiseError(_kt('Invalid document version object.'));
     }
     $iContentId = $oVersion->getContentVersionId();
     $oContentVersion = KTDocumentContentVersion::get($iContentId);
     if (PEAR::isError($oContentVersion) || $oContentVersion == false) {
         return PEAR::raiseError(_kt('Invalid document content version object.'));
     }
     // Check that the document content is not the same as the current content version
     $sDocStoragePath = $oDocument->getStoragePath();
     $sVersionStoragePath = $oContentVersion->getStoragePath();
     if ($sDocStoragePath == $sVersionStoragePath) {
         return PEAR::raiseError(_kt("Can't delete version: content is the same as the current document content."));
     }
     DBUtil::startTransaction();
     // now delete the document version
     $res = $oStorageManager->deleteVersion($oVersion);
     if (PEAR::isError($res) || $res == false) {
         //could not delete the document version from the file system
         $default->log->error('Deletion: Filesystem error deleting the metadata version ' . $oVersion->getMetadataVersion() . ' of the document ' . $oDocument->getFileName() . ' from folder ' . Folder::getFolderPath($oDocument->getFolderID()) . ' id=' . $oDocument->getFolderID());
         // we use a _real_ transaction here ...
         DBUtil::rollback();
         return PEAR::raiseError(_kt('There was a problem deleting the document from storage.'));
     }
     // change status for the metadata version
     $oVersion->setStatusId(VERSION_DELETED);
     $oVersion->update();
     // set the storage path to empty
     //        $oContentVersion->setStoragePath('');
     DBUtil::commit();
 }