Commit da6484cabaf4edb4a3ceab54714b8430a4b1f99e
1 parent
595a41ef
- deleted documents can now be either restored on expunged (again).
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4465 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
127 additions
and
3 deletions
plugins/ktcore/admin/deletedDocuments.php
| ... | ... | @@ -27,6 +27,17 @@ class DeletedDocumentsDispatcher extends KTAdminDispatcher { |
| 27 | 27 | return $oTemplate; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | + function do_branchConfirm() { | |
| 31 | + $submit = KTUtil::arrayGet($_REQUEST, 'submit' , array()); | |
| 32 | + if (array_key_exists('expunge',$submit)) { | |
| 33 | + return $this->do_confirm_expunge(); | |
| 34 | + } | |
| 35 | + if (array_key_exists('restore', $submit)) { | |
| 36 | + return $this->do_confirm_restore(); | |
| 37 | + } | |
| 38 | + $this->errorRedirectToMain(_('No action specified.')); | |
| 39 | + } | |
| 40 | + | |
| 30 | 41 | function do_confirm_expunge() { |
| 31 | 42 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Deleted Documents')); |
| 32 | 43 | |
| ... | ... | @@ -99,6 +110,82 @@ class DeletedDocumentsDispatcher extends KTAdminDispatcher { |
| 99 | 110 | if (count($aErrorDocuments) != 0) { $msg .= _('Failed to expunge') . ': ' . join(', ', $aErrorDocuments); } |
| 100 | 111 | $this->successRedirectToMain($msg); |
| 101 | 112 | } |
| 113 | + | |
| 114 | + | |
| 115 | + function do_confirm_restore() { | |
| 116 | + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Deleted Documents')); | |
| 117 | + | |
| 118 | + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); | |
| 119 | + | |
| 120 | + $this->oPage->setTitle(sprintf(_('Confirm Restore of %d documents'), count($selected_docs))); | |
| 121 | + | |
| 122 | + $this->oPage->setBreadcrumbDetails(sprintf(_('Confirm Restore of %d documents'), count($selected_docs))); | |
| 123 | + | |
| 124 | + $aDocuments = array(); | |
| 125 | + foreach ($selected_docs as $doc_id) { | |
| 126 | + $oDoc =& Document::get($doc_id); | |
| 127 | + if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 128 | + $this->errorRedirectToMain(_('Invalid document id specified. Aborting expunge')); | |
| 129 | + } else if ($oDoc->getStatusId() != DELETED) { | |
| 130 | + $this->errorRedirectToMain(sprintf(_('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); | |
| 131 | + } | |
| 132 | + $aDocuments[] = $oDoc; | |
| 133 | + } | |
| 134 | + | |
| 135 | + | |
| 136 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 137 | + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/restoreconfirmlist'); | |
| 138 | + $oTemplate->setData(array( | |
| 139 | + 'context' => $this, | |
| 140 | + 'documents' => $aDocuments, | |
| 141 | + )); | |
| 142 | + return $oTemplate; | |
| 143 | + } | |
| 144 | + | |
| 145 | + function do_finish_restore() { | |
| 146 | + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); | |
| 147 | + | |
| 148 | + $aDocuments = array(); | |
| 149 | + foreach ($selected_docs as $doc_id) { | |
| 150 | + $oDoc =& Document::get($doc_id); | |
| 151 | + if (PEAR::isError($oDoc) || ($oDoc === false)) { | |
| 152 | + $this->errorRedirectToMain(_('Invalid document id specified. Aborting restore')); | |
| 153 | + } else if ($oDoc->getStatusId() != DELETED) { | |
| 154 | + $this->errorRedirectToMain(sprintf(_('%s is not a deleted document. Aborting restore'), $oDoc->getName())); | |
| 155 | + } | |
| 156 | + $aDocuments[] = $oDoc; | |
| 157 | + } | |
| 158 | + | |
| 159 | + $this->startTransaction(); | |
| 160 | + $aErrorDocuments = array(); | |
| 161 | + $aSuccessDocuments = array(); | |
| 162 | + | |
| 163 | + foreach ($aDocuments as $oDoc) { | |
| 164 | + if (PhysicalDocumentManager::restore($oDoc)) { | |
| 165 | + $oDoc->setStatusId(LIVE); | |
| 166 | + $res = $oDoc->update(); | |
| 167 | + if (PEAR::isError($res) || ($res == false)) { | |
| 168 | + PhysicalDocumentManager::delete($oDoc) | |
| 169 | + $aErrorDocuments[] = $oDoc->getName; | |
| 170 | + continue; // skip transactions, etc. | |
| 171 | + } | |
| 172 | + // create a doc-transaction. | |
| 173 | + // FIXME does this warrant a transaction-type? | |
| 174 | + $oTransaction = new DocumentTransaction($oDoc, 'Restored from deleted state by ' . $this->oUser->getName(), 'ktcore.transactions.update'); | |
| 175 | + if (!$oTransaction->create()) { | |
| 176 | + ; // do nothing? the state of physicaldocumentmanager... | |
| 177 | + } | |
| 178 | + $aSuccessDocuments[] = $oDoc->getName(); | |
| 179 | + } else { | |
| 180 | + $aErrorDocuments[] = $oDoc->getName(); | |
| 181 | + } | |
| 182 | + } | |
| 183 | + $this->commitTransaction(); | |
| 184 | + $msg = sprintf(_('%d documents restored.'), count($aSuccessDocuments)); | |
| 185 | + if (count($aErrorDocuments) != 0) { $msg .= _('Failed to restore') . ': ' . join(', ', $aErrorDocuments); } | |
| 186 | + $this->successRedirectToMain($msg); | |
| 187 | + } | |
| 188 | + | |
| 102 | 189 | } |
| 103 | 190 | |
| 104 | 191 | ?> | ... | ... |
templates/ktcore/document/admin/deletedlist.smarty
| ... | ... | @@ -14,7 +14,7 @@ more information about the documents below - e.g. when was it deleted (last modi |
| 14 | 14 | |
| 15 | 15 | <form action="{$smarty.server.PHP_SELF}" method="POST"> |
| 16 | 16 | |
| 17 | -<input type="hidden" name="action" value="confirm_expunge" /> | |
| 17 | +<input type="hidden" name="action" value="branchConfirm" /> | |
| 18 | 18 | |
| 19 | 19 | <table class="listing"> |
| 20 | 20 | <thead> |
| ... | ... | @@ -35,8 +35,8 @@ more information about the documents below - e.g. when was it deleted (last modi |
| 35 | 35 | </tbody> |
| 36 | 36 | </table> |
| 37 | 37 | <div class="form_actions"> |
| 38 | - <input type="submit" value="{i18n}Expunge{/i18n}" /> | |
| 39 | - <!-- <input type="submit" value="Restore" /> --> <!-- how do we want to handle restore in this? major UI issue :( --> | |
| 38 | + <input type="submit" name="submit[expunge]" value="{i18n}Expunge{/i18n}" /> | |
| 39 | + <input type="submit" name="submit[restore]" value="{i18n}Restore{/i18n}" /> | |
| 40 | 40 | </div> |
| 41 | 41 | </form> |
| 42 | 42 | ... | ... |
templates/ktcore/document/admin/restoreconfirmlist.smarty
0 → 100644
| 1 | +<h2>{i18n}Confirm Restore{/i18n}</h2> | |
| 2 | + | |
| 3 | +<div class="ktInfo"><p><strong>{i18n}Note{/i18n}:</strong> {i18n}please | |
| 4 | +confirm that you want to restore these documents.{/i18n}</p></div> | |
| 5 | + | |
| 6 | +{if (!empty($documents))} | |
| 7 | + | |
| 8 | +<form action="{$smarty.server.PHP_SELF}" method="POST"> | |
| 9 | + | |
| 10 | +<input type="hidden" name="action" value="finish_restore" /> | |
| 11 | + | |
| 12 | +<table class="listing"> | |
| 13 | + <thead> | |
| 14 | + <tr> | |
| 15 | + | |
| 16 | + <th>{i18n}Document Name{/i18n}</th> | |
| 17 | + <th>{i18n}Location{/i18n}</th> | |
| 18 | + </tr> | |
| 19 | + </thead> | |
| 20 | + <tbody> | |
| 21 | + {foreach item=oDoc from=$documents} | |
| 22 | + <tr> | |
| 23 | + <td>{$oDoc->getName()}<input type="hidden" name="selected_docs[]" value="{$oDoc->getId()}" /></td> | |
| 24 | + <td class="descriptiveText">{$oDoc->getDisplayPath()}</td> | |
| 25 | + </tr> | |
| 26 | + {/foreach} | |
| 27 | + </tbody> | |
| 28 | +</table> | |
| 29 | +<div class="form_actions"> | |
| 30 | + <input type="submit" value="{i18n}Confirm Restore{/i18n}" /> | |
| 31 | + | |
| 32 | +</div> | |
| 33 | +</form> | |
| 34 | + | |
| 35 | +{else} | |
| 36 | +<div class="ktInfo"><p>{i18n}No documents were selected.{/i18n}</p></div> | |
| 37 | +{/if} | ... | ... |