コード例 #1
0
 function update($bPathMove = false)
 {
     //var_dump($this); exit(0);
     $res = parent::update();
     if ($res === true && $bPathMove === true) {
         KTPermissionUtil::updatePermissionLookup($this);
     }
     return $res;
 }
コード例 #2
0
 function do_reown()
 {
     $oForm = $this->form_owner();
     $res = $oForm->validate();
     $data = $res['results'];
     $errors = $res['errors'];
     if (!empty($errors)) {
         return $oForm->handleError();
     }
     $oUser = $data['user'];
     $this->startTransaction();
     $this->oDocument->setOwnerID($oUser->getId());
     $res = $this->oDocument->update();
     if (PEAR::isError($res)) {
         $this->errorRedirectToMain(sprintf(_kt('Failed to update document: %s'), $res->getMessage()), sprintf('fDocumentId=%d', $this->oDocument->getId()));
     }
     $res = KTPermissionUtil::updatePermissionLookup($this->oDocument);
     if (PEAR::isError($res)) {
         $this->errorRedirectToMain(sprintf(_kt('Failed to update document: %s'), $res->getMessage()), sprintf('fDocumentId=%d', $this->oDocument->getId()));
     }
     $this->successRedirectToMain(_kt('Ownership changed.'), sprintf('fDocumentId=%d', $this->oDocument->getId()));
 }
コード例 #3
0
 function renegeratePermissionsForRole($iRoleId, $iFolderId)
 {
     $iStartFolderId = $iFolderId;
     /*
      * 1. find all folders & documents "below" this one which use the role
      *    definition _active_ (not necessarily present) at this point.
      * 2. tell permissionutil to regen their permissions.
      *
      * The find algorithm is:
      *
      *  folder_queue <- (iStartFolderId)
      *  while folder_queue is not empty:
      *     active_folder =
      *     for each folder in the active_folder:
      *         find folders in _this_ folder without a role-allocation on the iRoleId
      *            add them to the folder_queue
      *         update the folder's permissions.
      *         find documents in this folder:
      *            update their permissions.
      */
     $sRoleAllocTable = KTUtil::getTableName('role_allocations');
     $sFolderTable = KTUtil::getTableName('folders');
     $sQuery = sprintf('SELECT f.id as id FROM %s AS f LEFT JOIN %s AS ra ON (f.id = ra.folder_id) WHERE ra.id IS NULL AND f.parent_id = ?', $sFolderTable, $sRoleAllocTable);
     $folder_queue = array($iStartFolderId);
     while (!empty($folder_queue)) {
         $active_folder = array_pop($folder_queue);
         $aParams = array($active_folder);
         $aNewFolders = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
         if (PEAR::isError($aNewFolders)) {
             //$this->errorRedirectToMain(_kt('Failure to generate folderlisting.'));
             echo _kt('Failure to generate folderlisting.');
         }
         $folder_queue = kt_array_merge($folder_queue, (array) $aNewFolders);
         // push.
         // update the folder.
         $oFolder =& Folder::get($active_folder);
         if (PEAR::isError($oFolder) || $oFolder == false) {
             //$this->errorRedirectToMain(_kt('Unable to locate folder: ') . $active_folder);
             echo _kt('Unable to locate folder: ') . $active_folder;
         }
         KTPermissionUtil::updatePermissionLookup($oFolder);
         $aDocList =& Document::getList(array('folder_id = ?', $active_folder));
         if (PEAR::isError($aDocList) || $aDocList === false) {
             //$this->errorRedirectToMain(sprintf(_kt('Unable to get documents in folder %s: %s'), $active_folder, $aDocList->getMessage()));
             echo _kt('Unable to get documents in folder ') . $active_folder;
         }
         foreach ($aDocList as $oDoc) {
             if (!PEAR::isError($oDoc)) {
                 KTPermissionUtil::updatePermissionLookup($oDoc);
             }
         }
     }
 }
