예제 #1
0
 function testBreadcrumbsForDocument()
 {
     $oFolder =& KTFolderUtil::add($this->oFolder, 'testBreadcrumbsForDocument', $this->oUser);
     $oDocument =& KTDocumentUtil::add($oFolder, 'testBreadcrumbsForDocument.txt', $this->oUser, array());
     $aBreadcrumbs =& KTBrowseUtil::breadcrumbsForDocument($oDocument, array('final' => true));
     $this->assertEqual($this->_getId($aBreadcrumbs[0]['url']), 1);
     $this->assertEqual($aBreadcrumbs[0]['name'], 'Folders');
     $this->assertEqual($this->_getId($aBreadcrumbs[1]['url']), $this->oFolder->getId());
     $this->assertEqual($aBreadcrumbs[1]['name'], $this->oFolder->getName());
     $this->assertEqual($this->_getId($aBreadcrumbs[2]['url']), $oFolder->getId());
     $this->assertEqual($aBreadcrumbs[2]['name'], $oFolder->getName());
     $this->assertNull($aBreadcrumbs[3]['url']);
     $this->assertEqual($aBreadcrumbs[3]['name'], $oDocument->getName());
     $aBreadcrumbs =& KTBrowseUtil::breadcrumbsForDocument($oDocument, array('final' => false));
     $this->assertEqual($this->_getId($aBreadcrumbs[0]['url']), 1);
     $this->assertEqual($aBreadcrumbs[0]['name'], 'Folders');
     $this->assertEqual($this->_getId($aBreadcrumbs[1]['url']), $this->oFolder->getId());
     $this->assertEqual($aBreadcrumbs[1]['name'], $this->oFolder->getName());
     $this->assertEqual($this->_getId($aBreadcrumbs[2]['url']), $oFolder->getId());
     $this->assertEqual($aBreadcrumbs[2]['name'], $oFolder->getName());
     $this->assertEqual($this->_getId($aBreadcrumbs[3]['url']), $oDocument->getId());
     $this->assertEqual($aBreadcrumbs[3]['name'], $oDocument->getName());
 }
예제 #2
0
 function testMove()
 {
     $oTestFolder = KTFolderUtil::add($this->oFolder, 'testMoveFolder', $this->oUser);
     $this->assertNotError($oTestFolder);
     if (PEAR::isError($oTestFolder)) {
         return;
     }
     $this->assertEntity($oTestFolder, 'Folder');
     $oSrcFolder = KTFolderUtil::add($this->oFolder, 'testMoveSrcFolder', $this->oUser);
     $this->assertNotError($oSrcFolder);
     if (PEAR::isError($oSrcFolder)) {
         return;
     }
     $this->assertEntity($oSrcFolder, 'Folder');
     $oFS =& new KTFSImportStorage(KT_DIR . "/tests/folder/move-dataset");
     $oBM =& new KTBulkImportManager($oSrcFolder, $oFS, $this->oUser);
     $this->assertNotError($oBM);
     if (PEAR::isError($oBM)) {
         return;
     }
     //$res = $oBM->import();
     //$this->assertNotError($res);
     //if(PEAR::isError($res)) return;
     $oDstFolder = KTFolderUtil::add($oTestFolder, 'testMoveDstFolder', $this->oUser);
     $this->assertNotError($oDstFolder);
     if (PEAR::isError($oDstFolder)) {
         return;
     }
     $this->assertEntity($oDstFolder, 'Folder');
     $res = KTFolderUtil::move($oSrcFolder, $oDstFolder, $this->oUser);
     $this->assertNotError($res);
     if (PEAR::isError($res)) {
         return;
     }
     $this->assertEqual($oSrcFolder->getParentID(), $oDstFolder->getID());
 }
예제 #3
0
 function tearDown()
 {
     $aOptions = array('ignore_permissions' => true);
     KTFolderUtil::delete($this->oFolder, $this->oUser, 'test case', $aOptions);
 }
