Пример #1
0
 function check_entity($oEntity)
 {
     if (is_a($oEntity, 'Document')) {
         if (!KTDocumentUtil::canBeMoved($oEntity)) {
             return PEAR::raiseError(_kt('Document cannot be copied'));
         }
     }
     return parent::check_entity($oEntity);
 }
Пример #2
0
 /**
  * Moves the document from one folder to another.
  *
  * <code>
  * $ktapi = new KTAPI();
  * $session = $ktapi->start_system_session();
  * $document = $ktapi->get_document_by_id($documentid);
  * $newFolder = $this->root->add_folder("New folder");
  * $document->move($newFolder, 'Reason for moving the document');
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @param KTAPI_Folder $ktapi_target_folder The folder object where the document is being moved into
  * @param string $reason The reason for the move
  * @param string $newname Optional. The title of the document to be used in the case of a name clash
  * @param string $newfilename Optional. The filename of the document to be used in the case of a name clash
  * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
  */
 function move(&$ktapi_target_folder, $reason, $newname = null, $newfilename = null)
 {
     assert(!is_null($ktapi_target_folder));
     assert($ktapi_target_folder instanceof KTAPI_Folder);
     // is_a($ktapi_target_folder,'KTAPI_Folder'));
     if (empty($newname)) {
         $newname = null;
     }
     if (empty($newfilename)) {
         $newfilename = null;
     }
     $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_DOCUMENT_MOVE);
     if (PEAR::isError($user)) {
         return $user;
     }
     if ($this->document->getIsCheckedOut()) {
         return new PEAR_Error(KTAPI_ERROR_DOCUMENT_CHECKED_OUT);
     }
     $target_folder = $ktapi_target_folder->get_folder();
     $result = $this->can_user_access_object_requiring_permission($target_folder, KTAPI_PERMISSION_WRITE);
     if (PEAR::isError($result)) {
         return $result;
     }
     if (!KTDocumentUtil::canBeMoved($this->document)) {
         return new PEAR_Error('Document cannot be moved.');
     }
     $name = $this->document->getName();
     $clash = KTDocumentUtil::nameExists($target_folder, $name);
     if ($clash && !is_null($newname)) {
         $name = $newname;
         $clash = KTDocumentUtil::nameExists($target_folder, $name);
     }
     if ($clash) {
         return new PEAR_Error('A document with this title already exists in your chosen folder.  Please choose a different folder, or specify a new title for the moved document.');
     }
     $filename = $this->document->getFilename();
     $clash = KTDocumentUtil::fileExists($target_folder, $filename);
     if ($clash && !is_null($newname)) {
         $filename = $newfilename;
         $clash = KTDocumentUtil::fileExists($target_folder, $filename);
     }
     if ($clash) {
         return new PEAR_Error('A document with this filename already exists in your chosen folder.  Please choose a different folder, or specify a new filename for the moved document.');
     }
     DBUtil::startTransaction();
     $res = KTDocumentUtil::move($this->document, $target_folder, $user, $reason);
     if (PEAR::isError($res)) {
         DBUtil::rollback();
         return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res);
     }
     $this->document->setName($name);
     $this->document->setFilename($filename);
     $res = $this->document->update();
     if (PEAR::isError($res)) {
         DBUtil::rollback();
         return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res);
     }
     DBUtil::commit();
 }
Пример #3
0
 function check_entity($oEntity)
 {
     if (is_a($oEntity, 'Document')) {
         if (!KTDocumentUtil::canBeMoved($oEntity, $sError)) {
             if (PEAR::isError($sError)) {
                 return $sError;
             }
             return PEAR::raiseError(_kt('Document cannot be moved'));
         }
     }
     if (is_a($oEntity, 'Folder')) {
         $aDocuments = array();
         $aChildFolders = array();
         $oFolder = $oEntity;
         // Get folder id
         $sFolderId = $oFolder->getID();
         // Get documents in folder
         $sDocuments = $oFolder->getDocumentIDs($sFolderId);
         $aDocuments = !empty($sDocuments) ? explode(',', $sDocuments) : array();
         // Loop through documents and send to this function for checking
         if (!empty($aDocuments)) {
             foreach ($aDocuments as $sDocID) {
                 $oDocument = Document::get($sDocID);
                 $res = $this->check_entity($oDocument);
                 if (PEAR::isError($res)) {
                     // NOTE: we may want to append the document reason to this
                     // in order for the user to have some idea WHY the folder cannot be moved
                     return PEAR::raiseError(_kt('Folder cannot be moved'));
                 }
             }
         }
         // If all documents at the current level may be moved, we can continue
         // Get any existing subfolders
         $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR\n            parent_folder_ids LIKE '{$sFolderId},%' OR\n            parent_folder_ids LIKE '%,{$sFolderId},%' OR\n            parent_folder_ids LIKE '%,{$sFolderId}'";
         $aChildFolders = $this->oFolder->getList($sWhereClause);
         // Loop through subfolders and check each in the same way as the parent
         if (!empty($aChildFolders)) {
             foreach ($aChildFolders as $oChild) {
                 $res = $this->check_entity($oChild);
                 if (PEAR::isError($res)) {
                     // NOTE: we may want to append the document reason to this
                     // in order for the user to have some idea WHY the folder cannot be moved
                     return PEAR::raiseError(_kt('Folder cannot be moved'));
                 }
             }
         }
     }
     return parent::check_entity($oEntity);
 }