function setup() { $oRootFolder =& Folder::get(1); $this->oUser = User::get(1); $sName = 'PermissionsTrest' . strftime('%Y%m%d%H%M%S'); $this->oFolder =& KTFolderUtil::add($oRootFolder, $sName, $this->oUser); }
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()); }
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()); }
/** * MKCOL method handler * * @param array parameter passing array * @return string HTTP status code or false */ function MKCOL($options) { $this->ktwebdavLog("Entering MKCOL. options are " . print_r($options, true), 'info', true); if ($this->checkSafeMode()) { global $default; if (!empty($_SERVER["CONTENT_LENGTH"])) { /* * RFC2518: 8.3.2 MKCOL status codes * * 415 (Unsupported Media Type)- The server does not support * the request type of the body. */ return "415 Unsupported media type"; } // Take Windows's escapes out $path = str_replace('\\', '', $options['path']); $res = $this->_folderOrDocument($path); list($iFolderID, $iDocumentID) = $res; if ($iDocumentID === false && $iFolderID === false) { // Couldn't find intermediary paths /* * RFC2518: 8.3.2 MKCOL status codes * * 409 (Conflict) - A collection cannot be made at the * Request-URI until one or more intermediate collections * have been created. */ $this->ktwebdavLog("409 Conflict in MKCOL", 'info', true); return "409 Conflict - Couldn't find intermediary paths"; } if (is_null($iDocumentID)) { // This means there is a folder with the given path /* * RFC2518: 8.3.2 MKCOL status codes * * 405 (Method Not Allowed) - MKCOL can only be executed on * a deleted/non-existent resource. */ $this->ktwebdavLog("405 Method not allowed - There is a folder with the given path", 'info', true); return "405 Method not allowed - There is a folder with the given path"; } if ($iDocumentID !== false) { // This means there is a document with the given path /* * RFC2518: 8.3.2 MKCOL status codes * * 405 (Method Not Allowed) - MKCOL can only be executed on * a deleted/non-existent resource. */ $this->ktwebdavLog("405 Method not allowed - There is a document with the given path", 'info', true); return "405 Method not allowed - There is a document with the given path"; } $sFolderName = basename($path); $sFolderPath = dirname($path); $dest_fspath = $default->documentRoot . "/" . $this->rootFolder . $path; $this->ktwebdavLog("Will create a physical path of " . $dest_fspath, 'info', true); $oParentFolder =& Folder::get($iFolderID); $this->ktwebdavLog("Got an oParentFolder of " . print_r($oParentFolder, true), 'info', true); // Check if the user has permissions to write in this folder $oPerm =& KTPermission::getByName('ktcore.permissions.addFolder'); $oUser =& User::get($this->userID); $this->ktwebdavLog("oPerm is " . print_r($oPerm, true), 'info', true); $this->ktwebdavLog("oUser is " . print_r($oUser, true), 'info', true); $this->ktwebdavLog("oFolder is " . print_r($oParentFolder, true), 'info', true); if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oParentFolder)) { $this->ktwebdavLog("Permission denied.", 'info', true); return "403 Forbidden - User does not have sufficient permissions"; } else { $this->ktwebdavLog("Permission granted.", 'info', true); } include_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php'; KTFolderUtil::add($oParentFolder, $sFolderName, $oUser); /* * RFC 2518: 8.3.2 MKCOL status codes * * 201 (Created) - The collection or structured resource was * created in its entirety. */ $this->ktwebdavLog("201 Created", 'info', true); return "201 Created"; } else { return "423 Locked - KTWebDAV is in SafeMode"; } }
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; } }
function do_createUnit() { $aOptions = array('redirect_to' => array('main'), 'message' => _kt('Invalid folder chosen')); $oParentFolder = $this->oValidator->validateFolder($_REQUEST['browse'], $aOptions); $aOptions = array('redirect_to' => array('addUnit', sprintf('browse=%d', $oParentFolder->getId())), 'message' => _kt('No name given')); $sName = $this->oValidator->validateString($_REQUEST['unit_name'], $aOptions); $aOptions['message'] = _kt('A unit with that name already exists.'); $sName = $this->oValidator->validateDuplicateName('Unit', $sName, $aOptions); $oFolder = KTFolderUtil::add($oParentFolder, $sName, $this->oUser); $aOptions = array('redirect_to' => array('addUnit2', sprintf('fFolderId=%d&unit_name=%s', $oParentFolder->getId(), $sName)), 'defaultmessage' => 'Error creating folder'); $this->oValidator->notError($oFolder, $aOptions); KTPermissionUtil::copyPermissionObject($oFolder); $oUnit = Unit::createFromArray(array('name' => $sName, 'folderid' => $oFolder->getId())); return $this->successRedirectToMain(_kt('Unit created')); }
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); }
/** * This adds a subfolder folder to the current folder. * * <code> * <?php * $kt = new KTAPI(); * $kt->start_session("admin", "admin"); * $root = $kt->get_root_folder(); * $root->add_folder("My New folder"); * ?> * </code> * * @author KnowledgeTree Team * @access public * @param string $foldername * @return KTAPI_Folder */ function add_folder($foldername) { $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER); if (PEAR::isError($user)) { return $user; } $foldername = KTUtil::replaceInvalidCharacters($foldername); DBUtil::startTransaction(); $result = KTFolderUtil::add($this->folder, $foldername, $user); if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result); } DBUtil::commit(); $folderid = $result->getId(); return $this->ktapi->get_folder_by_id($folderid); }
$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();