/**
  * Test the bulk archive functionality
  */
 function testArchive()
 {
     // Create documents
     $doc1 = $this->createDocument('Test Doc One', 'testdoc1.txt');
     $doc2 = $this->createDocument('Test Doc Two', 'testdoc2.txt');
     $doc3 = $this->createDocument('Test Doc Three', 'testdoc3.txt');
     $folder1 = $this->root->add_folder("New test folder");
     $this->assertNotError($newFolder);
     if (PEAR::isError($newFolder)) {
         return;
     }
     $doc4 = $this->createDocument('Test Doc Four', 'testdoc4.txt', $folder1);
     $aItems = array($doc1, $doc2, $doc3, $folder1);
     // Archive documents and folder
     $res = $this->bulk->archive($aItems, 'Testing bulk archive');
     $this->assertTrue(empty($res));
     $document1 = $doc1->getObject();
     $this->assertTrue($document1->getStatusID() == 4);
     // refresh the doc4 document object to reflect changes
     $doc4 = KTAPI_Document::get($this->ktapi, $doc4->get_documentid());
     $document4 = $doc4->getObject();
     $this->assertTrue($document4->getStatusID() == 4);
     // Restore for deletion
     $doc1->restore();
     $doc2->restore();
     $doc3->restore();
     $doc4->restore();
     // Delete and expunge documents and folder
     $this->deleteDocument($doc1);
     $this->deleteDocument($doc2);
     $this->deleteDocument($doc3);
     $this->deleteDocument($doc4);
     $folder1->delete('Testing bulk archive');
 }