コード例 #4
0
ファイル: edit.php プロジェクト: sfsergey/knowledgetree
 function do_trytype()
 {
     $oForm = $this->form_changetype();
     $res = $oForm->validate();
     $data = $res['results'];
     $errors = $res['errors'];
     if (!empty($errors)) {
         $oForm->handleError();
     }
     $document_type = $data['type'];
     $doctypeid = $document_type->getId();
     // Get the current document type, fieldsets and metadata
     $iOldDocTypeID = $this->oDocument->getDocumentTypeID();
     $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $iOldDocTypeID);
     $mdlist = DocumentFieldLink::getByDocument($this->oDocument);
     $field_values = array();
     foreach ($mdlist as $oFieldLink) {
         $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
     }
     DBUtil::startTransaction();
     // Update the document with the new document type id
     $this->oDocument->startNewMetadataVersion($this->oUser);
     $this->oDocument->setDocumentTypeId($doctypeid);
     $res = $this->oDocument->update();
     if (PEAR::isError($res)) {
         DBUtil::rollback();
         return $res;
     }
     // Ensure all values for fieldsets common to both document types are retained
     $fs_ids = array();
     $doctype_fieldsets = KTFieldSet::getForDocumentType($doctypeid);
     foreach ($doctype_fieldsets as $fieldset) {
         $fs_ids[] = $fieldset->getId();
     }
     $MDPack = array();
     foreach ($fieldsets as $oFieldset) {
         if ($oFieldset->getIsGeneric() || in_array($oFieldset->getId(), $fs_ids)) {
             $fields = $oFieldset->getFields();
             foreach ($fields as $oField) {
                 $val = isset($field_values[$oField->getId()]) ? $field_values[$oField->getId()] : '';
                 if (!empty($val)) {
                     $MDPack[] = array($oField, $val);
                 }
             }
         }
     }
     $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack, array('novalidate' => true));
     if (PEAR::isError($core_res)) {
         DBUtil::rollback();
         return $core_res;
     }
     DBUtil::commit();
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array("document" => $this->oDocument, "aOptions" => $MDPack);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
     }
     // Check if there are any dynamic conditions / permissions that need to be updated on the document
     // If there are dynamic conditions then update the permissions on the document
     // The dynamic condition test fails unless the changes exists in the DB therefore update permissions after committing the transaction.
     $iPermissionObjectId = $this->oDocument->getPermissionObjectID();
     $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId);
     if (!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)) {
         $res = KTPermissionUtil::updatePermissionLookup($this->oDocument);
     }
     $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName()));
 }
コード例 #5
0
 /**
  * Restores a deleted document
  *
  * @author KnowledgeTree Team
  * @access public
  */
 function restore()
 {
     DBUtil::startTransaction();
     $storage =& KTStorageManagerUtil::getSingleton();
     $folder = Folder::get($this->document->getRestoreFolderId());
     if (PEAR::isError($folder)) {
         $this->document->setFolderId(1);
         $folder = Folder::get(1);
     } else {
         $this->document->setFolderId($this->document->getRestoreFolderId());
     }
     $storage->restore($this->document);
     $this->document->setStatusId(LIVE);
     $this->document->setPermissionObjectId($folder->getPermissionObjectId());
     $res = $this->document->update();
     $res = KTPermissionUtil::updatePermissionLookup($this->document);
     $user = $this->ktapi->get_user();
     $oTransaction = new DocumentTransaction($this->document, 'Restored from deleted state by ' . $user->getName(), 'ktcore.transactions.update');
     $oTransaction->create();
     DBUtil::commit();
 }
コード例 #6
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);
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
 /**
  * Performs a workflow transition on a document, changing it from
  * one workflow state to another, with potential side effects (user
  * scripts, and so forth).
  *
  * This function currently assumes that the user in question is
  * allowed to perform the transition and that all the guard
  * functionality on the transition has passed.
  */
 function performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments)
 {
     $oWorkflow =& KTWorkflow::getByDocument($oDocument);
     if (empty($oWorkflow)) {
         return PEAR::raiseError(_kt("Document has no workflow"));
     }
     if (PEAR::isError($oWorkflow)) {
         return $oWorkflow;
     }
     $oSourceState =& KTWorkflowUtil::getWorkflowStateForDocument($oDocument);
     // walk the action triggers.
     $aActionTriggers = KTWorkflowUtil::getActionTriggersForTransition($oTransition);
     if (PEAR::isError($aActionTriggers)) {
         return $aActionTriggers;
         // error out?
     }
     foreach ($aActionTriggers as $oTrigger) {
         $res = $oTrigger->precheckTransition($oDocument, $oUser);
         if (PEAR::isError($res)) {
             return $res;
         }
     }
     $iPreviousMetadataVersion = $oDocument->getMetadataVersionId();
     $oDocument->startNewMetadataVersion($oUser);
     KTDocumentUtil::copyMetadata($oDocument, $iPreviousMetadataVersion);
     $iStateId = $oTransition->getTargetStateId();
     $oDocument->setWorkflowStateId($iStateId);
     $res = $oDocument->update();
     if (PEAR::isError($res)) {
         return $res;
     }
     $oTargetState =& KTWorkflowState::get($iStateId);
     $sSourceState = $oSourceState->getName();
     $sTargetState = $oTargetState->getName();
     // create the document transaction record
     $sTransactionComments = sprintf(_kt("Workflow state changed from %s to %s"), $sSourceState, $sTargetState);
     if ($sComments) {
         $sTransactionComments .= _kt("; Reason given was: ") . $sComments;
     }
     $oDocumentTransaction = new DocumentTransaction($oDocument, $sTransactionComments, 'ktcore.transactions.workflow_state_transition');
     $oDocumentTransaction->create();
     // walk the action triggers.
     foreach ($aActionTriggers as $oTrigger) {
         $res = $oTrigger->performTransition($oDocument, $oUser);
         if (PEAR::isError($res)) {
             return $res;
         }
     }
     KTPermissionUtil::updatePermissionLookup($oDocument);
     KTWorkflowUtil::informUsersForState($oTargetState, KTWorkflowUtil::getInformedForState($oTargetState), $oDocument, $oUser, $sComments);
     return true;
 }
