Commit ffaadefb320be5761ca6d40ee6d62b2f789aa4f4

Authored by Brad Shuttleworth
1 parent 95637c20

Brad Shuttleworth 2006-02-16 copy unit-tests

Brad Shuttleworth 2006-02-15 documentutil::checkout was broken by me.
    Brad Shuttleworth 2006-02-15 fix for KTS-XXX: IE blows up on manage cond...
    Brad Shuttleworth 2006-02-15 folder and document copy.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4928 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/documentutil.inc.php
@@ -125,9 +125,9 @@ class KTDocumentUtil { @@ -125,9 +125,9 @@ class KTDocumentUtil {
125 125
126 // FIXME at the moment errors this _does not_ rollback. 126 // FIXME at the moment errors this _does not_ rollback.
127 127
128 - $this->oDocument->setIsCheckedOut(true);  
129 - $this->oDocument->setCheckedOutUserID($oUser->getId());  
130 - if (!$this->oDocument->update()) { return PEAR::raiseError(_("There was a problem checking out the document.")); } 128 + $oDocument->setIsCheckedOut(true);
  129 + $oDocument->setCheckedOutUserID($oUser->getId());
  130 + if (!$oDocument->update()) { return PEAR::raiseError(_("There was a problem checking out the document.")); }
131 131
132 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 132 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
133 $aTriggers = $oKTTriggerRegistry->getTriggers('checkout', 'postValidate'); 133 $aTriggers = $oKTTriggerRegistry->getTriggers('checkout', 'postValidate');
@@ -646,7 +646,8 @@ class KTDocumentUtil { @@ -646,7 +646,8 @@ class KTDocumentUtil {
646 function copy($oDocument, $oDestinationFolder) { 646 function copy($oDocument, $oDestinationFolder) {
647 // 1. generate a new triad of content, metadata and core objects. 647 // 1. generate a new triad of content, metadata and core objects.
648 // 2. update the storage path. 648 // 2. update the storage path.
649 - 649 + //print '--------------------------------- BEFORE';
  650 + //print_r($oDocument);
650 651
651 // grab the "source "data 652 // grab the "source "data
652 $sTable = KTUtil::getTableName('documents'); 653 $sTable = KTUtil::getTableName('documents');
@@ -690,6 +691,11 @@ class KTDocumentUtil { @@ -690,6 +691,11 @@ class KTDocumentUtil {
690 // now, we have a semi-sane document object. get it. 691 // now, we have a semi-sane document object. get it.
691 $oNewDocument = Document::get($oCore->getId()); 692 $oNewDocument = Document::get($oCore->getId());
692 693
  694 + //print '--------------------------------- AFTER';
  695 + //print_r($oDocument);
  696 + //print '======';
  697 + //print_r($oNewDocument);
  698 +
693 // copy the metadata from old to new. 699 // copy the metadata from old to new.
694 $res = KTDocumentUtil::copyMetadata($oNewDocument, $oDocument->getMetadataVersionId()); 700 $res = KTDocumentUtil::copyMetadata($oNewDocument, $oDocument->getMetadataVersionId());
695 if (PEAR::isError($res)) { return $res; } 701 if (PEAR::isError($res)) { return $res; }
lib/foldermanagement/folderutil.inc.php
@@ -260,7 +260,10 @@ class KTFolderUtil { @@ -260,7 +260,10 @@ class KTFolderUtil {
260 return true; 260 return true;
261 } 261 }
262 262
263 - function copy($oFolder, $oDestFolder, $oUser, $sReason) { 263 + function copy($oSrcFolder, $oDestFolder, $oUser, $sReason) {
  264 + if (KTFolderUtil::exists($oDestFolder, $oSrcFolder->getName())) {
  265 + return PEAR::raiseError("Folder with the same name already exists in the new parent folder");
  266 + }
264 // 267 //
265 // FIXME the failure cleanup code here needs some serious work. 268 // FIXME the failure cleanup code here needs some serious work.
266 // 269 //
@@ -276,7 +279,7 @@ class KTFolderUtil { @@ -276,7 +279,7 @@ class KTFolderUtil {
276 $aFailedDocuments = array(); // of String 279 $aFailedDocuments = array(); // of String
277 $aFailedFolders = array(); // of String 280 $aFailedFolders = array(); // of String
278 281
279 - $aRemainingFolders = array($oFolder->getId()); 282 + $aRemainingFolders = array($oSrcFolder->getId());
280 283
281 DBUtil::startTransaction(); 284 DBUtil::startTransaction();
282 285
@@ -332,7 +335,7 @@ class KTFolderUtil { @@ -332,7 +335,7 @@ class KTFolderUtil {
332 335
333 $sTable = KTUtil::getTableName('folders'); 336 $sTable = KTUtil::getTableName('folders');
334 $sGetQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ? '; 337 $sGetQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ? ';
335 - $aParams = array($oFolder->getId()); 338 + $aParams = array($oSrcFolder->getId());
336 $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams)); 339 $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams));
337 unset($aRow['id']); 340 unset($aRow['id']);
338 $aRow['parent_id'] = $oDestFolder->getId(); 341 $aRow['parent_id'] = $oDestFolder->getId();
@@ -341,7 +344,7 @@ class KTFolderUtil { @@ -341,7 +344,7 @@ class KTFolderUtil {
341 DBUtil::rollback(); 344 DBUtil::rollback();
342 return $id; 345 return $id;
343 } 346 }
344 - $aFolderMap[$oFolder->getId()] = $id; 347 + $aFolderMap[$oSrcFolder->getId()] = $id;
345 $oNewBaseFolder = Folder::get($id); 348 $oNewBaseFolder = Folder::get($id);
346 $res = $oStorage->createFolder($oNewBaseFolder); 349 $res = $oStorage->createFolder($oNewBaseFolder);
347 if (PEAR::isError($res)) { 350 if (PEAR::isError($res)) {
@@ -349,7 +352,7 @@ class KTFolderUtil { @@ -349,7 +352,7 @@ class KTFolderUtil {
349 DBUtil::rollback(); 352 DBUtil::rollback();
350 return $res; 353 return $res;
351 } 354 }
352 - $aRemainingFolders = Folder::getList(array('parent_id = ?', array($oFolder->getId())), array('ids' => true)); 355 + $aRemainingFolders = Folder::getList(array('parent_id = ?', array($oSrcFolder->getId())), array('ids' => true));
353 356
354 357
355 while (!empty($aRemainingFolders)) { 358 while (!empty($aRemainingFolders)) {
@@ -364,10 +367,12 @@ class KTFolderUtil { @@ -364,10 +367,12 @@ class KTFolderUtil {
364 367
365 $id = DBUtil::autoInsert($sTable, $aRow); 368 $id = DBUtil::autoInsert($sTable, $aRow);
366 if (PEAR::isError($id)) { 369 if (PEAR::isError($id)) {
  370 + $oStorage->removeFolder($oNewBaseFolder);
367 DBUtil::rollback(); 371 DBUtil::rollback();
368 return $id; 372 return $id;
369 } 373 }
370 $aFolderMap[$iFolderId] = $id; 374 $aFolderMap[$iFolderId] = $id;
  375 +
371 $oNewFolder = Folder::get($id); 376 $oNewFolder = Folder::get($id);
372 $res = $oStorage->createFolder($oNewFolder); 377 $res = $oStorage->createFolder($oNewFolder);
373 if (PEAR::isError($res)) { 378 if (PEAR::isError($res)) {
@@ -382,12 +387,15 @@ class KTFolderUtil { @@ -382,12 +387,15 @@ class KTFolderUtil {
382 } 387 }
383 388
384 389
  390 + var_dump($aFolderMap);
385 391
386 // now we can go ahead. 392 // now we can go ahead.
387 foreach ($aDocuments as $oDocument) { 393 foreach ($aDocuments as $oDocument) {
388 $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]); 394 $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]);
  395 + var_dump($oDocument->getFolderID());
389 $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder); 396 $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder);
390 if (PEAR::isError($res) || ($res === false)) { 397 if (PEAR::isError($res) || ($res === false)) {
  398 + $oStorage->removeFolder($oNewBaseFolder);
391 DBUtil::rollback(); 399 DBUtil::rollback();
392 return PEAR::raiseError(_('Delete Aborted. Unexpected failure to copydocument: ') . $oDocument->getName() . $res->getMessage()); 400 return PEAR::raiseError(_('Delete Aborted. Unexpected failure to copydocument: ') . $oDocument->getName() . $res->getMessage());
393 } 401 }
lib/storage/ondiskpathstoragemanager.inc.php
@@ -283,9 +283,8 @@ class KTOnDiskPathStorageManager extends KTStorageManager { @@ -283,9 +283,8 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
283 $oConfig =& KTConfig::getSingleton(); 283 $oConfig =& KTConfig::getSingleton();
284 $sDocumentRoot = $oConfig->get('urls/documentRoot'); 284 $sDocumentRoot = $oConfig->get('urls/documentRoot');
285 285
286 - $sOldPath = sprintf("%s/%s-%s", KTDocumentCore::_generateFolderPath($oSrcDocument->getFolderID()), $oSrcDocument->_oDocumentContentVersion->getId(), $oSrcDocument->_oDocumentContentVersion->getFileName());  
287 - $sNewPath = sprintf("%s/%s-%s", KTDocumentCore::_generateFolderPath($oNewDocument->getFolderID()), $oNewDocument->_oDocumentContentVersion->getId(), $oNewDocument->_oDocumentContentVersion->getFileName());  
288 - $sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $sOldPath); 286 + $sNewPath = $this->generateStoragePath($oNewDocument);
  287 + $sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $this->generateStoragePath($oSrcDocument));
289 $sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath); 288 $sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath);
290 289
291 $res = KTUtil::copyFile($sFullOldPath, $sFullNewPath); 290 $res = KTUtil::copyFile($sFullOldPath, $sFullNewPath);
templates/ktcore/metadata/conditional/editsimple.smarty
1 {capture assign=sCSS} 1 {capture assign=sCSS}
2 {literal} 2 {literal}
3 /* inactivity */ 3 /* inactivity */
  4 +
4 .active .inactivity_message { display: none; } 5 .active .inactivity_message { display: none; }
5 6
6 select { width: 100%; } 7 select { width: 100%; }
@@ -14,11 +15,11 @@ select { width: 100%; } @@ -14,11 +15,11 @@ select { width: 100%; }
14 15
15 .active.editing .edit_button { display: none; } 16 .active.editing .edit_button { display: none; }
16 17
17 -.active { position: relative; } 18 +
18 td { vertical-align: top; } 19 td { vertical-align: top; }
19 .buttonset.inactive { background: transparent; } 20 .buttonset.inactive { background: transparent; }
20 21
21 -.inactive { background: #ccc; position: relative; } 22 +.inactive { background: #ccc; }
22 .inactive .fixed_message, 23 .inactive .fixed_message,
23 .inactive .unassigned_items, 24 .inactive .unassigned_items,
24 .inactive .available_behaviours, 25 .inactive .available_behaviours,
@@ -79,11 +80,14 @@ refresh the page.</p> @@ -79,11 +80,14 @@ refresh the page.</p>
79 <input type="hidden" name="fieldset_id" id="global-fieldset-id" value="{$fieldset_id}" /> 80 <input type="hidden" name="fieldset_id" id="global-fieldset-id" value="{$fieldset_id}" />
80 81
81 <table id="simple_conditional_edit"> 82 <table id="simple_conditional_edit">
  83 +<thead>
82 <tr> 84 <tr>
83 {foreach from=$aFields item=oField} 85 {foreach from=$aFields item=oField}
84 <th id="header_{$oField->getId()}">{$oField->getName()}</th> 86 <th id="header_{$oField->getId()}">{$oField->getName()}</th>
85 {/foreach} 87 {/foreach}
86 </tr> 88 </tr>
  89 +</thead>
  90 +<tbody>
87 <tr valign="top"> 91 <tr valign="top">
88 92
89 {foreach from=$aFields item=oField} 93 {foreach from=$aFields item=oField}
@@ -101,6 +105,8 @@ refresh the page.&lt;/p&gt; @@ -101,6 +105,8 @@ refresh the page.&lt;/p&gt;
101 {/foreach} 105 {/foreach}
102 106
103 </tr> 107 </tr>
  108 +</tbody>
  109 +<tfoot>
104 <tr> 110 <tr>
105 {foreach from=$aFields item=oField} 111 {foreach from=$aFields item=oField}
106 <td class="buttonset" id="buttons_{$oField->getId()}"> 112 <td class="buttonset" id="buttons_{$oField->getId()}">
@@ -112,7 +118,11 @@ refresh the page.&lt;/p&gt; @@ -112,7 +118,11 @@ refresh the page.&lt;/p&gt;
112 </td> 118 </td>
113 {/foreach} 119 {/foreach}
114 </tr> 120 </tr>
  121 +</tfoot>
115 </table> 122 </table>
  123 +
  124 +
  125 +</form>
116 <!-- 126 <!--
117 <table id="brad-log"> 127 <table id="brad-log">
118 <tr> 128 <tr>
tests/storage/copyFolder.php 0 → 100644
  1 +<?php
  2 +
  3 +require_once("../../config/dmsDefaults.php");
  4 +require_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php');
  5 +require_once(KT_LIB_DIR . '/users/User.inc');
  6 +require_once(KT_LIB_DIR . '/database/dbutil.inc');
  7 +
  8 +//error_reporting(E_ALL);
  9 +
  10 +$oSrc = Folder::get(3);
  11 +$oDest = Folder::get(2);
  12 +$oUser = User::get(1);
  13 +
  14 +var_dump(KTFolderUtil::copy($oSrc, $oDest, $oUser, 'copy test'));
  15 +
  16 +?>
0 \ No newline at end of file 17 \ No newline at end of file