Commit 4389f67ef83b837eb8ee5c280dbf0170bc57b192

Authored by nbm
1 parent 2eaee1fa

updatePermissions now not only updates the folder and its children's

permission folder, but the permissions on each of the documents in those
folders.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3127 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 50 additions and 2 deletions
lib/foldermanagement/Folder.inc
... ... @@ -762,14 +762,62 @@ class Folder extends KTEntity {
762 762  
763 763 // {{{ updatePermissions()
764 764 function updatePermissions () {
  765 + // Update PermissionFolderIDs on folder and all folders in this
  766 + // branch.
  767 + $this->updatePermissionFolders();
  768 +
  769 + // Now, we need to redo the permissions for all documents that
  770 + // share are in this branch of the tree that are in folders that
  771 + // share our PermissionFolderID.
  772 +
  773 + // First, we update the documents in this folder
  774 + $sQuery = "SELECT D.id AS id FROM documents AS D WHERE D.folder_id = ?";
  775 + $aParams = array($this->getID());
  776 + $aDocumentIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
  777 + // OPT: We could just do the work for the first, and copy it to
  778 + // the others...
  779 + foreach ($aDocumentIDs as $iDocumentID) {
  780 + Permission::updateSearchPermissionsForDocument($iDocumentID);
  781 + }
  782 +
  783 + // Then, we update the documents in our subfolders
  784 + $sFolderIDs = $this->generateFolderIDs($this->getID());
  785 + $sFolderIDs .= '%';
  786 + $sQuery = "SELECT D.id AS id FROM documents AS D JOIN folders AS F on D.folder_id = F.id WHERE F.parent_folder_ids LIKE ?";
  787 + $aParams = array($sFolderIDs);
  788 + $aDocumentIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
  789 +
  790 + // OPT: We could just do the work for the first, and copy it to
  791 + // the others...
  792 + foreach ($aDocumentIDs as $iDocumentID) {
  793 + Permission::updateSearchPermissionsForDocument($iDocumentID);
  794 + }
  795 + }
  796 + // }}}
  797 +
  798 + // {{{ updatePermissionFolders()
  799 + /**
  800 + * Update the PermissionFolderID on this folder and all folders on
  801 + * this branch.
  802 + *
  803 + */
  804 + function updatePermissionFolders() {
  805 + $iOldPermissionFolderID = $this->iPermissionFolderID;
765 806 $this->calculatePermissionFolder();
  807 + $iNewPermissionFolderID = $this->iPermissionFolderID;
  808 +
  809 + // If our permission folder hasn't changed, our children's won't
  810 + // have.
  811 + if ($iOldPermissionFolderID === $iNewPermissionFolderID) {
  812 + return;
  813 + }
  814 +
766 815 // XXX: Non-explicit update... Have to update, or the children
767 816 // wouldn't have access to it for the shortcut...
768 817 $this->update();
769   -
770 818 $aChildren = Folder::getList(array('parent_id = ?', $this->getID()));
771 819 foreach ($aChildren as $oChild) {
772   - $oChild->updatePermissions();
  820 + $oChild->updatePermissionFolders();
773 821 }
774 822 }
775 823 // }}}
... ...