예제 #4
0
 function do_rename()
 {
     $aErrorOptions = array('redirect_to' => array('', sprintf('fFolderId=%d', $this->oFolder->getId())));
     $sFolderName = KTUtil::arrayGet($_REQUEST, 'foldername');
     $aErrorOptions['defaultmessage'] = _kt("No folder name given");
     $sFolderName = $this->oValidator->validateString($sFolderName, $aErrorOptions);
     $sFolderName = $this->oValidator->validateIllegalCharacters($sFolderName, $aErrorOptions);
     $sOldFolderName = $this->oFolder->getName();
     if ($this->oFolder->getId() != 1) {
         $oParentFolder =& Folder::get($this->oFolder->getParentID());
         if (PEAR::isError($oParentFolder)) {
             $this->errorRedirectToMain(_kt('Unable to retrieve parent folder.'), $aErrorOptions['redirect_to'][1]);
             exit(0);
         }
         if (KTFolderUtil::exists($oParentFolder, $sFolderName)) {
             $this->errorRedirectToMain(_kt('A folder with that name already exists.'), $aErrorOptions['redirect_to'][1]);
             exit(0);
         }
     }
     $res = KTFolderUtil::rename($this->oFolder, $sFolderName, $this->oUser);
     if (PEAR::isError($res)) {
         $_SESSION['KTErrorMessage'][] = $res->getMessage();
         redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
         exit(0);
     } else {
         $_SESSION['KTInfoMessage'][] = sprintf(_kt('Folder "%s" renamed to "%s".'), $sOldFolderName, $sFolderName);
     }
     $this->commitTransaction();
     redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
     exit(0);
 }
예제 #5
0
 /**
  * COPY method helper for Folders
  *
  * @param  array   parameter passing array
  * @param  int     Parent Folder ID
  * @return string  HTTP status code or false
  */
 function _COPYFolder($options, $iFolderID)
 {
     /* ** Ensure that the destination path exists ** */
     if ($options['dest'] == '') {
         $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
     }
     $this->ktwebdavLog("Entering _COPYFolder. options are " . print_r($options, true), 'info', true);
     /* ** RFC 2518 Section 8.8.3. DAV compliant servers must support depth headers of '0' and 'infinity'.
        Check the requested depth. If depth is set to '0', set copyall to false. A depth of 0 indicates
        that the folder is copied without any children. If depth is set to '1', return a 400 error. ** */
     $copyAll = true;
     if ($options["depth"] != "infinity") {
         if ($options['depth'] == '0') {
             $copyAll = false;
             $this->ktwebdavLog("Depth is 0. Copy only the base folder.", 'info', true);
         } else {
             $this->ktwebdavLog("400 Bad request. Depth must be infinity or 0.", 'info', true);
             return "400 Bad request - Depth must be 'infinity' or '0'.";
         }
     }
     global $default;
     $new = true;
     /* ** Get the relevant paths. Get the basename of the destination path as the destination path name.
        Check whether the destination path refers to a folder / document. ** */
     $source_path = $options["path"];
     $dest_path = urldecode($options["dest"]);
     $sDestPathName = basename($dest_path);
     list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
     /* ** Get the source and destination folder objects.
        If the destination document is null, then the destination is an existing folder. Check overwrite.
        If overwrite is true, then check permissions and delete the folder, continue.
        If the destination document returns an id, then the destination is a document, return 409 error.
        If the destination document is false, then continue. ** */
     $oSrcFolder = Folder::get($iFolderID);
     $oDestFolder = Folder::get($iDestFolder);
     include_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php';
     if (is_null($iDestDoc)) {
         // Destination is a folder and exists
         //$sDestPathName = '';
         $this->ktwebdavLog("Destination Folder exists.", 'info', true);
         $oReplaceFolder = $oDestFolder;
         if ($options['overwrite'] != 'T') {
             $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true);
             return "412 Precondition Failed - Destination Folder exists. Overwrite needs to be TRUE.";
         }
         $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Folder.", 'info', true);
         // Check if the user has permissions to delete this folder
         $oPerm =& KTPermission::getByName('ktcore.permissions.delete');
         $oUser =& User::get($this->userID);
         if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceFolder)) {
             return "403 Forbidden - User does not have sufficient permissions";
         }
         KTFolderUtil::delete($oReplaceFolder, $oUser, 'KTWebDAV move overwrites target.');
         // Destination folder has been deleted - get new object of destination parent folder
         list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
         $oDestFolder = Folder::get($iDestFolder);
         $new = false;
     } else {
         if ($iDestDoc !== false) {
             // Destination is a document
             return "409 Conflict - Can't write a collection to a document";
         }
     }
     /* ** Get the destination folder object and the source document object.
        Check if user has permission to write to the folder.
        Copy the document. Pass parameters for the destination folder name and the depth of copy. ** */
     $oUser =& User::get($this->userID);
     $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true);
     $this->ktwebdavLog("Got an oDestFolder of " . print_r($oDestFolder, true), 'info', true);
     $this->ktwebdavLog("Got an oUser of " . print_r($oUser, true), 'info', true);
     // Check if the user has permissions to write in this folder
     $oPerm =& KTPermission::getByName('ktcore.permissions.write');
     $oUser =& User::get($this->userID);
     if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDestFolder)) {
         return "403 Forbidden - User does not have sufficient permissions";
     }
     $reason = isset($_SERVER['HTTP_REASON']) && !empty($_SERVER['HTTP_REASON']) ? $_SERVER['HTTP_REASON'] : "KTWebDAV Copy.";
     $res = KTFolderUtil::copy($oSrcFolder, $oDestFolder, $oUser, $reason, $sDestPathName, $copyAll);
     if (PEAR::isError($res)) {
         $this->ktwebdavLog("Copy on folder failed: " . $res->getMessage(), 'info', true);
         return "500 Internal Server Error - Copy on folder failed.";
     }
     if ($new) {
         $this->ktwebdavLog("201 Created", 'info', true);
         return "201 Created";
     } else {
         $this->ktwebdavLog("204 No Content", 'info', true);
         return "204 No Content";
     }
 }