コード例 #9
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/foldermanagement/Folder.inc';
require_once KT_LIB_DIR . '/documentmanagement/Document.inc';
require_once KT_LIB_DIR . '/permissions/permissionutil.inc.php';
error_reporting(E_ALL);
/*
$aFolders =& Folder::getList();
foreach ($aFolders as $oFolder) {
    KTPermissionUtil::updatePermissionLookup($oFolder);
}
$aDocuments =& Document::getList('permission_object_id IS NOT NULL');
foreach ($aDocuments as $oDocument) {
    KTPermissionUtil::updatePermissionLookup($oDocument);
}
*/
$oDocument = Document::get(447);
KTPermissionUtil::updatePermissionLookup($oDocument);
コード例 #10
0
 function move($oDocument, $oToFolder, $oUser = null, $sReason = null)
 {
     //make sure we move the symlink, and the document it's linking to
     if ($oDocument->isSymbolicLink()) {
         $oDocument->switchToRealCore();
     } else {
         $oDocument->switchToLinkedCore();
     }
     $oFolder = $oToFolder;
     // alias.
     $oOriginalFolder = Folder::get($oDocument->getFolderId());
     $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId();
     $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId();
     if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) {
         $oDocument->setPermissionObjectId($oFolder->getPermissionObjectId());
     }
     //put the document in the new folder
     $oDocument->setFolderID($oFolder->getId());
     $sName = $oDocument->getName();
     $sFilename = $oDocument->getFileName();
     $oDocument->setFileName(KTDocumentUtil::getUniqueFilename($oToFolder, $sFilename));
     $oDocument->setName(KTDocumentUtil::getUniqueDocumentName($oToFolder, $sName));
     $res = $oDocument->update();
     if (PEAR::isError($res)) {
         return $res;
     }
     //move the document on the file system(not if it's a symlink)
     if (!$oDocument->isSymbolicLink()) {
         $oStorage =& KTStorageManagerUtil::getSingleton();
         $res = $oStorage->moveDocument($oDocument, $oFolder, $oOriginalFolder);
         if (PEAR::isError($res) || $res === false) {
             $oDocument->setFolderID($oOriginalFolder->getId());
             $res = $oDocument->update();
             if (PEAR::isError($res)) {
                 return $res;
             }
             return $res;
             // we failed, bail.
         }
     }
     $sMoveMessage = sprintf(_kt("Moved from %s/%s to %s/%s. %s"), $oOriginalFolder->getFullPath(), $oOriginalFolder->getName(), $oFolder->getFullPath(), $oFolder->getName(), $sReason);
     // create the document transaction record
     $oDocumentTransaction = new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move');
     $oDocumentTransaction->create();
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array('document' => $oDocument, 'old_folder' => $oOriginalFolder, 'new_folder' => $oFolder);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
         if (PEAR::isError($ret)) {
             return $ret;
         }
     }
     // fire subscription alerts for the moved document
     $oSubscriptionEvent = new SubscriptionEvent();
     $oSubscriptionEvent->MoveDocument($oDocument, $oFolder, $oOriginalFolder);
     return KTPermissionUtil::updatePermissionLookup($oDocument);
 }
コード例 #11
0
ファイル: KTAssist.php プロジェクト: 5haman/knowledgetree
 function restore($iDocId)
 {
     // Get the document object
     $oDoc = Document::get($iDocId);
     if (PEAR::isError($oDoc) || $oDoc === false) {
         return $oDoc;
     }
     $this->startTransaction();
     $iRestoreFolder = $oDoc->getRestoreFolderId();
     $oFolder = Folder::get($iRestoreFolder);
     // move to root if parent no longer exists.
     if (PEAR::isError($oFolder)) {
         $oDoc->setFolderId(1);
         $oFolder = Folder::get(1);
     } else {
         $oDoc->setFolderId($iRestoreFolder);
     }
     $oStorage = KTStorageManagerUtil::getSingleton();
     if ($oStorage->restore($oDoc)) {
         $oDoc = Document::get($iDocId);
         // storage path has changed for most recent object...
         $oDoc->setStatusId(LIVE);
         $oDoc->setPermissionObjectId($oFolder->getPermissionObjectId());
         $res = $oDoc->update();
         if (PEAR::isError($res) || $res == false) {
             return $res;
         }
         $res = KTPermissionUtil::updatePermissionLookup($oDoc);
         if (PEAR::isError($res)) {
             return $res;
         }
         // create a doc-transaction.
         $oTransaction = new DocumentTransaction($oDoc, sprintf(_kt("Restored from deleted state by %s"), $this->oUser->getName()), 'ktcore.transactions.update');
         $oTransaction->create();
     }
     $this->commitTransaction();
     return true;
 }