Commit fad1cb52c319599b30d01ad36221f6a7676dc2c7

Authored by Conrad Vermeulen
1 parent 122d6a3f

KTS-2134

"Add @ in front of file functions such as unlink. There are cases that seem to break webservices because of warnings."
Fixed.

Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6859 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/documentutil.inc.php
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 * $Id$ 3 * $Id$
4 * 4 *
5 * Document-handling utility functions 5 * Document-handling utility functions
6 - * 6 + *
7 * Simplifies and canonicalises operations such as adding, updating, and 7 * Simplifies and canonicalises operations such as adding, updating, and
8 * deleting documents from the repository. 8 * deleting documents from the repository.
9 * 9 *
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 * License Version 1.1.2 ("License"); You may not use this file except in 11 * License Version 1.1.2 ("License"); You may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at 12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.knowledgetree.com/KPL 13 * http://www.knowledgetree.com/KPL
14 - * 14 + *
15 * Software distributed under the License is distributed on an "AS IS" 15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
17 * See the License for the specific language governing rights and 17 * See the License for the specific language governing rights and
@@ -22,9 +22,9 @@ @@ -22,9 +22,9 @@
22 * (ii) the KnowledgeTree copyright notice 22 * (ii) the KnowledgeTree copyright notice
23 * in the same form as they appear in the distribution. See the License for 23 * in the same form as they appear in the distribution. See the License for
24 * requirements. 24 * requirements.
25 - * 25 + *
26 * The Original Code is: KnowledgeTree Open Source 26 * The Original Code is: KnowledgeTree Open Source
27 - * 27 + *
28 * The Initial Developer of the Original Code is The Jam Warehouse Software 28 * The Initial Developer of the Original Code is The Jam Warehouse Software
29 * (Pty) Ltd, trading as KnowledgeTree. 29 * (Pty) Ltd, trading as KnowledgeTree.
30 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright 30 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
@@ -45,7 +45,7 @@ require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); @@ -45,7 +45,7 @@ require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php');
45 require_once(KT_LIB_DIR . '/filelike/filelikeutil.inc.php'); 45 require_once(KT_LIB_DIR . '/filelike/filelikeutil.inc.php');
46 require_once(KT_LIB_DIR . '/metadata/metadatautil.inc.php'); 46 require_once(KT_LIB_DIR . '/metadata/metadatautil.inc.php');
47 require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); 47 require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
48 -require_once(KT_LIB_DIR . '/subscriptions/subscriptions.inc.php'); 48 +require_once(KT_LIB_DIR . '/subscriptions/subscriptions.inc.php');
49 require_once(KT_LIB_DIR . '/triggers/triggerregistry.inc.php'); 49 require_once(KT_LIB_DIR . '/triggers/triggerregistry.inc.php');
50 require_once(KT_LIB_DIR . '/foldermanagement/Folder.inc'); 50 require_once(KT_LIB_DIR . '/foldermanagement/Folder.inc');
51 51
@@ -76,8 +76,8 @@ class KTDocumentUtil { @@ -76,8 +76,8 @@ class KTDocumentUtil {
76 $oDocument->setCheckedOutUserID(-1); 76 $oDocument->setCheckedOutUserID(-1);
77 if ($aOptions['major_update']) { 77 if ($aOptions['major_update']) {
78 $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1); 78 $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1);
79 - $oDocument->setMinorVersionNumber('0');  
80 - } else { 79 + $oDocument->setMinorVersionNumber('0');
  80 + } else {
81 $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1); 81 $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1);
82 } 82 }
83 $oDocument->setFileSize($iFileSize); 83 $oDocument->setFileSize($iFileSize);
@@ -92,10 +92,10 @@ class KTDocumentUtil { @@ -92,10 +92,10 @@ class KTDocumentUtil {
92 $default->log->info('renamed document ' . $oDocument->getId() . ' to ' . $sFilename); 92 $default->log->info('renamed document ' . $oDocument->getId() . ' to ' . $sFilename);
93 } 93 }
94 } 94 }
95 - 95 +
96 $sType = KTMime::getMimeTypeFromFile($sFilename); 96 $sType = KTMime::getMimeTypeFromFile($sFilename);
97 $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName()); 97 $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName());
98 - $oDocument->setMimeTypeId($iMimeTypeId); 98 + $oDocument->setMimeTypeId($iMimeTypeId);
99 99
100 $bSuccess = $oDocument->update(); 100 $bSuccess = $oDocument->update();
101 if ($bSuccess !== true) { 101 if ($bSuccess !== true) {
@@ -108,7 +108,7 @@ class KTDocumentUtil { @@ -108,7 +108,7 @@ class KTDocumentUtil {
108 // create the document transaction record 108 // create the document transaction record
109 $oDocumentTransaction = & new DocumentTransaction($oDocument, $sCheckInComment, 'ktcore.transactions.check_in'); 109 $oDocumentTransaction = & new DocumentTransaction($oDocument, $sCheckInComment, 'ktcore.transactions.check_in');
110 $oDocumentTransaction->create(); 110 $oDocumentTransaction->create();
111 - 111 +
112 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 112 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
113 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan'); 113 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan');
114 foreach ($aTriggers as $aTrigger) { 114 foreach ($aTriggers as $aTrigger) {
@@ -121,7 +121,7 @@ class KTDocumentUtil { @@ -121,7 +121,7 @@ class KTDocumentUtil {
121 return $ret; 121 return $ret;
122 } 122 }
123 } 123 }
124 - 124 +
125 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform'); 125 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform');
126 foreach ($aTriggers as $aTrigger) { 126 foreach ($aTriggers as $aTrigger) {
127 $sTrigger = $aTrigger[0]; 127 $sTrigger = $aTrigger[0];
@@ -132,14 +132,14 @@ class KTDocumentUtil { @@ -132,14 +132,14 @@ class KTDocumentUtil {
132 $oTrigger->setDocument($oDocument); 132 $oTrigger->setDocument($oDocument);
133 $oTrigger->transform(); 133 $oTrigger->transform();
134 } 134 }
135 - 135 +
136 // fire subscription alerts for the checked in document 136 // fire subscription alerts for the checked in document
137 $oSubscriptionEvent = new SubscriptionEvent(); 137 $oSubscriptionEvent = new SubscriptionEvent();
138 $oFolder = Folder::get($oDocument->getFolderID()); 138 $oFolder = Folder::get($oDocument->getFolderID());
139 $oSubscriptionEvent->CheckinDocument($oDocument, $oFolder); 139 $oSubscriptionEvent->CheckinDocument($oDocument, $oFolder);
140 - 140 +
141 KTDocumentUtil::updateSearchableText($oDocument); 141 KTDocumentUtil::updateSearchableText($oDocument);
142 - 142 +
143 return true; 143 return true;
144 } 144 }
145 145
@@ -147,9 +147,9 @@ class KTDocumentUtil { @@ -147,9 +147,9 @@ class KTDocumentUtil {
147 if ($oDocument->getIsCheckedOut()) { 147 if ($oDocument->getIsCheckedOut()) {
148 return PEAR::raiseError(_kt('Already checked out.')); 148 return PEAR::raiseError(_kt('Already checked out.'));
149 } 149 }
150 - 150 +
151 // FIXME at the moment errors this _does not_ rollback. 151 // FIXME at the moment errors this _does not_ rollback.
152 - 152 +
153 $oDocument->setIsCheckedOut(true); 153 $oDocument->setIsCheckedOut(true);
154 $oDocument->setCheckedOutUserID($oUser->getId()); 154 $oDocument->setCheckedOutUserID($oUser->getId());
155 if (!$oDocument->update()) { return PEAR::raiseError(_kt('There was a problem checking out the document.')); } 155 if (!$oDocument->update()) { return PEAR::raiseError(_kt('There was a problem checking out the document.')); }
@@ -176,13 +176,13 @@ class KTDocumentUtil { @@ -176,13 +176,13 @@ class KTDocumentUtil {
176 $oSubscriptionEvent = new SubscriptionEvent(); 176 $oSubscriptionEvent = new SubscriptionEvent();
177 $oFolder = Folder::get($oDocument->getFolderID()); 177 $oFolder = Folder::get($oDocument->getFolderID());
178 $oSubscriptionEvent->CheckOutDocument($oDocument, $oFolder); 178 $oSubscriptionEvent->CheckOutDocument($oDocument, $oFolder);
179 - 179 +
180 return true; 180 return true;
181 } 181 }
182 182
183 function &_add($oFolder, $sFilename, $oUser, $aOptions) { 183 function &_add($oFolder, $sFilename, $oUser, $aOptions) {
184 global $default; 184 global $default;
185 - 185 +
186 $oContents = KTUtil::arrayGet($aOptions, 'contents'); 186 $oContents = KTUtil::arrayGet($aOptions, 'contents');
187 $aMetadata = KTUtil::arrayGet($aOptions, 'metadata', null, false); 187 $aMetadata = KTUtil::arrayGet($aOptions, 'metadata', null, false);
188 $oDocumentType = KTUtil::arrayGet($aOptions, 'documenttype'); 188 $oDocumentType = KTUtil::arrayGet($aOptions, 'documenttype');
@@ -274,17 +274,17 @@ class KTDocumentUtil { @@ -274,17 +274,17 @@ class KTDocumentUtil {
274 $aFieldValues[$oField->getId()] = $v; 274 $aFieldValues[$oField->getId()] = $v;
275 } 275 }
276 } 276 }
277 - 277 +
278 if ($isRealConditional) { 278 if ($isRealConditional) {
279 $res = KTMetadataUtil::getNext($oFieldset, $aFieldValues); 279 $res = KTMetadataUtil::getNext($oFieldset, $aFieldValues);
280 if ($res) { 280 if ($res) {
281 foreach ($res as $aMDSet) { 281 foreach ($res as $aMDSet) {
282 if ($aMDSet['field']->getIsMandatory()) { 282 if ($aMDSet['field']->getIsMandatory()) {
283 - $aFailed['fieldset'][$oFieldset->getId()] = 1; 283 + $aFailed['fieldset'][$oFieldset->getId()] = 1;
284 } 284 }
285 } 285 }
286 - }  
287 - } 286 + }
  287 + }
288 } 288 }
289 if (!empty($aFailed)) { 289 if (!empty($aFailed)) {
290 return new KTMetadataValidationError($aFailed); 290 return new KTMetadataValidationError($aFailed);
@@ -304,7 +304,7 @@ class KTDocumentUtil { @@ -304,7 +304,7 @@ class KTDocumentUtil {
304 return $res; 304 return $res;
305 } 305 }
306 $aMetadata = empty($res)?array():$res; 306 $aMetadata = empty($res)?array():$res;
307 - 307 +
308 $iMetadataVersionId = $oDocument->getMetadataVersionId(); 308 $iMetadataVersionId = $oDocument->getMetadataVersionId();
309 $res = DBUtil::runQuery(array("DELETE FROM $table WHERE metadata_version_id = ?", array($iMetadataVersionId))); 309 $res = DBUtil::runQuery(array("DELETE FROM $table WHERE metadata_version_id = ?", array($iMetadataVersionId)));
310 if (PEAR::isError($res)) { 310 if (PEAR::isError($res)) {
@@ -341,7 +341,7 @@ class KTDocumentUtil { @@ -341,7 +341,7 @@ class KTDocumentUtil {
341 $aRow['metadata_version_id'] = $iNewMetadataVersion; 341 $aRow['metadata_version_id'] = $iNewMetadataVersion;
342 DBUtil::autoInsert($sTable, $aRow); 342 DBUtil::autoInsert($sTable, $aRow);
343 } 343 }
344 - 344 +
345 } 345 }
346 346
347 // {{{ setIncomplete 347 // {{{ setIncomplete
@@ -428,7 +428,7 @@ class KTDocumentUtil { @@ -428,7 +428,7 @@ class KTDocumentUtil {
428 if (KTDocumentUtil::fileExists($oFolder, $sFilename)) { 428 if (KTDocumentUtil::fileExists($oFolder, $sFilename)) {
429 $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId()); 429 $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId());
430 if (PEAR::isError($oDoc)) { 430 if (PEAR::isError($oDoc)) {
431 - return PEAR::raiseError(_kt('Document with that filename already exists in this folder, and appears to be invalid. Please contact the system administrator.')); 431 + return PEAR::raiseError(_kt('Document with that filename already exists in this folder, and appears to be invalid. Please contact the system administrator.'));
432 } else { 432 } else {
433 if ($oDoc->getStatusID() != LIVE) { 433 if ($oDoc->getStatusID() != LIVE) {
434 $sError = _kt('Document with that filename already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.'); 434 $sError = _kt('Document with that filename already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.');
@@ -444,7 +444,7 @@ class KTDocumentUtil { @@ -444,7 +444,7 @@ class KTDocumentUtil {
444 if (KTDocumentUtil::nameExists($oFolder, $sName)) { 444 if (KTDocumentUtil::nameExists($oFolder, $sName)) {
445 $oDoc = Document::getByNameAndFolder($sName, $oFolder->getId()); 445 $oDoc = Document::getByNameAndFolder($sName, $oFolder->getId());
446 if (PEAR::isError($oDoc)) { 446 if (PEAR::isError($oDoc)) {
447 - return PEAR::raiseError(_kt('Document with that title already exists in this folder, and appears to be invalid. Please contact the system administrator.')); 447 + return PEAR::raiseError(_kt('Document with that title already exists in this folder, and appears to be invalid. Please contact the system administrator.'));
448 } else { 448 } else {
449 if ($oDoc->getStatusID != LIVE) { 449 if ($oDoc->getStatusID != LIVE) {
450 return PEAR::raiseError(_kt('Document with that title already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.')); 450 return PEAR::raiseError(_kt('Document with that title already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.'));
@@ -452,7 +452,7 @@ class KTDocumentUtil { @@ -452,7 +452,7 @@ class KTDocumentUtil {
452 return PEAR::raiseError(_kt('Document with that title already exists in this folder.')); 452 return PEAR::raiseError(_kt('Document with that title already exists in this folder.'));
453 } 453 }
454 } 454 }
455 - 455 +
456 } 456 }
457 457
458 $oUploadChannel =& KTUploadChannel::getSingleton(); 458 $oUploadChannel =& KTUploadChannel::getSingleton();
@@ -508,10 +508,10 @@ class KTDocumentUtil { @@ -508,10 +508,10 @@ class KTDocumentUtil {
508 $oSubscriptionEvent = new SubscriptionEvent(); 508 $oSubscriptionEvent = new SubscriptionEvent();
509 $oFolder = Folder::get($oDocument->getFolderID()); 509 $oFolder = Folder::get($oDocument->getFolderID());
510 $oSubscriptionEvent->AddDocument($oDocument, $oFolder); 510 $oSubscriptionEvent->AddDocument($oDocument, $oFolder);
511 - 511 +
512 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 512 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
513 $aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate'); 513 $aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate');
514 - 514 +
515 foreach ($aTriggers as $aTrigger) { 515 foreach ($aTriggers as $aTrigger) {
516 $sTrigger = $aTrigger[0]; 516 $sTrigger = $aTrigger[0];
517 $oTrigger = new $sTrigger; 517 $oTrigger = new $sTrigger;
@@ -521,7 +521,7 @@ class KTDocumentUtil { @@ -521,7 +521,7 @@ class KTDocumentUtil {
521 ); 521 );
522 $oTrigger->setInfo($aInfo); 522 $oTrigger->setInfo($aInfo);
523 $ret = $oTrigger->postValidate(); 523 $ret = $oTrigger->postValidate();
524 - 524 +
525 } 525 }
526 KTDocumentUtil::updateSearchableText($oDocument, true); 526 KTDocumentUtil::updateSearchableText($oDocument, true);
527 527
@@ -555,16 +555,16 @@ class KTDocumentUtil { @@ -555,16 +555,16 @@ class KTDocumentUtil {
555 $oStorage =& KTStorageManagerUtil::getSingleton(); 555 $oStorage =& KTStorageManagerUtil::getSingleton();
556 556
557 $oKTConfig =& KTConfig::getSingleton(); 557 $oKTConfig =& KTConfig::getSingleton();
558 - $sBasedir = $oKTConfig->get('urls/tmpDirectory');  
559 - 558 + $sBasedir = $oKTConfig->get('urls/tmpDirectory');
  559 +
560 $sFilename = tempnam($sBasedir, 'kt_storecontents'); 560 $sFilename = tempnam($sBasedir, 'kt_storecontents');
561 $oOutputFile = new KTFSFileLike($sFilename); 561 $oOutputFile = new KTFSFileLike($sFilename);
562 $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); 562 $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile);
563 - if (($res === false)) { 563 + if (($res === false)) {
564 return PEAR::raiseError(_kt("Couldn't store contents, and no reason given.")); 564 return PEAR::raiseError(_kt("Couldn't store contents, and no reason given."));
565 } else if (PEAR::isError($res)) { 565 } else if (PEAR::isError($res)) {
566 return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage())); 566 return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage()));
567 - } 567 + }
568 $sType = KTMime::getMimeTypeFromFile($sFilename); 568 $sType = KTMime::getMimeTypeFromFile($sFilename);
569 $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName()); 569 $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName());
570 $oDocument->setMimeTypeId($iMimeTypeId); 570 $oDocument->setMimeTypeId($iMimeTypeId);
@@ -576,11 +576,11 @@ class KTDocumentUtil { @@ -576,11 +576,11 @@ class KTDocumentUtil {
576 return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage())); 576 return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage()));
577 } 577 }
578 KTDocumentUtil::setComplete($oDocument, 'contents'); 578 KTDocumentUtil::setComplete($oDocument, 'contents');
579 - 579 +
580 if ($aOptions['cleanup_initial_file']) { 580 if ($aOptions['cleanup_initial_file']) {
581 - unlink($oContents->sFilename); 581 + @unlink($oContents->sFilename);
582 } 582 }
583 - 583 +
584 return true; 584 return true;
585 } 585 }
586 // }}} 586 // }}}
@@ -644,48 +644,48 @@ class KTDocumentUtil { @@ -644,48 +644,48 @@ class KTDocumentUtil {
644 return DBUtil::autoInsert($sTable, $aInsert, array('noid' => true)); 644 return DBUtil::autoInsert($sTable, $aInsert, array('noid' => true));
645 } 645 }
646 // }}} 646 // }}}
647 - 647 +
648 // {{{ delete 648 // {{{ delete
649 function delete($oDocument, $sReason, $iDestFolderId = null) { 649 function delete($oDocument, $sReason, $iDestFolderId = null) {
650 $oDocument =& KTUtil::getObject('Document', $oDocument); 650 $oDocument =& KTUtil::getObject('Document', $oDocument);
651 - if (is_null($iDestFolderId)) {  
652 - $iDestFolderId = $oDocument->getFolderID(); 651 + if (is_null($iDestFolderId)) {
  652 + $iDestFolderId = $oDocument->getFolderID();
653 } 653 }
654 $oStorageManager =& KTStorageManagerUtil::getSingleton(); 654 $oStorageManager =& KTStorageManagerUtil::getSingleton();
655 - 655 +
656 global $default; 656 global $default;
657 -  
658 - if (count(trim($sReason)) == 0) {  
659 - return PEAR::raiseError(_kt('Deletion requires a reason')); 657 +
  658 + if (count(trim($sReason)) == 0) {
  659 + return PEAR::raiseError(_kt('Deletion requires a reason'));
660 } 660 }
661 -  
662 - if (PEAR::isError($oDocument) || ($oDocument == false)) {  
663 - return PEAR::raiseError(_kt('Invalid document object.')); 661 +
  662 + if (PEAR::isError($oDocument) || ($oDocument == false)) {
  663 + return PEAR::raiseError(_kt('Invalid document object.'));
664 } 664 }
665 -  
666 - if ($oDocument->getIsCheckedOut() == true) {  
667 - return PEAR::raiseError(sprintf(_kt('The document is checked out and cannot be deleted: %s'), $oDocument->getName())); 665 +
  666 + if ($oDocument->getIsCheckedOut() == true) {
  667 + return PEAR::raiseError(sprintf(_kt('The document is checked out and cannot be deleted: %s'), $oDocument->getName()));
668 } 668 }
669 - 669 +
670 // IF we're deleted ... 670 // IF we're deleted ...
671 - if ($oDocument->getStatusID() == DELETED) {  
672 - return true; 671 + if ($oDocument->getStatusID() == DELETED) {
  672 + return true;
673 } 673 }
674 - 674 +
675 $oOrigFolder = Folder::get($oDocument->getFolderId()); 675 $oOrigFolder = Folder::get($oDocument->getFolderId());
676 676
677 DBUtil::startTransaction(); 677 DBUtil::startTransaction();
678 - 678 +
679 // flip the status id 679 // flip the status id
680 $oDocument->setStatusID(DELETED); 680 $oDocument->setStatusID(DELETED);
681 - 681 +
682 // $iDestFolderId is DEPRECATED. 682 // $iDestFolderId is DEPRECATED.
683 - $oDocument->setFolderID(null); 683 + $oDocument->setFolderID(null);
684 $oDocument->setRestoreFolderId($oOrigFolder->getId()); 684 $oDocument->setRestoreFolderId($oOrigFolder->getId());
685 $oDocument->setRestoreFolderPath(Folder::generateFolderIDs($oOrigFolder->getId())); 685 $oDocument->setRestoreFolderPath(Folder::generateFolderIDs($oOrigFolder->getId()));
686 - 686 +
687 $res = $oDocument->update(); 687 $res = $oDocument->update();
688 - 688 +
689 if (PEAR::isError($res) || ($res == false)) { 689 if (PEAR::isError($res) || ($res == false)) {
690 DBUtil::rollback(); 690 DBUtil::rollback();
691 return PEAR::raiseError(_kt('There was a problem deleting the document from the database.')); 691 return PEAR::raiseError(_kt('There was a problem deleting the document from the database.'));
@@ -699,35 +699,35 @@ class KTDocumentUtil { @@ -699,35 +699,35 @@ class KTDocumentUtil {
699 $oDocument->getFileName() . ' from folder ' . 699 $oDocument->getFileName() . ' from folder ' .
700 Folder::getFolderPath($oDocument->getFolderID()) . 700 Folder::getFolderPath($oDocument->getFolderID()) .
701 ' id=' . $oDocument->getFolderID()); 701 ' id=' . $oDocument->getFolderID());
702 - 702 +
703 // we use a _real_ transaction here ... 703 // we use a _real_ transaction here ...
704 - 704 +
705 DBUtil::rollback(); 705 DBUtil::rollback();
706 - 706 +
707 /* 707 /*
708 //reverse the document deletion 708 //reverse the document deletion
709 $oDocument->setStatusID(LIVE); 709 $oDocument->setStatusID(LIVE);
710 $oDocument->update(); 710 $oDocument->update();
711 */ 711 */
712 - 712 +
713 return PEAR::raiseError(_kt('There was a problem deleting the document from storage.')); 713 return PEAR::raiseError(_kt('There was a problem deleting the document from storage.'));
714 } 714 }
715 - 715 +
716 $oDocumentTransaction = & new DocumentTransaction($oDocument, _kt('Document deleted: ') . $sReason, 'ktcore.transactions.delete'); 716 $oDocumentTransaction = & new DocumentTransaction($oDocument, _kt('Document deleted: ') . $sReason, 'ktcore.transactions.delete');
717 $oDocumentTransaction->create(); 717 $oDocumentTransaction->create();
718 - 718 +
719 $oDocument->setFolderID(1); 719 $oDocument->setFolderID(1);
720 - 720 +
721 DBUtil::commit(); 721 DBUtil::commit();
722 722
723 - 723 +
724 // we weren't doing notifications on this one 724 // we weren't doing notifications on this one
725 $oSubscriptionEvent = new SubscriptionEvent(); 725 $oSubscriptionEvent = new SubscriptionEvent();
726 $oSubscriptionEvent->RemoveDocument($oDocument, $oOrigFolder); 726 $oSubscriptionEvent->RemoveDocument($oDocument, $oOrigFolder);
727 727
728 - 728 +
729 // document is now deleted: triggers are best-effort. 729 // document is now deleted: triggers are best-effort.
730 - 730 +
731 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 731 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
732 $aTriggers = $oKTTriggerRegistry->getTriggers('delete', 'postValidate'); 732 $aTriggers = $oKTTriggerRegistry->getTriggers('delete', 'postValidate');
733 foreach ($aTriggers as $aTrigger) { 733 foreach ($aTriggers as $aTrigger) {
@@ -743,11 +743,11 @@ class KTDocumentUtil { @@ -743,11 +743,11 @@ class KTDocumentUtil {
743 return $ret; 743 return $ret;
744 } 744 }
745 } 745 }
746 -  
747 - 746 +
  747 +
748 } 748 }
749 // }}} 749 // }}}
750 - 750 +
751 function reindexDocument($oDocument) { 751 function reindexDocument($oDocument) {
752 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 752 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
753 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform'); 753 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform');
@@ -780,7 +780,7 @@ class KTDocumentUtil { @@ -780,7 +780,7 @@ class KTDocumentUtil {
780 // 2. update the storage path. 780 // 2. update the storage path.
781 //print '--------------------------------- BEFORE'; 781 //print '--------------------------------- BEFORE';
782 //print_r($oDocument); 782 //print_r($oDocument);
783 - 783 +
784 // grab the "source "data 784 // grab the "source "data
785 $sTable = KTUtil::getTableName('documents'); 785 $sTable = KTUtil::getTableName('documents');
786 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?'; 786 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?';
@@ -793,7 +793,7 @@ class KTDocumentUtil { @@ -793,7 +793,7 @@ class KTDocumentUtil {
793 if (PEAR::isError($id)) { return $id; } 793 if (PEAR::isError($id)) { return $id; }
794 // we still have a bogus md_version, but integrity holds, so fix it now. 794 // we still have a bogus md_version, but integrity holds, so fix it now.
795 $oCore = KTDocumentCore::get($id); 795 $oCore = KTDocumentCore::get($id);
796 - 796 +
797 $sTable = KTUtil::getTableName('document_metadata_version'); 797 $sTable = KTUtil::getTableName('document_metadata_version');
798 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?'; 798 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?';
799 $aParams = array($oDocument->getMetadataVersionId()); 799 $aParams = array($oDocument->getMetadataVersionId());
@@ -804,7 +804,7 @@ class KTDocumentUtil { @@ -804,7 +804,7 @@ class KTDocumentUtil {
804 if (PEAR::isError($id)) { return $id; } 804 if (PEAR::isError($id)) { return $id; }
805 $oCore->setMetadataVersionId($id); 805 $oCore->setMetadataVersionId($id);
806 $oMDV = KTDocumentMetadataVersion::get($id); 806 $oMDV = KTDocumentMetadataVersion::get($id);
807 - 807 +
808 $sTable = KTUtil::getTableName('document_content_version'); 808 $sTable = KTUtil::getTableName('document_content_version');
809 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?'; 809 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?';
810 $aParams = array($oDocument->_oDocumentContentVersion->getId()); 810 $aParams = array($oDocument->_oDocumentContentVersion->getId());
@@ -814,24 +814,24 @@ class KTDocumentUtil { @@ -814,24 +814,24 @@ class KTDocumentUtil {
814 $id = DBUtil::autoInsert($sTable, $aContentRow); 814 $id = DBUtil::autoInsert($sTable, $aContentRow);
815 if (PEAR::isError($id)) { return $id; } 815 if (PEAR::isError($id)) { return $id; }
816 $oMDV->setContentVersionId($id); 816 $oMDV->setContentVersionId($id);
817 - 817 +
818 $res = $oCore->update(); 818 $res = $oCore->update();
819 if (PEAR::isError($res)) { return $res; } 819 if (PEAR::isError($res)) { return $res; }
820 $res = $oMDV->update(); 820 $res = $oMDV->update();
821 if (PEAR::isError($res)) { return $res; } 821 if (PEAR::isError($res)) { return $res; }
822 - 822 +
823 // now, we have a semi-sane document object. get it. 823 // now, we have a semi-sane document object. get it.
824 $oNewDocument = Document::get($oCore->getId()); 824 $oNewDocument = Document::get($oCore->getId());
825 - 825 +
826 //print '--------------------------------- AFTER'; 826 //print '--------------------------------- AFTER';
827 //print_r($oDocument); 827 //print_r($oDocument);
828 //print '======'; 828 //print '======';
829 //print_r($oNewDocument); 829 //print_r($oNewDocument);
830 - 830 +
831 // copy the metadata from old to new. 831 // copy the metadata from old to new.
832 $res = KTDocumentUtil::copyMetadata($oNewDocument, $oDocument->getMetadataVersionId()); 832 $res = KTDocumentUtil::copyMetadata($oNewDocument, $oDocument->getMetadataVersionId());
833 if (PEAR::isError($res)) { return $res; } 833 if (PEAR::isError($res)) { return $res; }
834 - 834 +
835 // finally, copy the actual file. 835 // finally, copy the actual file.
836 $oStorage =& KTStorageManagerUtil::getSingleton(); 836 $oStorage =& KTStorageManagerUtil::getSingleton();
837 $res = $oStorage->copy($oDocument, $oNewDocument); 837 $res = $oStorage->copy($oDocument, $oNewDocument);
@@ -844,7 +844,7 @@ class KTDocumentUtil { @@ -844,7 +844,7 @@ class KTDocumentUtil {
844 if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) { 844 if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) {
845 $oNewDocument->setPermissionObjectId($oDestinationFolder->getPermissionObjectId()); 845 $oNewDocument->setPermissionObjectId($oDestinationFolder->getPermissionObjectId());
846 } 846 }
847 - 847 +
848 $res = $oNewDocument->update(); 848 $res = $oNewDocument->update();
849 if (PEAR::isError($res)) { return $res; } 849 if (PEAR::isError($res)) { return $res; }
850 850
@@ -859,19 +859,19 @@ class KTDocumentUtil { @@ -859,19 +859,19 @@ class KTDocumentUtil {
859 DBUtil::autoInsert($sTable, $aInsertValues, array('noid' => true)); 859 DBUtil::autoInsert($sTable, $aInsertValues, array('noid' => true));
860 KTDocumentUtil::updateSearchableText($oNewDocument); 860 KTDocumentUtil::updateSearchableText($oNewDocument);
861 KTPermissionUtil::updatePermissionLookup($oNewDocument); 861 KTPermissionUtil::updatePermissionLookup($oNewDocument);
862 - 862 +
863 if (is_null($sReason)) { 863 if (is_null($sReason)) {
864 $sReason = ''; 864 $sReason = '';
865 } 865 }
866 -  
867 - 866 +
  867 +
868 $oDocumentTransaction = & new DocumentTransaction($oDocument, sprintf(_kt("Copied to folder \"%s\". %s"), $oDestinationFolder->getName(), $sReason), 'ktcore.transactions.copy'); 868 $oDocumentTransaction = & new DocumentTransaction($oDocument, sprintf(_kt("Copied to folder \"%s\". %s"), $oDestinationFolder->getName(), $sReason), 'ktcore.transactions.copy');
869 - $oDocumentTransaction->create(); 869 + $oDocumentTransaction->create();
870 870
871 $oSrcFolder = Folder::get($oDocument->getFolderID()); 871 $oSrcFolder = Folder::get($oDocument->getFolderID());
872 $oDocumentTransaction = & new DocumentTransaction($oNewDocument, sprintf(_kt("Copied from original in folder \"%s\". %s"), $oSrcFolder->getName(), $sReason), 'ktcore.transactions.copy'); 872 $oDocumentTransaction = & new DocumentTransaction($oNewDocument, sprintf(_kt("Copied from original in folder \"%s\". %s"), $oSrcFolder->getName(), $sReason), 'ktcore.transactions.copy');
873 - $oDocumentTransaction->create();  
874 - 873 + $oDocumentTransaction->create();
  874 +
875 return $oNewDocument; 875 return $oNewDocument;
876 } 876 }
877 877
@@ -906,19 +906,19 @@ class KTDocumentUtil { @@ -906,19 +906,19 @@ class KTDocumentUtil {
906 // create the document transaction record 906 // create the document transaction record
907 $oDocumentTransaction = & new DocumentTransaction($oDocument, _kt('Document renamed'), 'ktcore.transactions.update'); 907 $oDocumentTransaction = & new DocumentTransaction($oDocument, _kt('Document renamed'), 'ktcore.transactions.update');
908 $oDocumentTransaction->create(); 908 $oDocumentTransaction->create();
909 - 909 +
910 // fire subscription alerts for the checked in document 910 // fire subscription alerts for the checked in document
911 $oSubscriptionEvent = new SubscriptionEvent(); 911 $oSubscriptionEvent = new SubscriptionEvent();
912 $oFolder = Folder::get($oDocument->getFolderID()); 912 $oFolder = Folder::get($oDocument->getFolderID());
913 $oSubscriptionEvent->ModifyDocument($oDocument, $oFolder); 913 $oSubscriptionEvent->ModifyDocument($oDocument, $oFolder);
914 -  
915 - return true; 914 +
  915 + return true;
916 } 916 }
917 - 917 +
918 function move($oDocument, $oToFolder, $oUser = null, $sReason = null) { 918 function move($oDocument, $oToFolder, $oUser = null, $sReason = null) {
919 -  
920 - $oFolder = $oToFolder; // alias.  
921 - 919 +
  920 + $oFolder = $oToFolder; // alias.
  921 +
922 $oOriginalFolder = Folder::get($oDocument->getFolderId()); 922 $oOriginalFolder = Folder::get($oDocument->getFolderId());
923 $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId(); 923 $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId();
924 $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId(); 924 $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId();
@@ -949,13 +949,13 @@ class KTDocumentUtil { @@ -949,13 +949,13 @@ class KTDocumentUtil {
949 949
950 $sMoveMessage = sprintf(_kt("Moved from %s/%s to %s/%s. %s"), 950 $sMoveMessage = sprintf(_kt("Moved from %s/%s to %s/%s. %s"),
951 $oOriginalFolder->getFullPath(), 951 $oOriginalFolder->getFullPath(),
952 - $oOriginalFolder->getName(), 952 + $oOriginalFolder->getName(),
953 $oFolder->getFullPath(), 953 $oFolder->getFullPath(),
954 $oFolder->getName(), 954 $oFolder->getName(),
955 $sReason); 955 $sReason);
956 956
957 // create the document transaction record 957 // create the document transaction record
958 - 958 +
959 $oDocumentTransaction = & new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move'); 959 $oDocumentTransaction = & new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move');
960 $oDocumentTransaction->create(); 960 $oDocumentTransaction->create();
961 961
@@ -975,8 +975,8 @@ class KTDocumentUtil { @@ -975,8 +975,8 @@ class KTDocumentUtil {
975 if (PEAR::isError($ret)) { 975 if (PEAR::isError($ret)) {
976 return $ret; 976 return $ret;
977 } 977 }
978 - }  
979 - 978 + }
  979 +
980 return KTPermissionUtil::updatePermissionLookup($oDocument); 980 return KTPermissionUtil::updatePermissionLookup($oDocument);
981 } 981 }
982 982