예제 #6
0
 function _importfolder($oFolder, $sPath)
 {
     $oPermission = KTPermission::getByName('ktcore.permissions.addFolder');
     $aDocPaths = $this->oStorage->listDocuments($sPath);
     if (PEAR::isError($aDocPaths)) {
         return $aDocPaths;
     }
     $oDocObjects = array();
     foreach ($aDocPaths as $sDocumentPath) {
         $res = $this->_importdocument($oFolder, $sDocumentPath);
         if (PEAR::isError($res)) {
             return $res;
         }
         // Store document object
         $this->uploadedDocs[] = $res;
     }
     $aFolderPaths = $this->oStorage->listFolders($sPath);
     if (PEAR::isError($aFolderPaths)) {
         return $aFolderPaths;
     }
     $oFolderObjects = array();
     foreach ($aFolderPaths as $sFolderPath) {
         $sFolderBasePath = basename($sFolderPath);
         $sFolderBasePath = $this->is_utf8($sFolderBasePath) ? $sFolderBasePath : utf8_encode($sFolderBasePath);
         if (Folder::folderExistsName($sFolderPath, KTUtil::getId($oFolder))) {
             $_SESSION['KTErrorMessage'][] = sprintf(_kt("The folder %s is already present in %s.  Adding files into pre-existing folder."), $sFolderBasePath, $oFolder->getName());
             $aOptions = Folder::getList("parent_id = " . KTUtil::getId($oFolder) . ' AND name = "' . DBUtil::escapeSimple($sFolderBasePath) . '"');
             if (PEAR::isError($aOptions)) {
                 return $aOptions;
             }
             if (count($aOptions) != 1) {
                 return PEAR::raiseError(sprintf(_kt("Two folders named %s present in %s. Unable to decide which to use..."), $sFolderName, $oFolder->getName()));
             } else {
                 $oThisFolder = $aOptions[0];
             }
         } else {
             if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $oFolder)) {
                 $oThisFolder = KTFolderUtil::add($oFolder, $sFolderBasePath, $this->oUser, true);
             } else {
                 $oThisFolder = $oFolder;
                 if (!in_array('Your documents have been added to this folder and not the folder structure within the upload file because you do not have permission to add any folders.', $_SESSION['KTErrorMessage'])) {
                     $_SESSION['KTErrorMessage'][] = sprintf(_kt('Your documents have been added to this folder and not the folder structure within the upload file because you do not have permission to add any folders.'));
                 }
             }
         }
         if (PEAR::isError($oThisFolder)) {
             return $oThisFolder;
         }
         $res = $this->_importfolder($oThisFolder, $sFolderPath);
         if (PEAR::isError($res)) {
             return $res;
         }
         // Store folder object
         $this->uploadedFolders[] = $res;
     }
 }
예제 #7
0
 function do_removeUnit()
 {
     $oUnit =& $this->oValidator->validateUnit($_REQUEST['unit_id']);
     $bDeleteFolder = KTUtil::arrayGet($_REQUEST, 'delete_folder', false);
     $res = $oUnit->delete();
     $aOptions = array('redirect_to' => array('main'), 'message' => _kt("Could not delete this unit because it has groups assigned to it"), 'no_exception' => true);
     $this->oValidator->notError($res, $aOptions);
     if ($bDeleteFolder) {
         $iFolderId = $oUnit->getFolderId();
         $oFolder = Folder::get($iFolderId);
         if (!PEAR::isError($oFolder) && $oFolder !== false) {
             $aOptions = array('ignore_permissions' => true);
             KTFolderUtil::delete($oFolder, $this->oUser, "Unit deleted", $aOptions);
         }
     }
     $this->successRedirectToMain(_kt("Unit removed"));
 }
