From e29fdadfac1bd841dbe71ec410636c97d7761a47 Mon Sep 17 00:00:00 2001
From: Brad Shuttleworth
Date: Tue, 18 Jul 2006 11:05:57 +0000
Subject: [PATCH] partial fix for KTS-484.
---
docs/VERSION.txt | 2 +-
lib/documentmanagement/Document.inc | 9 +++++++++
lib/documentmanagement/documentcore.inc.php | 15 +++++++++++++++
lib/documentmanagement/documentutil.inc.php | 32 ++++++++++++++++++++++----------
plugins/ktcore/admin/deletedDocuments.php | 19 +++++++++++++++++--
sql/mysql/upgrade/3.0.3.6/document-restore.sql | 3 +++
templates/ktcore/document/admin/deletedlist.smarty | 4 ++--
templates/ktcore/document/admin/restoreconfirmlist.smarty | 2 ++
8 files changed, 71 insertions(+), 15 deletions(-)
create mode 100644 sql/mysql/upgrade/3.0.3.6/document-restore.sql
diff --git a/docs/VERSION.txt b/docs/VERSION.txt
index 1427e53..2f7549e 100644
--- a/docs/VERSION.txt
+++ b/docs/VERSION.txt
@@ -1 +1 @@
-3.0.3.5
+3.0.3.6
diff --git a/lib/documentmanagement/Document.inc b/lib/documentmanagement/Document.inc
index e4c021b..60154bc 100644
--- a/lib/documentmanagement/Document.inc
+++ b/lib/documentmanagement/Document.inc
@@ -94,6 +94,13 @@ class Document {
function getImmutable() { return $this->_oDocumentCore->getImmutable(); }
function setImmutable($mValue) { $this->_oDocumentCore->setImmutable($mValue); }
+ function getRestoreFolderId() { return $this->_oDocumentCore->getRestoreFolderId(); }
+ function setRestoreFolderId($iValue) { $this->_oDocumentCore->setRestoreFolderId($iValue); }
+
+ function getRestoreFolderPath() { return $this->_oDocumentCore->getRestoreFolderPath(); }
+ function setRestoreFolderPath($sValue) { $this->_oDocumentCore->setRestoreFolderPath($sValue); }
+
+
// Document Metadata Items
function getDocumentTypeID() { return $this->_oDocumentMetadataVersion->getDocumentTypeId(); }
@@ -443,6 +450,8 @@ class Document {
"Modified",
"FolderId",
"StatusId",
+ "RestoreFolderId",
+ "RestoreFolderPath",
);
$aCore = array();
diff --git a/lib/documentmanagement/documentcore.inc.php b/lib/documentmanagement/documentcore.inc.php
index 158a492..02b6d46 100644
--- a/lib/documentmanagement/documentcore.inc.php
+++ b/lib/documentmanagement/documentcore.inc.php
@@ -67,6 +67,9 @@ class KTDocumentCore extends KTEntity {
var $bIsCheckedOut;
var $iCheckedOutUserId;
+
+ var $iRestoreFolderId;
+ var $sRestoreFolderPath;
var $_aFieldToSelect = array(
"iId" => "id",
@@ -95,6 +98,10 @@ class KTDocumentCore extends KTEntity {
"iPermissionObjectId" => 'permission_object_id',
"iPermissionLookupId" => 'permission_lookup_id',
"iOwnerId" => 'owner_id',
+
+ // restore-related
+ 'iRestoreFolderId' => 'restore_folder_id',
+ 'sRestoreFolderPath' => 'restore_folder_path',
);
function KTDocument() {
@@ -136,6 +143,12 @@ class KTDocumentCore extends KTEntity {
function getImmutable() { return $this->bImmutable; }
function setImmutable($mValue) { $this->bImmutable = $mValue; }
+
+ function getRestoreFolderId() { return $this->iRestoreFolderId; }
+ function setRestoreFolderId($iValue) { $this->iRestoreFolderId = $iValue; }
+
+ function getRestoreFolderPath() { return $this->sRestoreFolderPath; }
+ function setRestoreFolderPath($sValue) { $this->sRestoreFolderPath = $sValue; }
// }}}
// {{{ getParentId
@@ -234,7 +247,9 @@ class KTDocumentCore extends KTEntity {
// {{{ update
function update($bPathMove = false) {
+ //var_dump($this); exit(0);
$res = parent::update();
+
if (($res === true) && ($bPathMove === true)) {
KTPermissionUtil::updatePermissionLookup($this);
}
diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php
index 15852a4..3a51ca2 100644
--- a/lib/documentmanagement/documentutil.inc.php
+++ b/lib/documentmanagement/documentutil.inc.php
@@ -621,7 +621,9 @@ class KTDocumentUtil {
// {{{ delete
function delete($oDocument, $sReason, $iDestFolderId = null) {
$oDocument =& KTUtil::getObject('Document', $oDocument);
- if (is_null($iDestFolderId)) { $iDestFolderId = $oDocument->getFolderID(); }
+ if (is_null($iDestFolderId)) {
+ $iDestFolderId = $oDocument->getFolderID();
+ }
$oStorageManager =& KTStorageManagerUtil::getSingleton();
global $default;
@@ -629,24 +631,34 @@ class KTDocumentUtil {
if (count(trim($sReason)) == 0) {
return PEAR::raiseError('Deletion requires a reason');
}
- if (PEAR::isError($oDocument) || ($oDocument == false)) { return PEAR::raiseError('Invalid document object.'); }
- if ($oDocument->getIsCheckedOut() == true) { return PEAR::raiseError(sprintf(_kt('The document is checked out and cannot be deleted: %s'), $oDocument->getName())); }
+ if (PEAR::isError($oDocument) || ($oDocument == false)) {
+ return PEAR::raiseError('Invalid document object.');
+ }
+
+ if ($oDocument->getIsCheckedOut() == true) {
+ return PEAR::raiseError(sprintf(_kt('The document is checked out and cannot be deleted: %s'), $oDocument->getName()));
+ }
// IF we're deleted ...
- if ($oDocument->getStatusID() == DELETED) { return true; }
-
-
- $oOrigFolder = Folder::get($oDocument->getFolderId());
-
+ if ($oDocument->getStatusID() == DELETED) {
+ return true;
+ }
+ $oOrigFolder = Folder::get($oDocument->getFolderId());
+
DBUtil::startTransaction();
- // flip the status id
+ // flip the status id
$oDocument->setStatusID(DELETED);
- $oDocument->setFolderID($iDestFolderId); // try to keep it in _this_ folder, otherwise move to root.
+
+ // $iDestFolderId is DEPRECATED.
+ $oDocument->setFolderID(null);
+ $oDocument->setRestoreFolderId($oOrigFolder->getId());
+ $oDocument->setRestoreFolderPath(Folder::generateFolderIDs($oOrigFolder->getId()));
$res = $oDocument->update();
+
if (PEAR::isError($res) || ($res == false)) {
DBUtil::rollback();
return PEAR::raiseError(_kt("There was a problem deleting the document from the database."));
diff --git a/plugins/ktcore/admin/deletedDocuments.php b/plugins/ktcore/admin/deletedDocuments.php
index 78dc19b..7a6da73 100755
--- a/plugins/ktcore/admin/deletedDocuments.php
+++ b/plugins/ktcore/admin/deletedDocuments.php
@@ -198,10 +198,10 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html';
$oStorage =& KTStorageManagerUtil::getSingleton();
foreach ($aDocuments as $oDoc) {
- $oFolder = Folder::get($oDoc->getFolderID());
+ $oFolder = Folder::get($oDoc->getRestoreFolderId());
if (PEAR::isError($oFolder)) { $oDoc->setFolderId(1); $oDoc->update(); } // move to root if parent no longer exists.
if ($oStorage->restore($oDoc)) {
- $oDoc = Document::get($oDoc->getId()); // storage path has changed for most recent object...
+ $oDoc = Document::get($oDoc->getId()); // storage path has changed for most recent object...
$oDoc->setStatusId(LIVE);
$res = $oDoc->update();
if (PEAR::isError($res) || ($res == false)) {
@@ -233,6 +233,21 @@ var $sHelpPage = 'ktcore/admin/deleted documents.html';
$this->successRedirectToMain($msg);
}
+ function getRestoreLocationFor($oDocument) {
+ $iFolderId = $oDocument->getRestoreFolderId();
+ $oFolder = Folder::get($iFolderId);
+
+ if (PEAR::isError($oFolder)) {
+ return _kt('Original folder no longer exists. Document will be restored in the root folder.');
+ } else {
+ $aCrumbs = KTBrowseUtil::breadcrumbsForFolder($oFolder);
+ $aParts = array();
+ foreach ($aCrumbs as $aInfo) {
+ $aParts[] = $aInfo['name'];
+ }
+ return implode(' » ', $aParts);
+ }
+ }
}
?>
diff --git a/sql/mysql/upgrade/3.0.3.6/document-restore.sql b/sql/mysql/upgrade/3.0.3.6/document-restore.sql
new file mode 100644
index 0000000..fd782a4
--- /dev/null
+++ b/sql/mysql/upgrade/3.0.3.6/document-restore.sql
@@ -0,0 +1,3 @@
+ALTER TABLE `documents` ADD `restore_folder_id` INT(11);
+ALTER TABLE `documents` ADD `restore_folder_path` text;
+ALTER TABLE `documents` CHANGE `folder_id` `folder_id` int(11),
\ No newline at end of file
diff --git a/templates/ktcore/document/admin/deletedlist.smarty b/templates/ktcore/document/admin/deletedlist.smarty
index 54fce35..e106727 100644
--- a/templates/ktcore/document/admin/deletedlist.smarty
+++ b/templates/ktcore/document/admin/deletedlist.smarty
@@ -23,7 +23,7 @@ can restore them as necessary.{/i18n}
{i18n}Document Name{/i18n}
-
{i18n}Document Path{/i18n}
+{*
{i18n}Document Path{/i18n}
*}
{i18n}Last Modification{/i18n}
{i18n}Deletion Comment{/i18n}
@@ -33,7 +33,7 @@ can restore them as necessary.{/i18n}
{$oDoc->getName()}
-
{getCrumbStringForDocument document=$oDoc}
+{*
{getCrumbStringForDocument document=$oDoc}
*}
{$oDoc->getLastModifiedDate()}
{$oDoc->getLastDeletionComment()}
diff --git a/templates/ktcore/document/admin/restoreconfirmlist.smarty b/templates/ktcore/document/admin/restoreconfirmlist.smarty
index 66cc54a..83edd41 100644
--- a/templates/ktcore/document/admin/restoreconfirmlist.smarty
+++ b/templates/ktcore/document/admin/restoreconfirmlist.smarty
@@ -14,12 +14,14 @@ confirm that you want to restore these documents.{/i18n}