/** * Sets the status of the document to 'archived'. * * @author KnowledgeTree Team * @access public * @param string $reason The reason for archiving the document * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure */ function archive($reason) { $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } DBUtil::startTransaction(); $res = KTDocumentUtil::archive($this->document, $reason); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res); } DBUtil::commit(); /* list($permission, $user) = $perm_and_user; DBUtil::startTransaction(); $this->document->setStatusID(ARCHIVED); $res = $this->document->update(); if (($res === false) || PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res); } $oDocumentTransaction = new DocumentTransaction($this->document, sprintf(_kt('Document archived: %s'), $reason), 'ktcore.transactions.update'); $oDocumentTransaction->create(); DBUtil::commit(); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('archive', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger; $aInfo = array( 'document' => $this->document, ); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); } */ }
function do_archive() { $oForm = $this->form_main(); $res = $oForm->validate(); $data = $res['results']; if (!empty($res['errors'])) { return $oForm->handleError(); } $sReason = $data['reason']; $res = KTDocumentUtil::archive($this->oDocument, $sReason); if (PEAR::isError($res)) { $_SESSION['KTErrorMessage'][] = $res->getMessage(); controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); } $_SESSION['KTInfoMessage'][] = _kt('Document archived.'); controllerRedirect('browse', 'fFolderId=' . $this->oDocument->getFolderID()); exit(0); }
function perform_action($oEntity) { if (is_a($oEntity, 'Document')) { $res = KTDocumentUtil::archive($oEntity, $this->sReason); if (PEAR::isError($res)) { return $res; } return true; } else { 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(); // Get all the folders within the folder $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 folders and get documents if (!empty($aChildFolders)) { foreach ($aChildFolders as $oChild) { $sChildId = $oChild->getID(); $sChildDocs = $oChild->getDocumentIDs($sChildId); if (PEAR::isError($res)) { return false; } if (!empty($sChildDocs)) { $aChildDocs = explode(',', $sChildDocs); $aDocuments = array_merge($aDocuments, $aChildDocs); } } } // Archive all documents if (!empty($aDocuments)) { foreach ($aDocuments as $sDocumentId) { $oDocument = Document::get($sDocumentId); if (PEAR::isError($oDocument)) { return $oDocument; } $res = KTDocumentUtil::archive($oDocument, $this->sReason); if (PEAR::isError($res)) { return $res; } } } else { return PEAR::raiseError(_kt('The folder contains no documents to archive.')); } return true; } } }