예제 #8
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php';
require_once KT_LIB_DIR . '/users/User.inc';
require_once KT_LIB_DIR . '/database/dbutil.inc';
error_reporting(E_ALL);
$iFolderId = 43;
$oUser = User::get(1);
$j = 'll';
$oFolder = Folder::get($iFolderId);
var_dump(KTFolderUtil::rename($oFolder, $j . '1', $oUser));
$oFolder = Folder::get($iFolderId);
var_dump(KTFolderUtil::rename($oFolder, $j . '2', $oUser));
$oFolder = Folder::get($iFolderId);
var_dump(KTFolderUtil::rename($oFolder, $j . '3', $oUser));
$oFolder = Folder::get($iFolderId);
var_dump(KTFolderUtil::rename($oFolder, $j . '4', $oUser));
예제 #9
0
 function copy($oSrcFolder, $oDestFolder, $oUser, $sReason, $sDestFolderName = NULL, $copyAll = true)
 {
     $sDestFolderName = empty($sDestFolderName) ? $oSrcFolder->getName() : $sDestFolderName;
     if (KTFolderUtil::exists($oDestFolder, $sDestFolderName)) {
         return PEAR::raiseError(_kt("Folder with the same name already exists in the new parent folder"));
     }
     //
     // FIXME the failure cleanup code here needs some serious work.
     //
     $oPerm = KTPermission::getByName('ktcore.permissions.read');
     $oBaseFolderPerm = KTPermission::getByName('ktcore.permissions.addFolder');
     if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oBaseFolderPerm, $oDestFolder)) {
         return PEAR::raiseError(_kt('You are not allowed to create folders in the destination.'));
     }
     // Check if the source folder inherits its permissions
     // Get source PO id and its parent PO id
     $iSrcPoId = $oSrcFolder->getPermissionObjectID();
     $oSrcParent = Folder::get($oSrcFolder->getParentID());
     $iSrcParentPoId = $oSrcParent->getPermissionObjectID();
     // If the folder defines its own permissions then we copy the permission object
     // If the source folder inherits permissions we must change it to inherit from the new parent folder
     $bInheritPermissions = false;
     if ($iSrcPoId == $iSrcParentPoId) {
         $bInheritPermissions = true;
     }
     $aFolderIds = array();
     // of oFolder
     $aDocuments = array();
     // of oDocument
     $aFailedDocuments = array();
     // of String
     $aFailedFolders = array();
     // of String
     $aRemainingFolders = array($oSrcFolder->getId());
     DBUtil::startTransaction();
     while (!empty($aRemainingFolders) && $copyAll) {
         $iFolderId = array_pop($aRemainingFolders);
         $oFolder = Folder::get($iFolderId);
         if (PEAR::isError($oFolder) || $oFolder == false) {
             DBUtil::rollback();
             return PEAR::raiseError(sprintf(_kt('Failure resolving child folder with id = %d.'), $iFolderId));
         }
         // don't just stop ... plough on.
         if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oFolder)) {
             $aFolderIds[] = $iFolderId;
         } else {
             $aFailedFolders[] = $oFolder->getName();
         }
         // child documents
         $aChildDocs = Document::getList(array('folder_id = ?', array($iFolderId)));
         foreach ($aChildDocs as $oDoc) {
             if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDoc)) {
                 $aDocuments[] = $oDoc;
             } else {
                 $aFailedDocuments[] = $oDoc->getName();
             }
         }
         // child folders.
         $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true));
         $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds);
     }
     if (!empty($aFailedDocuments) || !empty($aFailedFolders)) {
         $sFD = '';
         $sFF = '';
         if (!empty($aFailedDocuments)) {
             $sFD = _kt('Documents: ') . implode(', ', $aFailedDocuments) . '. ';
         }
         if (!empty($aFailedFolders)) {
             $sFF = _kt('Folders: ') . implode(', ', $aFailedFolders) . '.';
         }
         return PEAR::raiseError(_kt('You do not have permission to copy these items. ') . $sFD . $sFF);
     }
     // first we walk the tree, creating in the new location as we go.
     // essentially this is an "ok" pass.
     $oStorage =& KTStorageManagerUtil::getSingleton();
     $aFolderMap = array();
     $sTable = 'folders';
     $sGetQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ? ';
     $aParams = array($oSrcFolder->getId());
     $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams));
     unset($aRow['id']);
     $aRow['name'] = $sDestFolderName;
     $aRow['description'] = $sDestFolderName;
     $aRow['parent_id'] = $oDestFolder->getId();
     $aRow['parent_folder_ids'] = sprintf('%s,%s', $oDestFolder->getParentFolderIDs(), $oDestFolder->getId());
     $aRow['full_path'] = $oDestFolder->getFullPath() . '/' . $aRow['name'];
     $id = DBUtil::autoInsert($sTable, $aRow);
     if (PEAR::isError($id)) {
         DBUtil::rollback();
         return $id;
     }
     $sSrcFolderId = $oSrcFolder->getId();
     $aFolderMap[$sSrcFolderId]['parent_id'] = $id;
     $aFolderMap[$sSrcFolderId]['parent_folder_ids'] = $aRow['parent_folder_ids'];
     $aFolderMap[$sSrcFolderId]['full_path'] = $aRow['full_path'];
     $aFolderMap[$sSrcFolderId]['name'] = $aRow['name'];
     $oNewBaseFolder = Folder::get($id);
     $res = $oStorage->createFolder($oNewBaseFolder);
     if (PEAR::isError($res)) {
         // it doesn't exist, so rollback and raise..
         DBUtil::rollback();
         return $res;
     }
     $aRemainingFolders = Folder::getList(array('parent_id = ?', array($oSrcFolder->getId())), array('ids' => true));
     while (!empty($aRemainingFolders) && $copyAll) {
         $iFolderId = array_pop($aRemainingFolders);
         $aParams = array($iFolderId);
         $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams));
         unset($aRow['id']);
         // since we are nested, we will have solved the parent first.
         $sPrevParentId = $aRow['parent_id'];
         $aRow['parent_id'] = $aFolderMap[$aRow['parent_id']]['parent_id'];
         $aRow['parent_folder_ids'] = sprintf('%s,%s', $aFolderMap[$sPrevParentId]['parent_folder_ids'], $aRow['parent_id']);
         $aRow['full_path'] = sprintf('%s/%s', $aFolderMap[$sPrevParentId]['full_path'], $aRow['name']);
         $id = DBUtil::autoInsert($sTable, $aRow);
         if (PEAR::isError($id)) {
             $oStorage->removeFolder($oNewBaseFolder);
             DBUtil::rollback();
             return $id;
         }
         $aFolderMap[$iFolderId]['parent_id'] = $id;
         $aFolderMap[$iFolderId]['parent_folder_ids'] = $aRow['parent_folder_ids'];
         $aFolderMap[$iFolderId]['full_path'] = $aRow['full_path'];
         $aFolderMap[$iFolderId]['name'] = $aRow['name'];
         $oNewFolder = Folder::get($id);
         $res = $oStorage->createFolder($oNewFolder);
         if (PEAR::isError($res)) {
             // first delete, then rollback, then fail out.
             $oStorage->removeFolder($oNewBaseFolder);
             DBUtil::rollback();
             return $res;
         }
         $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true));
         $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds);
     }
     // now we can go ahead.
     foreach ($aDocuments as $oDocument) {
         $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]['parent_id']);
         $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder);
         if (PEAR::isError($res) || $res === false) {
             $oStorage->removeFolder($oNewBaseFolder);
             DBUtil::rollback();
             return PEAR::raiseError(_kt('Delete Aborted. Unexpected failure to copydocument: ') . $oDocument->getName() . $res->getMessage());
         }
     }
     $sComment = sprintf(_kt("Folder copied from %s to %s"), $oSrcFolder->getFullPath(), $oDestFolder->getFullPath());
     if ($sReason !== null) {
         $sComment .= sprintf(_kt(" (reason: %s)"), $sReason);
     }
     $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $oFolder->getId(), 'comment' => $sComment, 'transactionNS' => 'ktcore.transactions.copy', 'userid' => $oUser->getId(), 'ip' => Session::getClientIP()));
     // If the folder inherits its permissions then we set it to inherit from the new parent folder and update permissions
     // If it defines its own then copy the permission object over
     if ($bInheritPermissions) {
         $aOptions = array('evenifnotowner' => true);
         KTPermissionUtil::inheritPermissionObject($oNewBaseFolder, $aOptions);
     } else {
         KTPermissionUtil::copyPermissionObject($oNewBaseFolder);
     }
     // and store
     DBUtil::commit();
     return true;
 }
