Commit 7addd52afd19e787dfbe8be2a91c678549c31f4e
1 parent
7f3cfc86
Implement document deletion using the action system.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4069 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
114 additions
and
7 deletions
plugins/ktcore/KTDocumentActions.php
| ... | ... | @@ -5,6 +5,7 @@ require_once(KT_LIB_DIR . '/subscriptions/Subscription.inc'); |
| 5 | 5 | require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); |
| 6 | 6 | require_once(KT_LIB_DIR . '/browse/browseutil.inc.php'); |
| 7 | 7 | require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); |
| 8 | +require_once(KT_LIB_DIR . '/documentmanagement/PhysicalDocumentManager.inc'); | |
| 8 | 9 | |
| 9 | 10 | $oKTActionRegistry =& KTActionRegistry::getSingleton(); |
| 10 | 11 | |
| ... | ... | @@ -123,6 +124,7 @@ class KTDocumentCheckOutAction extends KTDocumentAction { |
| 123 | 124 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentCheckOutAction', 'ktcore.actions.document.checkout'); |
| 124 | 125 | // }}} |
| 125 | 126 | |
| 127 | +// {{{ KTDocumentCheckInAction | |
| 126 | 128 | class KTDocumentCheckInAction extends KTDocumentAction { |
| 127 | 129 | var $sBuiltInAction = 'checkInDocument'; |
| 128 | 130 | var $sDisplayName = 'Checkin'; |
| ... | ... | @@ -199,23 +201,107 @@ class KTDocumentCheckInAction extends KTDocumentAction { |
| 199 | 201 | } |
| 200 | 202 | } |
| 201 | 203 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentCheckInAction', 'ktcore.actions.document.checkin'); |
| 204 | +// }}} | |
| 202 | 205 | |
| 203 | -class KTDocumentDeleteAction extends KTBuiltInDocumentActionSingle { | |
| 206 | +// {{{ KTDocumentDeleteAction | |
| 207 | +class KTDocumentDeleteAction extends KTDocumentAction { | |
| 204 | 208 | var $sBuiltInAction = 'deleteDocument'; |
| 205 | 209 | var $sDisplayName = 'Delete'; |
| 206 | 210 | var $sName = 'ktcore.actions.document.delete'; |
| 207 | 211 | |
| 208 | 212 | var $_sDisablePermission = "ktcore.permissions.write"; |
| 209 | 213 | |
| 210 | - function _disable() { | |
| 211 | - if ($this->oDocument->getIsCheckedOut()) { | |
| 212 | - $this->_sDisabledText = _("This document can't be deleted because its checked out"); | |
| 213 | - return true; | |
| 214 | - } | |
| 215 | - return parent::_disable(); | |
| 214 | + function getInfo() { | |
| 215 | + if ($this->oDocument->getIsCheckedOut()) { | |
| 216 | + return null; | |
| 217 | + } | |
| 218 | + return parent::getInfo(); | |
| 219 | + } | |
| 220 | + | |
| 221 | + function check() { | |
| 222 | + $res = parent::check(); | |
| 223 | + if ($res !== true) { | |
| 224 | + return $res; | |
| 225 | + } | |
| 226 | + if ($this->oDocument->getIsCheckedOut()) { | |
| 227 | + $_SESSION["KTErrorMessage"][]= _("This document can't be deleted because it is checked out"); | |
| 228 | + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); | |
| 229 | + exit(0); | |
| 230 | + } | |
| 231 | + return true; | |
| 232 | + } | |
| 233 | + function do_main() { | |
| 234 | + $this->oPage->setBreadcrumbDetails("delete"); | |
| 235 | + $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/delete'); | |
| 236 | + $delete_fields = array(); | |
| 237 | + $delete_fields[] = new KTStringWidget('Reason', 'The reason for this document to be removed.', 'reason', "", $this->oPage, true); | |
| 238 | + | |
| 239 | + $oTemplate->setData(array( | |
| 240 | + 'context' => &$this, | |
| 241 | + 'delete_fields' => $delete_fields, | |
| 242 | + )); | |
| 243 | + return $oTemplate->render(); | |
| 244 | + } | |
| 245 | + | |
| 246 | + function do_delete() { | |
| 247 | + global $default; | |
| 248 | + $sReason = KTUtil::arrayGet($_REQUEST, 'reason'); | |
| 249 | + $this->oValidator->notEmpty($sReason); | |
| 250 | + | |
| 251 | + // flip the status id | |
| 252 | + $this->oDocument->setStatusID(DELETED); | |
| 253 | + | |
| 254 | + if (!$this->oDocument->update()) { | |
| 255 | + $_SESSION["KTErrorMessage"][]= _("There was a problem deleting the document from the database."); | |
| 256 | + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); | |
| 257 | + exit(0); | |
| 258 | + } | |
| 259 | + | |
| 260 | + // now move the document to the delete folder | |
| 261 | + if (!PhysicalDocumentManager::delete($this->oDocument)) { | |
| 262 | + //could not delete the document from the file system | |
| 263 | + $default->log->error("deleteDocumentBL.php Filesystem error deleting document " . | |
| 264 | + $this->oDocument->getFileName() . " from folder " . | |
| 265 | + Folder::getFolderPath($this->oDocument->getFolderID()) . | |
| 266 | + " id=" . $this->oDocument->getFolderID()); | |
| 267 | + //reverse the document deletion | |
| 268 | + $this->oDocument->setStatusID(LIVE); | |
| 269 | + $this->oDocument->update(); | |
| 270 | + //get rid of the document transaction | |
| 271 | + $_SESSION["KTErrorMessage"][]= _("There was a problem deleting the document from storage."); | |
| 272 | + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); | |
| 273 | + exit(0); | |
| 274 | + } | |
| 275 | + | |
| 276 | + $oDocumentTransaction = & new DocumentTransaction($this->oDocument->getId(), "Document deleted: " . $sReason, DELETE); | |
| 277 | + $oDocumentTransaction->create(); | |
| 278 | + | |
| 279 | + $this->commitTransaction(); | |
| 280 | + | |
| 281 | + // At this point, the document is deleted. | |
| 282 | + | |
| 283 | + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | |
| 284 | + $aTriggers = $oKTTriggerRegistry->getTriggers('delete', 'postValidate'); | |
| 285 | + foreach ($aTriggers as $aTrigger) { | |
| 286 | + $sTrigger = $aTrigger[0]; | |
| 287 | + $oTrigger = new $sTrigger; | |
| 288 | + $aInfo = array( | |
| 289 | + "document" => $this->oDocument, | |
| 290 | + ); | |
| 291 | + $oTrigger->setInfo($aInfo); | |
| 292 | + $ret = $oTrigger->postValidate(); | |
| 293 | + if (PEAR::isError($ret)) { | |
| 294 | + $this->oDocument->delete(); | |
| 295 | + return $ret; | |
| 296 | + } | |
| 297 | + } | |
| 298 | + | |
| 299 | + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); | |
| 300 | + exit(0); | |
| 216 | 301 | } |
| 217 | 302 | } |
| 218 | 303 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete'); |
| 304 | +// }}} | |
| 219 | 305 | |
| 220 | 306 | class KTDocumentMoveAction extends KTBuiltInDocumentActionSingle { |
| 221 | 307 | var $sBuiltInAction = 'moveDocument'; | ... | ... |
templates/ktcore/action/delete.smarty
0 → 100644
| 1 | +<p class="descriptiveText">Deleting a document marks it as no longer | |
| 2 | +being displayed. The document management system does not remove the | |
| 3 | +document entirely, and it can be restored at a later stage.</p> | |
| 4 | + | |
| 5 | +{assign var=iDocumentId value=$context->oDocument->getId()} | |
| 6 | +<p class="descriptiveText">If you do not intend to delete this document, you should | |
| 7 | +<a href="{"viewDocument"|generateControllerUrl:"fDocumentId=$iDocumentId"}">cancel | |
| 8 | +the deletion</a>.</p> | |
| 9 | + | |
| 10 | +<form method="POST" action="{$smarty.server.PHP_SELF}"> | |
| 11 | +<fieldset><legend>Delete</legend> | |
| 12 | +<input type="hidden" name="action" value="delete" /> | |
| 13 | +<input type="hidden" name="fDocumentId" value="{$iDocumentId}" /> | |
| 14 | +{foreach from=$delete_fields item=oWidget } | |
| 15 | + {$oWidget->render()} | |
| 16 | +{/foreach} | |
| 17 | +<div class="form_actions"> | |
| 18 | +<input type="submit" name="submit" value="Delete" /> | |
| 19 | +</div> | |
| 20 | +</fieldset> | |
| 21 | +</form> | ... | ... |