Beispiel #1
0
 function check_entity($oEntity)
 {
     // NOTE: these checks don't have an equivalent in the delete and move functions.
     //       possibly they are no longer needed but I am leaving them here
     //       to avoid any potential problems I may not be aware of
     if (!is_a($oEntity, 'Document') && !is_a($oEntity, 'Folder')) {
         return PEAR::raiseError(_kt('Document cannot be archived'));
     }
     if ($oEntity->isSymbolicLink()) {
         return PEAR::raiseError(_kt("It is not possible to archive a shortcut. Please archive the target document or folder instead."));
     }
     if (is_a($oEntity, 'Document')) {
         if (!KTDocumentUtil::canBeArchived($oEntity, $sError)) {
             if (PEAR::isError($sError)) {
                 return $sError;
             }
             return PEAR::raiseError(_kt('Document cannot be archived'));
         }
     }
     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();
         // Loop through documents and send to this function for checking
         if (!empty($aDocuments)) {
             foreach ($aDocuments as $sDocID) {
                 $oDocument = Document::get($sDocID);
                 $res = $this->check_entity($oDocument);
                 if (PEAR::isError($res)) {
                     // NOTE: we may want to append the document reason to this
                     // in order for the user to have some idea WHY the folder cannot be archived
                     return PEAR::raiseError(_kt('Folder cannot be archived'));
                 }
             }
         }
         // If all documents at the current level may be archived, we can continue
         // Get any existing subfolders
         $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 subfolders and check each in the same way as the parent
         if (!empty($aChildFolders)) {
             foreach ($aChildFolders as $oChild) {
                 $res = $this->check_entity($oChild);
                 if (PEAR::isError($res)) {
                     // NOTE: we may want to append the document reason to this
                     // in order for the user to have some idea WHY the folder cannot be archived
                     return PEAR::raiseError(_kt('Folder cannot be archived'));
                 }
             }
         }
     }
     return parent::check_entity($oEntity);
 }