예제 #10
0
 function do_addFolder()
 {
     $oForm = $this->form_main();
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         $oForm->handleError();
     }
     $res = $res['results'];
     if (KTFolderUtil::exists($this->oFolder, $res['name'])) {
         $oForm->handleError(null, array('name' => _kt('A folder with that name already exists.')));
     }
     $this->startTransaction();
     $res = KTFolderUtil::add($this->oFolder, $res['name'], $this->oUser);
     $aErrorOptions['defaultmessage'] = _kt("Could not create folder in the document management system");
     $this->oValidator->notError($res, $aErrorOptions);
     $this->commitTransaction();
     controllerRedirect('browse', sprintf('fFolderId=%d', $res->getId()));
     exit(0);
 }
예제 #11
0
 function perform_action($oEntity)
 {
     if (is_a($oEntity, 'Document')) {
         return KTDocumentUtil::copy($oEntity, $this->oTargetFolder, $this->sReason);
     } else {
         if (is_a($oEntity, 'Folder')) {
             return KTFolderUtil::copy($oEntity, $this->oTargetFolder, $this->oUser, $this->sReason);
         }
     }
 }
예제 #12
0
 /**
  * This copies a folder to another location.
  *
  * <code>
  * $root = $this->ktapi->get_root_folder();
  * $folder = $root->add_folder("Test folder");
  * $new_folder = $root->add_folder("New test folder");
  * $res = $folder->copy($new_folder, "Test copy");
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @param KTAPI_Folder $ktapi_target_folder
  * @param string $reason
  */
 function copy($ktapi_target_folder, $reason = '')
 {
     assert(!is_null($ktapi_target_folder));
     assert(is_a($ktapi_target_folder, 'KTAPI_Folder'));
     $user = $this->ktapi->get_user();
     $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;
     }
     DBUtil::startTransaction();
     $result = KTFolderUtil::copy($this->folder, $target_folder, $user, $reason);
     if (PEAR::isError($result)) {
         DBUtil::rollback();
         return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result);
     }
     DBUtil::commit();
 }