Example #2
0
 /**
  * Method to test the document subscriptions for webservices
  *
  */
 public function testSubscriptions_KTAPI()
 {
     $this->ktapi->session_logout();
     $this->session = $this->ktapi->start_session('admin', 'admin');
     $randomFile = APIDocumentHelper::createRandomFile();
     $this->assertTrue(is_file($randomFile));
     $document = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
     $this->assertIsA($document, 'KTAPI_Document');
     $this->assertNoErrors();
     @unlink($randomFile);
     $documentid = $document->get_documentid();
     // case no subscription
     $response = $this->ktapi->is_document_subscribed($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['subscribed'], 'FALSE');
     $this->assertNoErrors();
     //case add subscription
     $response = $this->ktapi->subscribe_to_document($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     //case add DUPLICATE subscription
     $response = $this->ktapi->subscribe_to_document($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     // case subscription exists
     $response = $this->ktapi->is_document_subscribed($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['subscribed'], 'TRUE');
     $this->assertNoErrors();
     //case delete subscription
     $response = $this->ktapi->unsubscribe_from_document($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     //case delete NOT EXISTANT subscription
     $response = $this->ktapi->unsubscribe_from_document($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     $document->delete('Test');
     $document->expunge();
 }
Example #3
0
 public function getPermissions()
 {
     return KTAPI_Folder::get_permission_string($this->Folder);
 }
 /**
  * This is used to get a document based on document id.
  *
  * @author KnowledgeTree Team
  * @static
  * @access public
  * @param KTAPI $ktapi The ktapi object
  * @param int $documentid The document id
  * @return KTAPI_Document The document object
  */
 function &get(&$ktapi, $documentid)
 {
     assert(!is_null($ktapi));
     assert(is_a($ktapi, 'KTAPI'));
     assert(is_numeric($documentid));
     $documentid += 0;
     $document =& Document::get($documentid);
     if (is_null($document) || PEAR::isError($document)) {
         return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID, $document);
     }
     $user = $ktapi->can_user_access_object_requiring_permission($document, KTAPI_PERMISSION_READ);
     if (is_null($user) || PEAR::isError($user)) {
         return $user;
     }
     $folderid = $document->getParentID();
     if (!is_null($folderid)) {
         $ktapi_folder =& KTAPI_Folder::get($ktapi, $folderid);
     } else {
         $ktapi_folder = null;
     }
     // We don't do any checks on this folder as it could possibly be deleted, and is not required right now.
     return new KTAPI_Document($ktapi, $ktapi_folder, $document);
 }
 /**
  * Recursive function to perform a given action on a folder and contained documents.
  *
  * @author KnowledgeTree Team
  * @access private
  * @param KTAPI_Folder $folder The instance of the folder object being archived
  * @param string $reason The reason for archiving
  * @param string $action The action to be performed on the documents
  * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
  */
 private function recurseFolder($folder, $reason = '', $action = 'archive')
 {
     if (!$folder instanceof KTAPI_Folder) {
         return PEAR::raiseError('Object is not an instance of KTAPI_Folder');
     }
     // Archive contained documents
     $listDocs = $folder->get_listing(1, 'D');
     if (!empty($listDocs)) {
         foreach ($listDocs as $docInfo) {
             $doc = $this->ktapi->get_document_by_id($docInfo['id']);
             switch ($action) {
                 case 'archive':
                     $res = $doc->archive($reason);
                     break;
                 case 'checkout':
                     $res = $doc->checkout($reason);
                     break;
                 case 'undo_checkout':
                     $res = $doc->undo_checkout($reason);
                     break;
                 case 'immute':
                     $res = $doc->immute();
                     break;
             }
             if (PEAR::isError($res)) {
                 return $res;
             }
         }
     }
     // Archive contained folders
     $listFolders = $folder->get_listing(1, 'F');
     if (!empty($listFolders)) {
         foreach ($listFolders as $folderItem) {
             $res = $this->archiveFolder($folderItem, $reason);
             if (PEAR::isError($res)) {
                 return $res;
             }
         }
     }
     return;
 }
 /**
  * Get's a folder listing, recursing to the maximum depth.
  * Derived from the get_listing function.
  *
  * <code>
  * $root = $this->ktapi->get_root_folder();
  * $listing = $root->get_full_listing();
  * foreach($listing as $val) {
  * 	if($val['item_type'] == 'F') {
  *   // It's a folder
  *   echo $val['title'];
  *  }
  * }
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $what
  * @return array
  */
 function get_full_listing($what = 'DFS')
 {
     $what = strtoupper($what);
     $read_permission =& KTPermission::getByName(KTAPI_PERMISSION_READ);
     $folder_permission =& KTPermission::getByName(KTAPI_PERMISSION_VIEW_FOLDER);
     $config = KTConfig::getSingleton();
     $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
     $user = $this->ktapi->get_user();
     $contents = array();
     if (strpos($what, 'F') !== false) {
         $folder_children = Folder::getList(array('parent_id = ?', $this->folderid));
         foreach ($folder_children as $folder) {
             if (KTPermissionUtil::userHasPermissionOnItem($user, $folder_permission, $folder) || KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $folder)) {
                 $sub_folder =& $this->ktapi->get_folder_by_id($folder->getId());
                 if (!PEAR::isError($sub_folder)) {
                     $items = $sub_folder->get_full_listing($what);
                 } else {
                     $items = array();
                 }
                 $creator = $this->_resolve_user($folder->getCreatorID());
                 if ($wsversion >= 2) {
                     $array = array('id' => (int) $folder->getId(), 'item_type' => 'F', 'custom_document_no' => 'n/a', 'oem_document_no' => 'n/a', 'title' => $folder->getName(), 'document_type' => 'n/a', 'filename' => $folder->getName(), 'filesize' => 'n/a', 'created_by' => is_null($creator) ? 'n/a' : $creator->getName(), 'created_date' => 'n/a', 'checked_out_by' => 'n/a', 'checked_out_date' => 'n/a', 'modified_by' => 'n/a', 'modified_date' => 'n/a', 'owned_by' => 'n/a', 'version' => 'n/a', 'is_immutable' => 'n/a', 'permissions' => KTAPI_Folder::get_permission_string($folder), 'workflow' => 'n/a', 'workflow_state' => 'n/a', 'mime_type' => 'folder', 'mime_icon_path' => 'folder', 'mime_display' => 'Folder', 'storage_path' => 'n/a');
                     if ($wsversion >= 3) {
                         $array['linked_folder_id'] = $folder->getLinkedFolderId();
                         if ($folder->isSymbolicLink()) {
                             $array['item_type'] = "S";
                         }
                     }
                     $array['items'] = $items;
                     if ($wsversion < 3 || strpos($what, 'F') !== false && !$folder->isSymbolicLink() || $folder->isSymbolicLink() && strpos($what, 'S') !== false) {
                         $contents[] = $array;
                     }
                 } else {
                     $contents[] = array('id' => (int) $folder->getId(), 'item_type' => 'F', 'title' => $folder->getName(), 'creator' => is_null($creator) ? 'n/a' : $creator->getName(), 'checkedoutby' => 'n/a', 'modifiedby' => 'n/a', 'filename' => $folder->getName(), 'size' => 'n/a', 'major_version' => 'n/a', 'minor_version' => 'n/a', 'storage_path' => 'n/a', 'mime_type' => 'folder', 'mime_icon_path' => 'folder', 'mime_display' => 'Folder', 'items' => $items, 'workflow' => 'n/a', 'workflow_state' => 'n/a');
                 }
             }
         }
     }
     if (strpos($what, 'D') !== false) {
         $document_children = Document::getList(array('folder_id = ? AND status_id = 1', $this->folderid));
         // I hate that KT doesn't cache things nicely...
         $mime_cache = array();
         foreach ($document_children as $document) {
             if (KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document)) {
                 $created_by = $this->_resolve_user($document->getCreatorID());
                 $created_date = $document->getCreatedDateTime();
                 if (empty($created_date)) {
                     $created_date = 'n/a';
                 }
                 $checked_out_by = $this->_resolve_user($document->getCheckedOutUserID());
                 $checked_out_date = $document->getCheckedOutDate();
                 if (empty($checked_out_date)) {
                     $checked_out_date = 'n/a';
                 }
                 $modified_by = $this->_resolve_user($document->getCreatorID());
                 $modified_date = $document->getLastModifiedDate();
                 if (empty($modified_date)) {
                     $modified_date = 'n/a';
                 }
                 $owned_by = $this->_resolve_user($document->getOwnerID());
                 $mimetypeid = $document->getMimeTypeID();
                 if (!array_key_exists($mimetypeid, $mime_cache)) {
                     $type = KTMime::getMimeTypeName($mimetypeid);
                     $icon = KTMime::getIconPath($mimetypeid);
                     $display = KTMime::getFriendlyNameForString($type);
                     $mime_cache[$mimetypeid] = array('type' => $type, 'icon' => $icon, 'display' => $display);
                 }
                 $mimeinfo = $mime_cache[$mimetypeid];
                 $workflow = 'n/a';
                 $state = 'n/a';
                 $wf = KTWorkflowUtil::getWorkflowForDocument($document);
                 if (!is_null($wf) && !PEAR::isError($wf)) {
                     $workflow = $wf->getHumanName();
                     $ws = KTWorkflowUtil::getWorkflowStateForDocument($document);
                     if (!is_null($ws) && !PEAR::isError($ws)) {
                         $state = $ws->getHumanName();
                     }
                 }
                 if ($wsversion >= 2) {
                     $docTypeId = $document->getDocumentTypeID();
                     $documentType = DocumentType::get($docTypeId);
                     $oemDocumentNo = $document->getOemNo();
                     if (empty($oemDocumentNo)) {
                         $oemDocumentNo = 'n/a';
                     }
                     $array = array('id' => (int) $document->getId(), 'item_type' => 'D', 'custom_document_no' => 'n/a', 'oem_document_no' => $oemDocumentNo, 'title' => $document->getName(), 'document_type' => $documentType->getName(), 'filename' => $document->getFileName(), 'filesize' => $document->getFileSize(), 'created_by' => is_null($created_by) ? 'n/a' : $created_by->getName(), 'created_date' => $created_date, 'checked_out_by' => is_null($checked_out_by) ? 'n/a' : $checked_out_by->getName(), 'checked_out_date' => $checked_out_date, 'modified_by' => is_null($modified_by) ? 'n/a' : $modified_by->getName(), 'modified_date' => $modified_date, 'owned_by' => is_null($owned_by) ? 'n/a' : $owned_by->getName(), 'version' => $document->getMajorVersionNumber() . '.' . $document->getMinorVersionNumber(), 'content_id' => $document->getContentVersionId(), 'is_immutable' => $document->getImmutable() ? 'true' : 'false', 'permissions' => KTAPI_Document::get_permission_string($document), 'workflow' => $workflow, 'workflow_state' => $state, 'mime_type' => $mime_cache[$mimetypeid]['type'], 'mime_icon_path' => $mime_cache[$mimetypeid]['icon'], 'mime_display' => $mime_cache[$mimetypeid]['display'], 'storage_path' => $document->getStoragePath());
                     if ($wsversion >= 3) {
                         $document->switchToRealCore();
                         $array['linked_document_id'] = $document->getLinkedDocumentId();
                         $document->switchToLinkedCore();
                         if ($document->isSymbolicLink()) {
                             $array['item_type'] = "S";
                         }
                     }
                     $array['items'] = array();
                     if ($wsversion < 3 || strpos($what, 'D') !== false && !$document->isSymbolicLink() || $document->isSymbolicLink() && strpos($what, 'S') !== false) {
                         $contents[] = $array;
                     }
                 } else {
                     $contents[] = array('id' => (int) $document->getId(), 'item_type' => 'D', 'title' => $document->getName(), 'creator' => is_null($created_by) ? 'n/a' : $created_by->getName(), 'checkedoutby' => is_null($checked_out_by) ? 'n/a' : $checked_out_by->getName(), 'modifiedby' => is_null($modified_by) ? 'n/a' : $modified_by->getName(), 'filename' => $document->getFileName(), 'size' => $document->getFileSize(), 'major_version' => $document->getMajorVersionNumber(), 'minor_version' => $document->getMinorVersionNumber(), 'storage_path' => $document->getStoragePath(), 'mime_type' => $mime_cache[$mimetypeid]['type'], 'mime_icon_path' => $mime_cache[$mimetypeid]['icon'], 'mime_display' => $mime_cache[$mimetypeid]['display'], 'items' => array(), 'workflow' => $workflow, 'workflow_state' => $state);
                 }
             }
         }
     }
     return $contents;
 }
Example #7
0
 /**
  * Gets the the folder object based on the folder name
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $foldername The folder name
  * @return object $folder The KTAPI_Folder object
  */
 public function &get_folder_by_name($foldername, $parentId = 1)
 {
     $folder = KTAPI_Folder::_get_folder_by_name($this, $foldername, $parentId);
     return $folder;
 }
Example #8
0
 /**
  * Gets the the folder object based on the folder name
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $foldername The folder name
  * @return object $folder The KTAPI_Folder object
  */
 public function &get_folder_by_name($foldername)
 {
     $folder = KTAPI_Folder::_get_folder_by_name($this, $foldername, 1);
     return $folder;
 }