/** * function that load packages and register them in storage * @param integer * @return void **/ public static function load(int $group) : bool { $packages = Database::query(TABLE_PACKAGE_TO_GROUP, ['packageid'], '`groupid` = ' . $group); $list = []; $store = []; foreach ($packages as $package) { $list[] = $package['packageid']; } if (!empty($list)) { $packages = Database::query(TABLE_PACKAGE, ['*'], '`packageid` IN ( ' . implode(', ', $list) . ' )'); foreach ($packages as $package) { if (file_exists(DIR_PACKAGES . '/' . $package['repertory'] . '/confs.php')) { require DIR_PACKAGES . '/' . $package['repertory'] . '/confs.php'; } if (file_exists(DIR_PACKAGES . '/' . $package['repertory'] . '/models')) { Document::get(DIR_PACKAGES . '/' . $package['repertory'] . '/models'); } if (file_exists(DIR_PACKAGES . '/' . $package['repertory'] . '/controllers')) { Document::get(DIR_PACKAGES . '/' . $package['repertory'] . '/controllers'); } $store[] = $package; } } Storage::store(['packages' => $store]); return true; }
/** * Constructer - creates the document object * * @param int $iDocumentId The document Id * @return */ function DocumentPreview($iId, $type = 'document') { if ($type == 'folder') { // $type should never be a folder. $this->_oDocument = false; return; } $oDocument = Document::get($iId); if (PEAR::isError($oDocument)) { $this->_oDocument = false; return; } $this->_oDocument = $oDocument; $this->_IDocId = $iId; $this->_iMimeId = $oDocument->getMimeTypeID(); $this->imageMimeTypes = array(10, 27, 37, 38, 39, 71); }
public function testDefaults() { $a = new Document(); $this->assertEquals('bar', $a->get('a', 'bar')); $this->assertEquals('bar', $a->get('a')); $a['a'] = 'foo'; $this->assertEquals('foo', $a->get('a', 'bar')); $a['b'] = 'bar'; $a->defaults = array('b' => 'baz', 'c' => array('d' => 'foobar', 'e' => 'foobaz')); $this->assertEquals('bar', $a->get('b', 'foo')); $this->assertEquals('foobar', $a['c']['d']); // types $a['a'] = 'foo'; $this->assertEquals(12, $a->get('a', 12)); $this->assertEquals(5, $a->get('a', 5)); }
/** * Delete a version * */ function do_deleteVersion() { $iVersionId = $_REQUEST['versionid']; $sReason = $_REQUEST['reason']; $oVersion = Document::get($this->oDocument->getId(), $iVersionId); $res = KTDocumentUtil::deleteVersion($this->oDocument, $iVersionId, $sReason); if (PEAR::isError($res)) { $this->addErrorMessage($res->getMessage()); redirect(KTDocumentAction::getURL()); exit(0); } // Record the transaction $aOptions['version'] = sprintf('%d.%d', $oVersion->getMajorVersionNumber(), $oVersion->getMinorVersionNumber()); $oDocumentTransaction =& new DocumentTransaction($this->oDocument, _kt('Document version deleted'), 'ktcore.transactions.delete_version', $aOptions); $oDocumentTransaction->create(); redirect(KTDocumentAction::getURL()); }
/** * Update Document Voted Cancel * @param int $document_srl * @param Document $oDocument * @param int $point * @return object */ function updateVotedCountCancel($document_srl, $oDocument, $point) { $logged_info = Context::get('logged_info'); $args = new stdClass(); $d_args = new stdClass(); $args->document_srl = $d_args->document_srl = $document_srl; $d_args->member_srl = $logged_info->member_srl; if ($point > 0) { $args->voted_count = $oDocument->get('voted_count') - $point; $output = executeQuery('document.updateVotedCount', $args); } else { $args->blamed_count = $oDocument->get('blamed_count') - $point; $output = executeQuery('document.updateBlamedCount', $args); } $d_output = executeQuery('document.deleteDocumentVotedLog', $d_args); if (!$d_output->toBool()) { return $d_output; } //session reset $_SESSION['voted_document'][$document_srl] = false; // begin transaction $oDB = DB::getInstance(); $oDB->begin(); $obj = new stdClass(); $obj->member_srl = $oDocument->get('member_srl'); $obj->module_srl = $oDocument->get('module_srl'); $obj->document_srl = $oDocument->get('document_srl'); $obj->update_target = $point < 0 ? 'blamed_count' : 'voted_count'; $obj->point = $point; $obj->before_point = $point < 0 ? $oDocument->get('blamed_count') : $oDocument->get('voted_count'); $obj->after_point = $point < 0 ? $args->blamed_count : $args->voted_count; $obj->cancel = 1; ModuleHandler::triggerCall('document.updateVotedCountCancel', 'after', $obj); $oDB->commit(); return $output; }
function do_disableAdminMode() { $iDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId'); if ($iDocumentId) { $oDocument = Document::get($iDocumentId); if (PEAR::isError($oDocument) || $oDocument === false) { return null; } $iFolderId = $oDocument->getFolderId(); } if (!Permission::userIsSystemAdministrator() && !Permission::isUnitAdministratorForFolder($this->oUser, $iFolderId)) { $this->errorRedirectToMain(_kt('You are not an administrator')); } // log this entry $oLogEntry =& KTUserHistory::createFromArray(array('userid' => $this->oUser->getId(), 'datetime' => date('Y-m-d H:i:s', time()), 'actionnamespace' => 'ktcore.user_history.disable_admin_mode', 'comments' => 'Admin Mode disabled', 'sessionid' => $_SESSION['sessionID'])); $aOpts = array('redirect_to' => 'main', 'message' => _kt('Unable to log admin mode exit. Not de-activating admin mode.')); $this->oValidator->notError($oLogEntry, $aOpts); $_SESSION['adminmode'] = false; if ($_REQUEST['fDocumentId']) { $_SESSION['KTInfoMessage'][] = _kt('Administrator mode disabled'); redirect(KTBrowseUtil::getUrlForDocument($iDocumentId)); exit(0); } if ($_REQUEST['fFolderId']) { $this->successRedirectToMain(_kt('Administrator mode disabled'), sprintf('fFolderId=%d', $_REQUEST['fFolderId'])); } $this->successRedirectToMain(_kt('Administrator mode disabled')); }
function do_delete() { $this->oPage->setBreadcrumbDetails(_kt("link")); // check security $oPermission =& KTPermission::getByName('ktcore.permissions.write'); if (PEAR::isError($oPermission) || !KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument)) { $this->errorRedirectToMain(_kt('You do not have sufficient permissions to delete a link'), sprintf("fDocumentId=%d", $this->oDocument->getId())); exit(0); } // check validity of things $oDocumentLink = DocumentLink::get(KTUtil::arrayGet($_REQUEST, 'fDocumentLinkId')); if (PEAR::isError($oDocumentLink)) { $this->errorRedirectToMain(_kt('Invalid document link selected.')); exit(0); } $oParentDocument = Document::get(KTUtil::arrayGet($_REQUEST, 'fDocumentId')); if (PEAR::isError($oParentDocument)) { $this->errorRedirectToMain(_kt('Invalid document selected.')); exit(0); } // do deletion $this->startTransaction(); // Cannot call delete directly if no link exists. if ($oDocumentLink) { $res = $oDocumentLink->delete(); if (PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Could not delete document link'), sprintf('fDocumentId=%d', $oParentDocument->getId())); exit(0); } } else { $this->successRedirectToMain(_kt('Document link not deleted. Document link does not exists, or previously deleted.'), sprintf('fDocumentId=%d', $oParentDocument->getId())); } $this->commitTransaction(); $this->successRedirectToMain(_kt('Document link deleted'), sprintf('fDocumentId=%d', $oParentDocument->getId())); exit(0); }
function _retrieveDocumentInfo($iDocumentId) { $row_info = array('docid' => $iDocumentId); $row_info['type'] = 'document'; $row_info['document'] =& Document::get($iDocumentId); return $row_info; }
public function get() { return $this->document->get($this->var); }
function _getEventObject($sAlertType, $id) { $t = KTUtil::arrayGet($this->_eventObjectMap, $sAlertType, ''); if ($t == 'document') { $o = Document::get($id); if (PEAR::isError($o) || $o == false) { return null; } else { return $o; } } else { if ($t == 'folder') { $o = Folder::get($id); if (PEAR::isError($o) || $o == false) { return null; } else { return $o; } } else { return null; } } }
function rebuildPermissionLookups($bEmptyOnly = true) { if ($bEmptyOnly) { $sTable = KTUtil::getTableName('folders'); $sQuery = sprintf("SELECT id FROM %s WHERE permission_lookup_id IS NULL AND permission_object_id IS NOT NULL", $sTable); } else { $sTable = KTUtil::getTableName('folders'); $sQuery = sprintf("SELECT id FROM %s WHERE permission_object_id IS NOT NULL", $sTable); } $aIds = DBUtil::getResultArrayKey($sQuery, 'id'); foreach ($aIds as $iId) { $oFolder =& Folder::get($iId); KTPermissionUtil::updatePermissionLookup($oFolder); } if ($bEmptyOnly) { $sTable = KTUtil::getTableName('documents'); $sQuery = sprintf("SELECT id FROM %s WHERE permission_lookup_id IS NULL", $sTable); } else { $sTable = KTUtil::getTableName('documents'); $sQuery = sprintf("SELECT id FROM %s", $sTable); } $aIds = DBUtil::getResultArrayKey($sQuery, 'id'); foreach ($aIds as $iId) { $oDocument =& Document::get($iId); KTPermissionUtil::updatePermissionLookup($oDocument); } }
public function processQueue() { global $default; $default->log->debug('documentProcessor: starting'); // Check for lock file to ensure processor is not currently running $cacheDir = $default->cacheDirectory; $lockFile = $cacheDir . DIRECTORY_SEPARATOR . 'document_processor.lock'; if (file_exists($lockFile)) { // lock file exists, exit $default->log->debug('documentProcessor: stopping, lock file in place ' . $lockFile); return; } if ($default->enableIndexing) { // Setup indexing - load extractors, run diagnostics if ($this->indexer->preIndexingSetup() === false) { $default->log->debug('documentProcessor: stopping - indexer setup failed.'); return; } } // Get document queue $queue = $this->indexer->getDocumentsQueue($this->limit); if (empty($queue)) { $default->log->debug('documentProcessor: stopping - no documents in processing queue'); return; } // indexing starting - create lock file touch($lockFile); // Process queue foreach ($queue as $item) { // Get the document object $document = Document::get($item['document_id']); if (PEAR::isError($document)) { Indexer::unqueueDocument($docId, sprintf(_kt("indexDocuments: Cannot resolve document id %d: %s."), $docId, $document->getMessage()), 'error'); continue; } // index document if ($default->enableIndexing) { $this->indexer->processDocument($document, $item); } // loop through processors if ($this->processors !== false) { foreach ($this->processors as $processor) { $default->log->debug('documentProcessor: running processor: ' . $processor->getNamespace()); // Check document mime type against supported types if (!$this->isSupportedMimeType($item['mimetypes'], $processor->getSupportedMimeTypes())) { $default->log->debug('documentProcessor: not a supported mimetype: ' . $item['mimetypes']); continue; } // Process document $processor->setDocument($document); $processor->processDocument(); } } } // update the indexer statistics $this->indexer->updateIndexStats(); // Remove lock file to indicate processing has completed if (file_exists($lockFile)) { @unlink($lockFile); } $default->log->debug('documentProcessor: stopping'); }
/** * * parses the left over author/include tags and sets the author accordingly */ function parseAuthorAndInclude() { $newdoc=array(); $author=''; $deleted_by=''; for ($index=0, $cdoc = count($this->_document); $index < $cdoc; $index++) { $word=$this->_document[$index]; if (preg_match('/\{AUTHOR\(.+?\)\}/', $word['word'])) { $params=$this->retrieveParams($word['word']); $author=$params['author']; if (isset($params['deleted_by'])) { $deleted_by=$params['deleted_by']; } // manage double whitespace before and after $this->killDoubleWhitespaces($newdoc, $index); } elseif (preg_match('/\{AUTHOR\}/', $word['word'])) { $author=''; $deleted_by=''; $this->killDoubleWhitespaces($newdoc, $index); } elseif (preg_match('/\{INCLUDE\(.+?\)\}\{INCLUDE\}/', $word['word'])) { $params=$this->retrieveParams($word['word']); $start=''; $stop=''; if (isset($params['start'])) { $start=$params['start']; } if (isset($params['stop'])) { $stop=$params['stop']; } $subdoc=new Document($params['page'], 0, $this->_process, $this->_showpopups, $start, $stop); $newdoc=array_merge($newdoc, $subdoc->get()); } else { //normal word if ($author!='') { $word['author']=$author; } if ($deleted_by!='') { $word['deleted']=true; $word['deleted_by']=$deleted_by; } $newdoc[]=$word; } } //foreach $this->_document=$newdoc; }
function sendEmailHyperlink($aDestEmailAddress, $iDocumentID, $sDocumentName, $sComment, &$aEmailErrors) { global $default; // Get the email list as a string for the logs $sDestEmails = implode(',', $aDestEmailAddress); $oSendingUser = User::get($_SESSION['userID']); $sMessage = '<font face="arial" size="2">'; /* if ($sDestUserName) { $sMessage .= $sDestUserName . ',<br><br>'; } */ $sMessage .= sprintf(_kt("Your colleague, %s, wishes you to view the document entitled '%s'."), $oSendingUser->getName(), $sDocumentName); $sMessage .= " \n"; $sMessage .= _kt('Click on the hyperlink below to view it.') . '<br>'; // add the link to the document to the mail $sMessage .= '<br>' . generateControllerLink('viewDocument', "fDocumentID={$iDocumentID}", $sDocumentName, true); // add optional comment if (strlen($sComment) > 0) { $sMessage .= '<br><br>' . _kt('Comments') . ':<br>' . $sComment; } $sMessage .= '</font>'; $sTitle = sprintf(_kt("Link (ID %s): %s from %s"), $iDocumentID, $sDocumentName, $oSendingUser->getName()); //email the hyperlink // $sEmail = null; $sEmailFrom = null; $oConfig =& KTConfig::getSingleton(); if (!$oConfig->get('email/sendAsSystem')) { $sEmail = $oSendingUser->getEmail(); $sEmailFrom = $oSendingUser->getName(); } $oEmail = new Email($sEmail, $sEmailFrom); $res = $oEmail->send($aDestEmailAddress, $sTitle, $sMessage); if (PEAR::isError($res)) { $default->log->error($res->getMessage()); $aEmailErrors[] = $res->getMessage(); return $res; } else { if ($res === false) { $default->log->error("Error sending email ({$sTitle}) to {$sDestEmails}"); $aEmailErrors[] = "Error sending email ({$sTitle}) to {$sDestEmails}"; return PEAR::raiseError(sprintf(_kt("Error sending email (%s) to %s"), $sTitle, $sDestEmails)); } else { $default->log->info("Send email ({$sTitle}) to {$sDestEmails}"); } } // emailed link transaction // need a document to do this. $oDocument =& Document::get($iDocumentID); $oDocumentTransaction = new DocumentTransaction($oDocument, sprintf(_kt("Document link emailed to %s. "), $sDestEmails) . $sComment, 'ktcore.transactions.email_link'); if ($oDocumentTransaction->create()) { $default->log->debug("emailBL.php created email link document transaction for document ID={$iDocumentID}"); } else { $default->log->error("emailBL.php couldn't create email link document transaction for document ID={$iDocumentID}"); } }
/** * Returns a Document object for the most recently modified child */ function getLastModifiedChild() { return Document::get(self::$DB->queryValue("SELECT ID FROM Documents WHERE Parent = ? AND Visible = 'True' ORDER BY Modified DESC LIMIT 1", $this->ID)); }
function checkBackUpFile($path, $filename) { $pos = strpos($filename, '.bak'); $doc = substr($filename, 0, $pos); $oDocument = Document::get($doc); if ($oDocument instanceof Document || $oDocument instanceof DocumentProxy) { return; } $this->aFilesToRemove[] = $path; }
function getDocInfo($iDocId) { $oDocument = Document::get($iDocId); if (PEAR::isError($oDocument)) { return _kt('Document no longer exists.'); } $sName = htmlentities($oDocument->getName(), ENT_NOQUOTES, 'UTF-8'); $sLink = KTBrowseUtil::getUrlForDocument($oDocument); $aAnchorData = array(); $aAnchorData[] = $sLink; $aAnchorData[] = $sName; return $aAnchorData; }
/** * 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; }
<?php require_once "../../config/dmsDefaults.php"; require_once KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'; error_reporting(E_ALL); $oDocument = Document::get(2); var_dump(DocumentUtil::createMetadataVersion($oDocument));
function do_checkin() { global $default; $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); if (empty($document_id)) { return $this->errorRedirectToMain(_kt('You must select a document to check in first.')); } $oDocument = Document::get($document_id); if (PEAR::isError($oDocument)) { return $this->errorRedirectToMain(_kt('The document you specified appears to be invalid.')); } $this->startTransaction(); // actually do the checkin. $oDocument->setIsCheckedOut(0); $oDocument->setCheckedOutUserID(-1); if (!$oDocument->update()) { $this->rollbackTransaction(); return $this->errorRedirectToMain(_kt("Failed to force the document's checkin.")); } // checkout cancelled transaction $oDocumentTransaction =& new DocumentTransaction($oDocument, _kt('Document checked out cancelled'), 'ktcore.transactions.force_checkin'); $res = $oDocumentTransaction->create(); if (PEAR::isError($res) || $res == false) { $this->rollbackTransaction(); return $this->errorRedirectToMain(_kt("Failed to force the document's checkin.")); } $this->commitTransaction(); // FIXME do we want to do this if we can't created the document-transaction? return $this->successRedirectToMain(sprintf(_kt('Successfully forced "%s" to be checked in.'), $oDocument->getName())); }
/** * Retrieves the real document (which is a shortcut that links to the linked document) * */ function getRealDocument() { if (is_null($this->getLinkedDocumentId())) { return Document::get($this->getId()); } $document = Document::get($this->getLinkedDocumentId()); return $document->getRealDocument(); }
<?php require_once "../../config/dmsDefaults.php"; require_once KT_LIB_DIR . '/documentmanagement/Document.inc'; require_once KT_DIR . '/plugins/ktstandard/contents/WordIndexer.php'; $oDocument = Document::get(959); $oIndexer = new KTWordIndexerTrigger(); $oIndexer->setDocument($oDocument); $oIndexer->transform();
<?php require_once '../../config/dmsDefaults.php'; require_once KT_LIB_DIR . '/documentmanagement/Document.inc'; require_once KT_LIB_DIR . '/workflow/workflow.inc.php'; require_once KT_LIB_DIR . '/workflow/workflowutil.inc.php'; $oDocument =& Document::get(4); $oWorkflow =& KTWorkflow::get(1); $res = KTWorkflowUtil::startWorkflowOnDocument($oWorkflow, $oDocument); if (PEAR::isError($res)) { var_dump($res); }
/** * Add a folder to the archive * * @param unknown_type $zip * @param unknown_type $folderId * @return unknown */ public function addFolder(&$zip, $folderId) { $oFolder = Folder::get($folderId); if (PEAR::isError($oFolder)) { $this->errors[] = _kt('Folder cannot be exported, an error occurred: ') . $oFolder->getMessage(); return $oFolder; } $sFolderDocs = $oFolder->getDocumentIDs($folderId); if (PEAR::isError($sFolderDocs)) { $default->log->error('Download Queue: get document ids for folder caused an error: ' . $sFolderDocs->getMessage()); $sFolderDocs = ''; } // Add folder to zip $zip->addFolderToZip($oFolder); $aDocuments = array(); if (!empty($sFolderDocs)) { $aDocuments = explode(',', $sFolderDocs); } // Get all the folders within the current folder $sWhereClause = "parent_folder_ids like '%,{$folderId}'\n OR parent_folder_ids like '%,{$folderId},%'\n OR parent_folder_ids like '{$folderId},%'\n OR parent_id = {$folderId}"; $aFolderList = $oFolder->getList($sWhereClause); $aLinkingFolders = $this->getLinkingEntities($aFolderList); $aFolderList = array_merge($aFolderList, $aLinkingFolders); $aFolderObjects = array(); $aFolderObjects[$folderId] = $oFolder; // Export the folder structure to ensure the export of empty directories if (!empty($aFolderList)) { foreach ($aFolderList as $k => $oFolderItem) { if ($oFolderItem->isSymbolicLink()) { $oFolderItem = $oFolderItem->getLinkedFolder(); } if (Permission::userHasFolderReadPermission($oFolderItem)) { // Get documents for each folder $sFolderItemId = $oFolderItem->getID(); $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId); if (!empty($sFolderItemDocs)) { $aFolderDocs = explode(',', $sFolderItemDocs); $aDocuments = array_merge($aDocuments, $aFolderDocs); } $zip->addFolderToZip($oFolderItem); $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; } } } // Add all documents to the export if (!empty($aDocuments)) { foreach ($aDocuments as $sDocumentId) { $oDocument = Document::get($sDocumentId); if ($oDocument->isSymbolicLink()) { $oDocument->switchToLinkedCore(); } if (Permission::userHasDocumentReadPermission($oDocument)) { if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')) { $this->errors[] = $oDocument->getName() . ': ' . _kt('Document cannot be exported as it is restricted by the workflow.'); continue; } $sDocFolderId = $oDocument->getFolderID(); $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); if ($this->bNoisy) { $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array()); $oDocumentTransaction->create(); } // fire subscription alerts for the downloaded document if ($this->bNotifications) { $oSubscriptionEvent = new SubscriptionEvent(); $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder); } $zip->addDocumentToZip($oDocument, $oFolder); } } } }
<?php require_once "../../config/dmsDefaults.php"; require_once KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'; require_once KT_LIB_DIR . '/filelike/fsfilelike.inc.php'; $sLocalname = KT_DIR . "/tests/document/dataset1/critique-of-pure-reason.txt"; $sFilename = tempnam("/tmp", "kt_tests_document_add"); copy($sLocalname, $sFilename); $oDocument =& Document::get(6); if (PEAR::isError($oDocument)) { print "FAILURE\n"; var_dump($oDocument); } $res = KTDocumentUtil::updateTransactionText($oDocument); if (PEAR::isError($res)) { print "FAILURE\n"; var_dump($res); exit(0); }
function do_finish_restore() { $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); $aDocuments = array(); foreach ($selected_docs as $doc_id) { $oDoc =& Document::get($doc_id); if (PEAR::isError($oDoc) || $oDoc === false) { $this->errorRedirectToMain(_kt('Invalid document id specified. Aborting restore')); } else { if ($oDoc->getStatusId() != DELETED) { $this->errorRedirectToMain(sprintf(_kt('%s is not a deleted document. Aborting restore'), $oDoc->getName())); } } $aDocuments[] = $oDoc; } $this->startTransaction(); $aErrorDocuments = array(); $aSuccessDocuments = array(); $oStorage =& KTStorageManagerUtil::getSingleton(); foreach ($aDocuments as $oDoc) { $oFolder = Folder::get($oDoc->getRestoreFolderId()); // move to root if parent no longer exists. if (PEAR::isError($oFolder)) { $oDoc->setFolderId(1); $oFolder = Folder::get(1); } else { $oDoc->setFolderId($oDoc->getRestoreFolderId()); } if ($oStorage->restore($oDoc)) { $oDoc = Document::get($oDoc->getId()); // storage path has changed for most recent object... $oDoc->setStatusId(LIVE); $oDoc->setPermissionObjectId($oFolder->getPermissionObjectId()); $res = $oDoc->update(); if (PEAR::isError($res) || $res == false) { $aErrorDocuments[] = $oDoc->getName(); continue; // skip transactions, etc. } $res = KTPermissionUtil::updatePermissionLookup($oDoc); if (PEAR::isError($res)) { $aErrorDocuments[] = $oDoc->getName(); continue; // skip transactions, etc. } // create a doc-transaction. // FIXME does this warrant a transaction-type? $oTransaction = new DocumentTransaction($oDoc, sprintf(_kt("Restored from deleted state by %s"), $this->oUser->getName()), 'ktcore.transactions.update'); if (!$oTransaction->create()) { // do nothing? the state of physicaldocumentmanager... } $aSuccessDocuments[] = $oDoc->getName(); } else { $aErrorDocuments[] = $oDoc->getName(); } } $this->commitTransaction(); $msg = sprintf(_kt('%d documents restored.'), count($aSuccessDocuments)); if (count($aErrorDocuments) != 0) { $msg .= _kt('Failed to restore') . ': ' . join(', ', $aErrorDocuments); } $this->successRedirectToMain($msg); }
public function updateDocumentIndex($docId, $text) { $config = KTConfig::getSingleton(); $tempPath = $config->get("urls/tmpDirectory"); $tempFile = tempnam($tempPath, 'ud_'); file_put_contents($tempFile, $text); $document = Document::get($docId); $title = $document->getDescription(); $version = $document->getVersion(); $result = $this->indexDocument($docId, $tempFile, $title, $version); if (file_exists($tempFile)) { unlink($tempFile); } return $result; }
/** * Create a new document instance by ID, and load it with values requested * from the API. * * @param string $id The document ID. * * @return Box\View\Document A document instance using data from the API. * @throws Box\View\BoxViewException */ public function getDocument($id) { return Document::get($this, $id); }
/** * canCopyMoveRenameDocument() helper * checks if document is checked out; if not, returns true * if checked out, cheks if checked out by same user; if yes, returns true; * else returns false * * @return bool true or false */ function canCopyMoveRenameDocument($iDocumentID) { $this->ktwebdavLog("Entering canCopyMoveRenameDocument ", 'info', true); $oDocument =& Document::get($iDocumentID); if (is_null($oDocument) || $oDocument === false || PEAR::isError($oDocument)) { $this->ktwebdavLog("Document invalid " . print_r($oDocument, true), 'info', true); return false; } if ($oDocument->getIsCheckedOut()) { $info = array(); $info["props"][] = $this->mkprop($sNameSpace, 'CheckedOut', $oDocument->getCheckedOutUserID()); //$this->ktwebdavLog("getIsCheckedOut ". print_r($info,true), 'info', true); $oCOUser = User::get($oDocument->getCheckedOutUserID()); if (PEAR::isError($oCOUser) || is_null($oCOUser) || $oCOUser === false) { $couser_id = '0'; } else { $couser_id = $oCOUser->getID(); } //$this->ktwebdavLog("getCheckedOutUserID " .$couser_id, 'info', true); $oUser =& User::get($this->userID); //$this->ktwebdavLog("this UserID " .$oUser->getID(), 'info', true); if (PEAR::isError($oUser) || is_null($oUser) || $oUser === false) { $this->ktwebdavLog("User invalid " . print_r($oUser, true), 'info', true); return false; } else { $ouser_id = $oUser->getID(); } //$this->ktwebdavLog("that UserID " .$oCOUser->getID(), 'info', true); if ($couser_id != $ouser_id) { $this->ktwebdavLog("Document checked out by another user {$couser_id} != {$ouser_id}", 'info', true); return false; } else { $this->ktwebdavLog("Document checked out by this user", 'info', true); return true; } } else { //not checked out $this->ktwebdavLog("Document not checked out by any user", 'info', true); return true; } }
function do_viewComparison() { $document_data = array(); $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); if ($document_id === null) { $this->oPage->addError(sprintf(_kt("No document was requested. Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl())); return $this->do_error(); } $document_data['document_id'] = $document_id; $base_version = KTUtil::arrayGet($_REQUEST, 'fBaseVersion'); // try get the document. $oDocument =& Document::get($document_id, $base_version); if (PEAR::isError($oDocument)) { $this->oPage->addError(sprintf(_kt("The base document you attempted to retrieve is invalid. Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl())); return $this->do_error(); } if (!Permission::userHasDocumentReadPermission($oDocument)) { // FIXME inconsistent. $this->oPage->addError(_kt('You are not allowed to view this document')); return $this->permissionDenied(); } $this->oDocument =& $oDocument; $this->oPage->setSecondaryTitle($oDocument->getName()); $aOptions = array('documentaction' => 'viewDocument', 'folderaction' => 'browse'); $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions)); $this->oPage->setBreadcrumbDetails(_kt('compare versions')); $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion'); if ($comparison_version === null) { $this->oPage->addError(sprintf(_kt("No comparison version was requested. Please <a href=\"%s\">select a version</a>."), KTUtil::addQueryStringSelf('action=history&fDocumentId=' . $document_id))); return $this->do_error(); } $oComparison =& Document::get($oDocument->getId(), $comparison_version); if (PEAR::isError($oComparison)) { $this->errorRedirectToMain(_kt('Invalid document to compare against.')); } $comparison_data = array(); $comparison_data['document_id'] = $oComparison->getId(); $document_data['document'] = $oDocument; $comparison_data['document'] = $oComparison; $document_data['document_type'] =& DocumentType::get($oDocument->getDocumentTypeID()); $comparison_data['document_type'] =& DocumentType::get($oComparison->getDocumentTypeID()); // follow twice: once for normal, once for comparison. $is_valid_doctype = true; if (PEAR::isError($document_data['document_type'])) { $this->oPage->addError(_kt('The document you requested has an invalid <strong>document type</strong>. Unfortunately, this means that we cannot effectively display it.')); $is_valid_doctype = false; } // we want to grab all the md for this doc, since its faster that way. $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($base_version))); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } $document_data['field_values'] = $field_values; $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($comparison_version))); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } $comparison_data['field_values'] = $field_values; // Fieldset generation. // // we need to create a set of FieldsetDisplay objects // that adapt the Fieldsets associated with this lot // to the view (i.e. ZX3). Unfortunately, we don't have // any of the plumbing to do it, so we handle this here. $fieldsets = array(); // we always have a generic. array_push($fieldsets, new GenericFieldsetDisplay()); // FIXME can we key this on fieldset namespace? or can we have duplicates? // now we get the other fieldsets, IF there is a valid doctype. if ($is_valid_doctype) { // these are the _actual_ fieldsets. $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton(); // and the generics $activesets = KTFieldset::getGenericFieldsets(); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } $activesets = KTFieldset::getForDocumentType($oDocument->getDocumentTypeID()); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } } // FIXME handle ad-hoc fieldsets. $this->addPortlets(); $oTemplate = $this->oValidator->validateTemplate('ktcore/document/compare'); $aTemplateData = array('context' => $this, 'document_id' => $document_id, 'document' => $oDocument, 'document_data' => $document_data, 'comparison_data' => $comparison_data, 'comparison_document' => $oComparison, 'fieldsets' => $fieldsets); //var_dump($aTemplateData['comparison_data']); return $oTemplate->render($aTemplateData); }