예제 #13
0
$oRootFolder =& Folder::get(1);
$oUser =& User::get(1);
DBUtil::startTransaction();
$oTestFolder = KTFolderUtil::add($oRootFolder, "test-move-folder", $oUser);
if (PEAR::isError($oTestFolder)) {
    var_dump($oTestFolder);
    exit(0);
}
$oSrcFolder = KTFolderUtil::add($oTestFolder, "test-src-folder", $oUser);
if (PEAR::isError($oSrcFolder)) {
    var_dump($oSrcFolder);
    exit(0);
}
$bm =& new KTBulkImportManager($oSrcFolder, $fs, $oUser);
$res = $bm->import();
if (PEAR::isError($res)) {
    print "FAILURE\n";
    var_dump($res);
    exit(0);
}
$oDstFolder = KTFolderUtil::add($oTestFolder, "test-dst-folder", $oUser);
if (PEAR::isError($oDstFolder)) {
    var_dump($oDstFolder);
    exit(0);
}
$res = KTFolderUtil::move($oSrcFolder, $oDstFolder, $oUser);
if (PEAR::isError($res)) {
    var_dump($res);
    exit(0);
}
DBUtil::commit();
예제 #14
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php';
require_once KT_LIB_DIR . '/foldermanagement/Folder.inc';
require_once KT_LIB_DIR . '/users/User.inc';
$oParentFolder = Folder::get(1);
var_dump(KTFolderUtil::_add($oParentFolder, "testfolder", User::get(1)));
예제 #15
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php';
require_once KT_LIB_DIR . '/users/User.inc';
require_once KT_LIB_DIR . '/database/dbutil.inc';
//error_reporting(E_ALL);
$oSrc = Folder::get(3);
$oDest = Folder::get(2);
$oUser = User::get(1);
var_dump(KTFolderUtil::copy($oSrc, $oDest, $oUser, 'copy test'));
예제 #16
0
 function perform_action($oEntity)
 {
     if (is_a($oEntity, 'Document')) {
         $res = KTDocumentUtil::copy($oEntity, $this->oTargetFolder, $this->sReason, null, true);
         if (PEAR::isError($res)) {
             return $res;
         }
     } else {
         if (is_a($oEntity, 'Folder')) {
             $res = KTFolderUtil::copy($oEntity, $this->oTargetFolder, $this->oUser, $this->sReason, null, true);
             if (PEAR::isError($res)) {
                 return $res;
             }
         }
     }
     return 'CopiedDocument';
 }