Commit 2fd5f2e4b234cab451715ce5fef54ad3d455e481
1 parent
fd5af8dc
Added triggers after the expunge has completed to do a bulk action on all expunged documents.
PT: 2100328 Committed by: Megan Watson
Showing
1 changed file
with
78 additions
and
64 deletions
plugins/ktcore/admin/deletedDocuments.php
| ... | ... | @@ -5,32 +5,32 @@ |
| 5 | 5 | * KnowledgeTree Community Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2008, 2009 KnowledgeTree Inc. |
| 8 | - * | |
| 9 | - * | |
| 8 | + * | |
| 9 | + * | |
| 10 | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | 11 | * the terms of the GNU General Public License version 3 as published by the |
| 12 | 12 | * Free Software Foundation. |
| 13 | - * | |
| 13 | + * | |
| 14 | 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 17 | 17 | * details. |
| 18 | - * | |
| 18 | + * | |
| 19 | 19 | * You should have received a copy of the GNU General Public License |
| 20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | - * | |
| 22 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 21 | + * | |
| 22 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | 23 | * California 94120-7775, or email info@knowledgetree.com. |
| 24 | - * | |
| 24 | + * | |
| 25 | 25 | * The interactive user interfaces in modified source and object code versions |
| 26 | 26 | * of this program must display Appropriate Legal Notices, as required under |
| 27 | 27 | * Section 5 of the GNU General Public License version 3. |
| 28 | - * | |
| 28 | + * | |
| 29 | 29 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 30 | 30 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 31 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | 32 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 33 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | 34 | * copyright notice. |
| 35 | 35 | * Contributor( s): ______________________________________ |
| 36 | 36 | * |
| ... | ... | @@ -51,9 +51,9 @@ class DeletedDocumentsDispatcher extends KTAdminDispatcher { |
| 51 | 51 | var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 52 | 52 | function do_main () { |
| 53 | 53 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Deleted Documents')); |
| 54 | - | |
| 54 | + | |
| 55 | 55 | $this->oPage->setBreadcrumbDetails(_kt('view')); |
| 56 | - | |
| 56 | + | |
| 57 | 57 | $aDocuments =& Document::getList('status_id=' . DELETED); |
| 58 | 58 | |
| 59 | 59 | if(!empty($aDocuments)){ |
| ... | ... | @@ -72,12 +72,12 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 72 | 72 | }else{ |
| 73 | 73 | $limit = 9; |
| 74 | 74 | } |
| 75 | - | |
| 75 | + | |
| 76 | 76 | for($i = 0; $i <= $limit; $i++){ |
| 77 | 77 | $aDocumentsList[] = $aDocuments[$i]; |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | - | |
| 80 | + | |
| 81 | 81 | $oTemplating =& KTTemplating::getSingleton(); |
| 82 | 82 | $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/deletedlist'); |
| 83 | 83 | $oTemplate->setData(array( |
| ... | ... | @@ -90,7 +90,7 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 90 | 90 | )); |
| 91 | 91 | return $oTemplate; |
| 92 | 92 | } |
| 93 | - | |
| 93 | + | |
| 94 | 94 | function do_branchConfirm() { |
| 95 | 95 | $submit = KTUtil::arrayGet($_REQUEST, 'submit' , array()); |
| 96 | 96 | if (array_key_exists('expunge',$submit)) { |
| ... | ... | @@ -104,33 +104,33 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 104 | 104 | } |
| 105 | 105 | $this->errorRedirectToMain(_kt('No action specified.')); |
| 106 | 106 | } |
| 107 | - | |
| 107 | + | |
| 108 | 108 | function do_confirm_expunge($all = false) { |
| 109 | 109 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Deleted Documents')); |
| 110 | - | |
| 110 | + | |
| 111 | 111 | $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); |
| 112 | 112 | $full_docs = KTUtil::arrayGet($_REQUEST, 'docIds', array()); |
| 113 | - | |
| 113 | + | |
| 114 | 114 | if($all == true){ |
| 115 | 115 | $selected_docs = $full_docs; |
| 116 | 116 | } |
| 117 | - | |
| 117 | + | |
| 118 | 118 | $this->oPage->setTitle(sprintf(_kt('Confirm Expunge of %d documents'), count($selected_docs))); |
| 119 | - | |
| 119 | + | |
| 120 | 120 | $this->oPage->setBreadcrumbDetails(sprintf(_kt('confirm expunge of %d documents'), count($selected_docs))); |
| 121 | - | |
| 121 | + | |
| 122 | 122 | $aDocuments = array(); |
| 123 | 123 | foreach ($selected_docs as $doc_id) { |
| 124 | 124 | $oDoc =& Document::get($doc_id); |
| 125 | - if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 125 | + if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 126 | 126 | $this->errorRedirectToMain(_kt('Invalid document id specified. Aborting expunge')); |
| 127 | 127 | } else if ($oDoc->getStatusId() != DELETED) { |
| 128 | 128 | $this->errorRedirectToMain(sprintf(_kt('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); |
| 129 | 129 | } |
| 130 | 130 | $aDocuments[] = $oDoc; |
| 131 | 131 | } |
| 132 | - | |
| 133 | - | |
| 132 | + | |
| 133 | + | |
| 134 | 134 | $oTemplating =& KTTemplating::getSingleton(); |
| 135 | 135 | $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/expungeconfirmlist'); |
| 136 | 136 | $oTemplate->setData(array( |
| ... | ... | @@ -140,47 +140,49 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 140 | 140 | return $oTemplate; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - function do_finish_expunge() { | |
| 144 | - $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); | |
| 145 | - | |
| 143 | + function do_finish_expunge() { | |
| 144 | + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); | |
| 145 | + | |
| 146 | 146 | $aDocuments = array(); |
| 147 | 147 | foreach ($selected_docs as $doc_id) { |
| 148 | 148 | $oDoc =& Document::get($doc_id); |
| 149 | - if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 149 | + if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 150 | 150 | $this->errorRedirectToMain(_kt('Invalid document id specified. Aborting expunge')); |
| 151 | 151 | } else if ($oDoc->getStatusId() != DELETED) { |
| 152 | 152 | $this->errorRedirectToMain(sprintf(_kt('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); |
| 153 | 153 | } |
| 154 | 154 | $aDocuments[] = $oDoc; |
| 155 | 155 | } |
| 156 | - | |
| 156 | + | |
| 157 | 157 | $this->startTransaction(); |
| 158 | 158 | $aErrorDocuments = array(); |
| 159 | - $aSuccessDocuments = array(); | |
| 159 | + $aSuccessDocuments = array(); | |
| 160 | + $aDeletedDocs = array(); | |
| 160 | 161 | |
| 161 | 162 | $oStorage =& KTStorageManagerUtil::getSingleton(); |
| 163 | + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | |
| 162 | 164 | |
| 163 | 165 | foreach ($aDocuments as $oDoc) { |
| 164 | 166 | // first evaluate the folder for inconsistencies. |
| 165 | 167 | $oFolder = Folder::get($oDoc->getFolderID()); |
| 166 | 168 | if (PEAR::isError($oFolder)) { $oDoc->setFolderId(1); $oDoc->update(); } |
| 167 | - | |
| 169 | + | |
| 168 | 170 | if (!$oStorage->expunge($oDoc)) { $aErrorDocuments[] = $oDoc->getDisplayPath(); } |
| 169 | 171 | else { |
| 170 | 172 | $oDocumentTransaction = & new DocumentTransaction($oDoc, _kt('Document expunged'), 'ktcore.transactions.expunge'); |
| 171 | 173 | $oDocumentTransaction->create(); |
| 172 | - | |
| 174 | + | |
| 173 | 175 | // delete this from the db now |
| 174 | 176 | if (!$oDoc->delete()) { |
| 175 | - $aErrorDocuments[] = $oDoc->getId(); | |
| 177 | + $aErrorDocuments[] = $oDoc->getId(); | |
| 176 | 178 | } else { |
| 177 | 179 | // removed succesfully |
| 178 | 180 | $aSuccessDocuments[] = $oDoc->getDisplayPath(); |
| 179 | - | |
| 181 | + $aDeletedDocs[] = $oDoc->getId(); | |
| 182 | + | |
| 180 | 183 | // remove any document data |
| 181 | 184 | $oDoc->cleanupDocumentData($oDoc->getId()); // silly - why the redundancy? |
| 182 | - | |
| 183 | - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | |
| 185 | + | |
| 184 | 186 | $aTriggers = $oKTTriggerRegistry->getTriggers('expunge', 'finalised'); |
| 185 | 187 | foreach ($aTriggers as $aTrigger) { |
| 186 | 188 | $sTrigger = $aTrigger[0]; |
| ... | ... | @@ -189,38 +191,50 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 189 | 191 | 'document' => $oDoc, |
| 190 | 192 | ); |
| 191 | 193 | $oTrigger->setInfo($aInfo); |
| 192 | - $ret = $oTrigger->finalised(); | |
| 194 | + $ret = $oTrigger->finalised(); | |
| 193 | 195 | } |
| 194 | 196 | } |
| 195 | 197 | } |
| 196 | 198 | } |
| 197 | 199 | $this->commitTransaction(); |
| 200 | + | |
| 201 | + $aTriggers = $oKTTriggerRegistry->getTriggers('expunge', 'postValidate'); | |
| 202 | + foreach ($aTriggers as $aTrigger) { | |
| 203 | + $sTrigger = $aTrigger[0]; | |
| 204 | + $oTrigger = new $sTrigger; | |
| 205 | + $aInfo = array( | |
| 206 | + 'documents' => $aDeletedDocs, | |
| 207 | + ); | |
| 208 | + $oTrigger->setInfo($aInfo); | |
| 209 | + $ret = $oTrigger->postValidate(); | |
| 210 | + } | |
| 211 | + | |
| 198 | 212 | $msg = sprintf(_kt('%d documents expunged.'), count($aSuccessDocuments)); |
| 199 | 213 | if (count($aErrorDocuments) != 0) { $msg .= _kt('Failed to expunge') . ': ' . join(', ', $aErrorDocuments); } |
| 200 | 214 | $this->successRedirectToMain($msg); |
| 201 | 215 | } |
| 202 | - | |
| 216 | + | |
| 203 | 217 | function do_confirm_restore() { |
| 204 | 218 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Deleted Documents')); |
| 205 | - | |
| 206 | - $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); | |
| 207 | - | |
| 219 | + | |
| 220 | + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); | |
| 221 | + | |
| 208 | 222 | $this->oPage->setTitle(sprintf(_kt('Confirm Restore of %d documents'), count($selected_docs))); |
| 209 | - | |
| 223 | + | |
| 210 | 224 | $this->oPage->setBreadcrumbDetails(sprintf(_kt('Confirm Restore of %d documents'), count($selected_docs))); |
| 211 | - | |
| 225 | + | |
| 212 | 226 | $aDocuments = array(); |
| 213 | 227 | foreach ($selected_docs as $doc_id) { |
| 214 | 228 | $oDoc =& Document::get($doc_id); |
| 215 | - if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 229 | + if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 216 | 230 | $this->errorRedirectToMain(_kt('Invalid document id specified. Aborting expunge')); |
| 217 | 231 | } else if ($oDoc->getStatusId() != DELETED) { |
| 218 | 232 | $this->errorRedirectToMain(sprintf(_kt('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); |
| 219 | 233 | } |
| 220 | 234 | $aDocuments[] = $oDoc; |
| 221 | 235 | } |
| 222 | - | |
| 223 | - | |
| 236 | + | |
| 237 | + | |
| 224 | 238 | $oTemplating =& KTTemplating::getSingleton(); |
| 225 | 239 | $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/restoreconfirmlist'); |
| 226 | 240 | $oTemplate->setData(array( |
| ... | ... | @@ -230,36 +244,36 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 230 | 244 | return $oTemplate; |
| 231 | 245 | } |
| 232 | 246 | |
| 233 | - function do_finish_restore() { | |
| 234 | - $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); | |
| 235 | - | |
| 247 | + function do_finish_restore() { | |
| 248 | + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); | |
| 249 | + | |
| 236 | 250 | $aDocuments = array(); |
| 237 | 251 | foreach ($selected_docs as $doc_id) { |
| 238 | 252 | $oDoc =& Document::get($doc_id); |
| 239 | - if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 253 | + if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 240 | 254 | $this->errorRedirectToMain(_kt('Invalid document id specified. Aborting restore')); |
| 241 | 255 | } else if ($oDoc->getStatusId() != DELETED) { |
| 242 | 256 | $this->errorRedirectToMain(sprintf(_kt('%s is not a deleted document. Aborting restore'), $oDoc->getName())); |
| 243 | 257 | } |
| 244 | 258 | $aDocuments[] = $oDoc; |
| 245 | 259 | } |
| 246 | - | |
| 260 | + | |
| 247 | 261 | $this->startTransaction(); |
| 248 | 262 | $aErrorDocuments = array(); |
| 249 | - $aSuccessDocuments = array(); | |
| 263 | + $aSuccessDocuments = array(); | |
| 250 | 264 | |
| 251 | 265 | $oStorage =& KTStorageManagerUtil::getSingleton(); |
| 252 | 266 | |
| 253 | 267 | foreach ($aDocuments as $oDoc) { |
| 254 | 268 | $oFolder = Folder::get($oDoc->getRestoreFolderId()); |
| 255 | 269 | // move to root if parent no longer exists. |
| 256 | - if (PEAR::isError($oFolder)) { | |
| 257 | - $oDoc->setFolderId(1); | |
| 270 | + if (PEAR::isError($oFolder)) { | |
| 271 | + $oDoc->setFolderId(1); | |
| 258 | 272 | $oFolder = Folder::get(1); |
| 259 | - } else { | |
| 273 | + } else { | |
| 260 | 274 | $oDoc->setFolderId($oDoc->getRestoreFolderId()); |
| 261 | 275 | } |
| 262 | - | |
| 276 | + | |
| 263 | 277 | if ($oStorage->restore($oDoc)) { |
| 264 | 278 | $oDoc = Document::get($oDoc->getId()); // storage path has changed for most recent object... |
| 265 | 279 | $oDoc->setStatusId(LIVE); |
| ... | ... | @@ -269,14 +283,14 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 269 | 283 | $aErrorDocuments[] = $oDoc->getName(); |
| 270 | 284 | continue; // skip transactions, etc. |
| 271 | 285 | } |
| 272 | - | |
| 286 | + | |
| 273 | 287 | $res = KTPermissionUtil::updatePermissionLookup($oDoc); |
| 274 | - | |
| 288 | + | |
| 275 | 289 | if (PEAR::isError($res)) { |
| 276 | 290 | $aErrorDocuments[] = $oDoc->getName(); |
| 277 | 291 | continue; // skip transactions, etc. |
| 278 | 292 | } |
| 279 | - | |
| 293 | + | |
| 280 | 294 | // create a doc-transaction. |
| 281 | 295 | // FIXME does this warrant a transaction-type? |
| 282 | 296 | $oTransaction = new DocumentTransaction($oDoc, sprintf(_kt("Restored from deleted state by %s"), $this->oUser->getName()), 'ktcore.transactions.update'); |
| ... | ... | @@ -293,14 +307,14 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html'; |
| 293 | 307 | $msg = sprintf(_kt('%d documents restored.'), count($aSuccessDocuments)); |
| 294 | 308 | if (count($aErrorDocuments) != 0) { $msg .= _kt('Failed to restore') . ': ' . join(', ', $aErrorDocuments); } |
| 295 | 309 | $this->successRedirectToMain($msg); |
| 296 | - } | |
| 297 | - | |
| 310 | + } | |
| 311 | + | |
| 298 | 312 | function getRestoreLocationFor($oDocument) { |
| 299 | - $iFolderId = $oDocument->getRestoreFolderId(); | |
| 313 | + $iFolderId = $oDocument->getRestoreFolderId(); | |
| 300 | 314 | $oFolder = Folder::get($iFolderId); |
| 301 | - | |
| 315 | + | |
| 302 | 316 | if (PEAR::isError($oFolder)) { |
| 303 | - return _kt('Original folder no longer exists. Document will be restored in the root folder.'); | |
| 317 | + return _kt('Original folder no longer exists. Document will be restored in the root folder.'); | |
| 304 | 318 | } else { |
| 305 | 319 | $aCrumbs = KTBrowseUtil::breadcrumbsForFolder($oFolder); |
| 306 | 320 | $aParts = array(); | ... | ... |