コード例 #1
0
 /**
  * Inherits permission object from parent, throwing away our own
  * permission object.
  */
 function inheritPermissionObject(&$oDocumentOrFolder, $aOptions = null)
 {
     global $default;
     $oDocumentOrFolder->cacheGlobal = array();
     $bEvenIfNotOwner = KTUtil::arrayGet($aOptions, 'evenifnotowner');
     if (empty($bEvenIfNotOwner) && !KTPermissionUtil::isPermissionOwner($oDocumentOrFolder)) {
         return PEAR::raiseError(_kt("Document or Folder doesn't own its permission object"));
     }
     $iOrigPOID = $oDocumentOrFolder->getPermissionObjectID();
     $oOrigPO =& KTPermissionObject::get($iOrigPOID);
     $oFolder =& Folder::get($oDocumentOrFolder->getParentID());
     $iNewPOID = $oFolder->getPermissionObjectID();
     $oNewPO =& KTPermissionObject::get($iNewPOID);
     $oDocumentOrFolder->setPermissionObjectID($iNewPOID);
     $oDocumentOrFolder->update();
     if (is_a($oDocumentOrFolder, 'Document')) {
         // If we're a document, no niggly children to worry about.
         KTPermissionUtil::updatePermissionLookup($oDocumentOrFolder);
         return;
     }
     // if the new and old permission object and lookup ids are the same, then we might as well bail
     if ($iOrigPOID == $iNewPOID) {
         if ($oDocumentOrFolder->getPermissionLookupID() == $oFolder->getPermissionLookupID()) {
             // doing this, as this was done below... (not ideal to copy, but anyways...)
             Document::clearAllCaches();
             Folder::clearAllCaches();
             return;
         }
     }
     $iFolderID = $oDocumentOrFolder->getID();
     $sFolderIDs = Folder::generateFolderIDs($iFolderID);
     $sFolderIDs .= '%';
     $sQuery = "UPDATE {$default->folders_table} SET\n            permission_object_id = ? WHERE permission_object_id = ? AND\n            parent_folder_ids LIKE ?";
     $aParams = array($oNewPO->getID(), $oOrigPO->getID(), $sFolderIDs);
     DBUtil::runQuery(array($sQuery, $aParams));
     Folder::clearAllCaches();
     // Update all documents in the folder and in the sub-folders
     $sQuery = "UPDATE {$default->documents_table} SET\n            permission_object_id = ? WHERE permission_object_id = ? AND\n            (parent_folder_ids LIKE ? OR folder_id = ?)";
     $aParams[] = $iFolderID;
     DBUtil::runQuery(array($sQuery, $aParams));
     Document::clearAllCaches();
     KTPermissionUtil::updatePermissionLookupForPO($oNewPO);
 }