Commit 99b80311c9c80695567e127702389fa86fb3ffc4

Authored by kevin_fourie
1 parent 0b60b9ae

Merged in from DEV trunk...

KTS-2128
"Renaming a folder double sanitizes the new foldername"
Fixed the folder add method too.

Committed By: Kevin
Reviewed By: Isaac


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@6850 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/foldermanagement/folderutil.inc.php
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 */ 31 */
32 32
33 require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); 33 require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php');
34 -require_once(KT_LIB_DIR . '/subscriptions/subscriptions.inc.php'); 34 +require_once(KT_LIB_DIR . '/subscriptions/subscriptions.inc.php');
35 35
36 require_once(KT_LIB_DIR . '/permissions/permission.inc.php'); 36 require_once(KT_LIB_DIR . '/permissions/permission.inc.php');
37 require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); 37 require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php');
@@ -42,7 +42,7 @@ require_once(KT_LIB_DIR . '/foldermanagement/foldertransaction.inc.php'); @@ -42,7 +42,7 @@ require_once(KT_LIB_DIR . '/foldermanagement/foldertransaction.inc.php');
42 require_once(KT_LIB_DIR . '/database/dbutil.inc'); 42 require_once(KT_LIB_DIR . '/database/dbutil.inc');
43 43
44 class KTFolderUtil { 44 class KTFolderUtil {
45 - function _add ($oParentFolder, $sFolderName, $oUser) { 45 + function _add($oParentFolder, $sFolderName, $oUser) {
46 if (PEAR::isError($oParentFolder)) { 46 if (PEAR::isError($oParentFolder)) {
47 return $oParentFolder; 47 return $oParentFolder;
48 } 48 }
@@ -51,10 +51,10 @@ class KTFolderUtil { @@ -51,10 +51,10 @@ class KTFolderUtil {
51 } 51 }
52 $oStorage =& KTStorageManagerUtil::getSingleton(); 52 $oStorage =& KTStorageManagerUtil::getSingleton();
53 $oFolder =& Folder::createFromArray(array( 53 $oFolder =& Folder::createFromArray(array(
54 - 'name' => $sFolderName,  
55 - 'description' => $sFolderName,  
56 - 'parentid' => $oParentFolder->getID(),  
57 - 'creatorid' => $oUser->getID(), 54 + 'name' => sanitizeForSQL($sFolderName),
  55 + 'description' => sanitizeForSQL($sFolderName),
  56 + 'parentid' => $oParentFolder->getID(),
  57 + 'creatorid' => $oUser->getID(),
58 )); 58 ));
59 if (PEAR::isError($oFolder)) { 59 if (PEAR::isError($oFolder)) {
60 return $oFolder; 60 return $oFolder;
@@ -67,35 +67,35 @@ class KTFolderUtil { @@ -67,35 +67,35 @@ class KTFolderUtil {
67 return $oFolder; 67 return $oFolder;
68 } 68 }
69 69
70 - function add ($oParentFolder, $sFolderName, $oUser) {  
71 -  
72 -  
73 - $folderid=$oParentFolder->getId(); 70 + function add($oParentFolder, $sFolderName, $oUser) {
  71 +
  72 +
  73 + $folderid=$oParentFolder->getId();
74 // check for conflicts first 74 // check for conflicts first
75 if (Folder::folderExistsName($sFolderName,$folderid)) { 75 if (Folder::folderExistsName($sFolderName,$folderid)) {
76 return PEAR::raiseError(sprintf(_kt('The folder %s already exists.'), $sFolderName)); 76 return PEAR::raiseError(sprintf(_kt('The folder %s already exists.'), $sFolderName));
77 } 77 }
78 -  
79 - $oFolder = KTFolderUtil::_add($oParentFolder, $sFolderName, $oUser); 78 +
  79 + $oFolder = KTFolderUtil::_add($oParentFolder, $sFolderName, $oUser);
80 if (PEAR::isError($oFolder)) { 80 if (PEAR::isError($oFolder)) {
81 return $oFolder; 81 return $oFolder;
82 } 82 }
83 - 83 +
84 84
85 $oTransaction = KTFolderTransaction::createFromArray(array( 85 $oTransaction = KTFolderTransaction::createFromArray(array(
86 - 'folderid' => $oFolder->getId(),  
87 - 'comment' => _kt('Folder created'),  
88 - 'transactionNS' => 'ktcore.transactions.create',  
89 - 'userid' => $oUser->getId(),  
90 - 'ip' => Session::getClientIP(), 86 + 'folderid' => $oFolder->getId(),
  87 + 'comment' => _kt('Folder created'),
  88 + 'transactionNS' => 'ktcore.transactions.create',
  89 + 'userid' => $oUser->getId(),
  90 + 'ip' => Session::getClientIP(),
91 )); 91 ));
92 92
93 // fire subscription alerts for the new folder 93 // fire subscription alerts for the new folder
94 $oSubscriptionEvent = new SubscriptionEvent(); 94 $oSubscriptionEvent = new SubscriptionEvent();
95 $oSubscriptionEvent->AddFolder($oFolder, $oParentFolder); 95 $oSubscriptionEvent->AddFolder($oFolder, $oParentFolder);
96 - 96 +
97 KTFolderUtil::updateSearchableText($oFolder); 97 KTFolderUtil::updateSearchableText($oFolder);
98 - 98 +
99 return $oFolder; 99 return $oFolder;
100 } 100 }
101 101
@@ -131,7 +131,7 @@ class KTFolderUtil { @@ -131,7 +131,7 @@ class KTFolderUtil {
131 131
132 // First, deal with SQL, as it, at least, is guaranteed to be atomic 132 // First, deal with SQL, as it, at least, is guaranteed to be atomic
133 $table = 'folders'; 133 $table = 'folders';
134 - 134 +
135 if ($oNewParentFolder->getId() == 1) { 135 if ($oNewParentFolder->getId() == 1) {
136 $sNewParentFolderPath = $oNewParentFolder->getName(); 136 $sNewParentFolderPath = $oNewParentFolder->getName();
137 $sNewParentFolderIds = ''; 137 $sNewParentFolderIds = '';
@@ -150,10 +150,10 @@ class KTFolderUtil { @@ -150,10 +150,10 @@ class KTFolderUtil {
150 // Update the moved folder first... 150 // Update the moved folder first...
151 $sQuery = "UPDATE $table SET full_path = ?, parent_folder_ids = ?, parent_id = ? WHERE id = ?"; 151 $sQuery = "UPDATE $table SET full_path = ?, parent_folder_ids = ?, parent_id = ? WHERE id = ?";
152 $aParams = array( 152 $aParams = array(
153 - sprintf("%s", $sNewParentFolderPath),  
154 - $sNewParentFolderIds,  
155 - $oNewParentFolder->getID(),  
156 - $oFolder->getID(), 153 + sprintf("%s", $sNewParentFolderPath),
  154 + $sNewParentFolderIds,
  155 + $oNewParentFolder->getID(),
  156 + $oFolder->getID(),
157 ); 157 );
158 $res = DBUtil::runQuery(array($sQuery, $aParams)); 158 $res = DBUtil::runQuery(array($sQuery, $aParams));
159 if (PEAR::isError($res)) { 159 if (PEAR::isError($res)) {
@@ -165,14 +165,14 @@ class KTFolderUtil { @@ -165,14 +165,14 @@ class KTFolderUtil {
165 } else { 165 } else {
166 $sOldFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName()); 166 $sOldFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName());
167 } 167 }
168 - 168 +
169 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)), parent_folder_ids = CONCAT(?, SUBSTRING(parent_folder_ids FROM ?)) WHERE full_path LIKE ?"; 169 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)), parent_folder_ids = CONCAT(?, SUBSTRING(parent_folder_ids FROM ?)) WHERE full_path LIKE ?";
170 $aParams = array( 170 $aParams = array(
171 - sprintf("%s", $sNewParentFolderPath),  
172 - strlen($oFolder->getFullPath()) + 1,  
173 - $sNewParentFolderIds,  
174 - strlen($oFolder->getParentFolderIDs()) + 1,  
175 - sprintf("%s%%", $sOldFolderPath), 171 + sprintf("%s", $sNewParentFolderPath),
  172 + strlen($oFolder->getFullPath()) + 1,
  173 + $sNewParentFolderIds,
  174 + strlen($oFolder->getParentFolderIDs()) + 1,
  175 + sprintf("%s%%", $sOldFolderPath),
176 ); 176 );
177 $res = DBUtil::runQuery(array($sQuery, $aParams)); 177 $res = DBUtil::runQuery(array($sQuery, $aParams));
178 if (PEAR::isError($res)) { 178 if (PEAR::isError($res)) {
@@ -182,11 +182,11 @@ class KTFolderUtil { @@ -182,11 +182,11 @@ class KTFolderUtil {
182 $table = 'documents'; 182 $table = 'documents';
183 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)), parent_folder_ids = CONCAT(?, SUBSTRING(parent_folder_ids FROM ?)) WHERE full_path LIKE ?"; 183 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)), parent_folder_ids = CONCAT(?, SUBSTRING(parent_folder_ids FROM ?)) WHERE full_path LIKE ?";
184 $aParams = array( 184 $aParams = array(
185 - sprintf("%s", $sNewParentFolderPath),  
186 - strlen($oFolder->getFullPath()) + 1,  
187 - $sNewParentFolderIds,  
188 - strlen($oFolder->getParentFolderIDs()) + 1,  
189 - sprintf("%s%%", $sOldFolderPath), 185 + sprintf("%s", $sNewParentFolderPath),
  186 + strlen($oFolder->getFullPath()) + 1,
  187 + $sNewParentFolderIds,
  188 + strlen($oFolder->getParentFolderIDs()) + 1,
  189 + sprintf("%s%%", $sOldFolderPath),
190 ); 190 );
191 $res = DBUtil::runQuery(array($sQuery, $aParams)); 191 $res = DBUtil::runQuery(array($sQuery, $aParams));
192 if (PEAR::isError($res)) { 192 if (PEAR::isError($res)) {
@@ -204,11 +204,11 @@ class KTFolderUtil { @@ -204,11 +204,11 @@ class KTFolderUtil {
204 } 204 }
205 205
206 $oTransaction = KTFolderTransaction::createFromArray(array( 206 $oTransaction = KTFolderTransaction::createFromArray(array(
207 - 'folderid' => $oFolder->getId(),  
208 - 'comment' => $sComment,  
209 - 'transactionNS' => 'ktcore.transactions.move',  
210 - 'userid' => $oUser->getId(),  
211 - 'ip' => Session::getClientIP(), 207 + 'folderid' => $oFolder->getId(),
  208 + 'comment' => $sComment,
  209 + 'transactionNS' => 'ktcore.transactions.move',
  210 + 'userid' => $oUser->getId(),
  211 + 'ip' => Session::getClientIP(),
212 )); 212 ));
213 213
214 Document::clearAllCaches(); 214 Document::clearAllCaches();
@@ -216,20 +216,20 @@ class KTFolderUtil { @@ -216,20 +216,20 @@ class KTFolderUtil {
216 216
217 if ($bChangePermissionObject) { 217 if ($bChangePermissionObject) {
218 $aOptions = array( 218 $aOptions = array(
219 - 'evenifnotowner' => true, // Inherit from parent folder, even though not permission owner 219 + 'evenifnotowner' => true, // Inherit from parent folder, even though not permission owner
220 ); 220 );
221 KTPermissionUtil::inheritPermissionObject($oFolder, $aOptions); 221 KTPermissionUtil::inheritPermissionObject($oFolder, $aOptions);
222 } 222 }
223 223
224 return true; 224 return true;
225 } 225 }
226 - 226 +
227 function rename($oFolder, $sNewName, $oUser) { 227 function rename($oFolder, $sNewName, $oUser) {
228 $oStorage =& KTStorageManagerUtil::getSingleton(); 228 $oStorage =& KTStorageManagerUtil::getSingleton();
229 $sOldName = $oFolder->getName(); 229 $sOldName = $oFolder->getName();
230 // First, deal with SQL, as it, at least, is guaranteed to be atomic 230 // First, deal with SQL, as it, at least, is guaranteed to be atomic
231 $table = "folders"; 231 $table = "folders";
232 - 232 +
233 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)) WHERE full_path LIKE ?"; 233 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)) WHERE full_path LIKE ?";
234 234
235 if ($oFolder->getId() == 1) { 235 if ($oFolder->getId() == 1) {
@@ -241,9 +241,9 @@ class KTFolderUtil { @@ -241,9 +241,9 @@ class KTFolderUtil {
241 241
242 } 242 }
243 $aParams = array( 243 $aParams = array(
244 - sprintf("%s", $sNewPath),  
245 - strlen($sOldPath) + 1,  
246 - sprintf("%s%%", $sOldPath), 244 + sprintf("%s", $sNewPath),
  245 + strlen($sOldPath) + 1,
  246 + sprintf("%s%%", $sOldPath),
247 ); 247 );
248 $res = DBUtil::runQuery(array($sQuery, $aParams)); 248 $res = DBUtil::runQuery(array($sQuery, $aParams));
249 if (PEAR::isError($res)) { 249 if (PEAR::isError($res)) {
@@ -253,9 +253,9 @@ class KTFolderUtil { @@ -253,9 +253,9 @@ class KTFolderUtil {
253 $table = "documents"; 253 $table = "documents";
254 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)) WHERE full_path LIKE ?"; 254 $sQuery = "UPDATE $table SET full_path = CONCAT(?, SUBSTRING(full_path FROM ?)) WHERE full_path LIKE ?";
255 $aParams = array( 255 $aParams = array(
256 - sprintf("%s", $sNewPath),  
257 - strlen($sOldPath) + 1,  
258 - sprintf("%s%%", $sOldPath), 256 + sprintf("%s", $sNewPath),
  257 + strlen($sOldPath) + 1,
  258 + sprintf("%s%%", $sOldPath),
259 ); 259 );
260 $res = DBUtil::runQuery(array($sQuery, $aParams)); 260 $res = DBUtil::runQuery(array($sQuery, $aParams));
261 if (PEAR::isError($res)) { 261 if (PEAR::isError($res)) {
@@ -266,16 +266,16 @@ class KTFolderUtil { @@ -266,16 +266,16 @@ class KTFolderUtil {
266 if (PEAR::isError($res)) { 266 if (PEAR::isError($res)) {
267 return $res; 267 return $res;
268 } 268 }
269 - 269 +
270 $oFolder->setName($sNewName); 270 $oFolder->setName($sNewName);
271 $res = $oFolder->update(); 271 $res = $oFolder->update();
272 272
273 $oTransaction = KTFolderTransaction::createFromArray(array( 273 $oTransaction = KTFolderTransaction::createFromArray(array(
274 - 'folderid' => $oFolder->getId(),  
275 - 'comment' => sprintf(_kt("Renamed from \"%s\" to \"%s\""), $sOldName, $sNewName),  
276 - 'transactionNS' => 'ktcore.transactions.rename',  
277 - 'userid' => $_SESSION['userID'],  
278 - 'ip' => Session::getClientIP(), 274 + 'folderid' => $oFolder->getId(),
  275 + 'comment' => sprintf(_kt("Renamed from \"%s\" to \"%s\""), $sOldName, $sNewName),
  276 + 'transactionNS' => 'ktcore.transactions.rename',
  277 + 'userid' => $_SESSION['userID'],
  278 + 'ip' => Session::getClientIP(),
279 )); 279 ));
280 if (PEAR::isError($oTransaction)) { 280 if (PEAR::isError($oTransaction)) {
281 return $oTransaction; 281 return $oTransaction;
@@ -292,34 +292,34 @@ class KTFolderUtil { @@ -292,34 +292,34 @@ class KTFolderUtil {
292 function exists($oParentFolder, $sName) { 292 function exists($oParentFolder, $sName) {
293 return Folder::folderExistsName($sName, $oParentFolder->getID()); 293 return Folder::folderExistsName($sName, $oParentFolder->getID());
294 } 294 }
295 -  
296 -  
297 - 295 +
  296 +
  297 +
298 /* folderUtil::delete 298 /* folderUtil::delete
299 - *  
300 - * this function is _much_ more complex than it might seem.  
301 - * we need to:  
302 - * - recursively identify children  
303 - * - validate that permissions are allocated correctly.  
304 - * - step-by-step delete.  
305 - */  
306 - 299 + *
  300 + * this function is _much_ more complex than it might seem.
  301 + * we need to:
  302 + * - recursively identify children
  303 + * - validate that permissions are allocated correctly.
  304 + * - step-by-step delete.
  305 + */
  306 +
307 function delete($oStartFolder, $oUser, $sReason, $aOptions = null) { 307 function delete($oStartFolder, $oUser, $sReason, $aOptions = null) {
308 require_once(KT_LIB_DIR . '/unitmanagement/Unit.inc'); 308 require_once(KT_LIB_DIR . '/unitmanagement/Unit.inc');
309 309
310 $oPerm = KTPermission::getByName('ktcore.permissions.delete'); 310 $oPerm = KTPermission::getByName('ktcore.permissions.delete');
311 311
312 $bIgnorePermissions = KTUtil::arrayGet($aOptions, 'ignore_permissions'); 312 $bIgnorePermissions = KTUtil::arrayGet($aOptions, 'ignore_permissions');
313 - 313 +
314 $aFolderIds = array(); // of oFolder 314 $aFolderIds = array(); // of oFolder
315 $aDocuments = array(); // of oDocument 315 $aDocuments = array(); // of oDocument
316 $aFailedDocuments = array(); // of String 316 $aFailedDocuments = array(); // of String
317 $aFailedFolders = array(); // of String 317 $aFailedFolders = array(); // of String
318 - 318 +
319 $aRemainingFolders = array($oStartFolder->getId()); 319 $aRemainingFolders = array($oStartFolder->getId());
320 - 320 +
321 DBUtil::startTransaction(); 321 DBUtil::startTransaction();
322 - 322 +
323 while (!empty($aRemainingFolders)) { 323 while (!empty($aRemainingFolders)) {
324 $iFolderId = array_pop($aRemainingFolders); 324 $iFolderId = array_pop($aRemainingFolders);
325 $oFolder = Folder::get($iFolderId); 325 $oFolder = Folder::get($iFolderId);
@@ -340,15 +340,15 @@ class KTFolderUtil { @@ -340,15 +340,15 @@ class KTFolderUtil {
340 } else { 340 } else {
341 $aFolderIds[] = $iFolderId; 341 $aFolderIds[] = $iFolderId;
342 } 342 }
343 - 343 +
344 // child documents 344 // child documents
345 $aChildDocs = Document::getList(array('folder_id = ?',array($iFolderId))); 345 $aChildDocs = Document::getList(array('folder_id = ?',array($iFolderId)));
346 foreach ($aChildDocs as $oDoc) { 346 foreach ($aChildDocs as $oDoc) {
347 if (!$bIgnorePermissions && $oDoc->getImmutable()) { 347 if (!$bIgnorePermissions && $oDoc->getImmutable()) {
348 - if (!KTBrowseUtil::inAdminMode($oUser, $oStartFolder)) { 348 + if (!KTBrowseUtil::inAdminMode($oUser, $oStartFolder)) {
349 $aFailedDocuments[] = $oDoc->getName(); 349 $aFailedDocuments[] = $oDoc->getName();
350 continue; 350 continue;
351 - } 351 + }
352 } 352 }
353 if ($bIgnorePermissions || (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDoc) && ($oDoc->getIsCheckedOut() == false)) ) { 353 if ($bIgnorePermissions || (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDoc) && ($oDoc->getIsCheckedOut() == false)) ) {
354 $aDocuments[] = $oDoc; 354 $aDocuments[] = $oDoc;
@@ -356,14 +356,14 @@ class KTFolderUtil { @@ -356,14 +356,14 @@ class KTFolderUtil {
356 $aFailedDocuments[] = $oDoc->getName(); 356 $aFailedDocuments[] = $oDoc->getName();
357 } 357 }
358 } 358 }
359 - 359 +
360 // child folders. 360 // child folders.
361 $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true)); 361 $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true));
362 $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds); 362 $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds);
363 } 363 }
364 364
365 // FIXME we could subdivide this to provide a per-item display (viz. bulk upload, etc.) 365 // FIXME we could subdivide this to provide a per-item display (viz. bulk upload, etc.)
366 - 366 +
367 if ((!empty($aFailedDocuments) || (!empty($aFailedFolders)))) { 367 if ((!empty($aFailedDocuments) || (!empty($aFailedFolders)))) {
368 $sFD = ''; 368 $sFD = '';
369 $sFF = ''; 369 $sFF = '';
@@ -391,23 +391,23 @@ class KTFolderUtil { @@ -391,23 +391,23 @@ class KTFolderUtil {
391 // documents all cleared. 391 // documents all cleared.
392 $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folders') . ' WHERE id IN (' . DBUtil::paramArray($aFolderIds) . ')'; 392 $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folders') . ' WHERE id IN (' . DBUtil::paramArray($aFolderIds) . ')';
393 $aParams = $aFolderIds; 393 $aParams = $aFolderIds;
394 - 394 +
395 $res = DBUtil::runQuery(array($sQuery, $aParams)); 395 $res = DBUtil::runQuery(array($sQuery, $aParams));
396 396
397 if (PEAR::isError($res)) { 397 if (PEAR::isError($res)) {
398 DBUtil::rollback(); 398 DBUtil::rollback();
399 return PEAR::raiseError(_kt('Failure deleting folders.')); 399 return PEAR::raiseError(_kt('Failure deleting folders.'));
400 } 400 }
401 - 401 +
402 // purge caches 402 // purge caches
403 - KTEntityUtil::clearAllCaches('Folder');  
404 - 403 + KTEntityUtil::clearAllCaches('Folder');
  404 +
405 // and store 405 // and store
406 DBUtil::commit(); 406 DBUtil::commit();
407 - 407 +
408 return true; 408 return true;
409 } 409 }
410 - 410 +
411 function copy($oSrcFolder, $oDestFolder, $oUser, $sReason) { 411 function copy($oSrcFolder, $oDestFolder, $oUser, $sReason) {
412 if (KTFolderUtil::exists($oDestFolder, $oSrcFolder->getName())) { 412 if (KTFolderUtil::exists($oDestFolder, $oSrcFolder->getName())) {
413 return PEAR::raiseError(_kt("Folder with the same name already exists in the new parent folder")); 413 return PEAR::raiseError(_kt("Folder with the same name already exists in the new parent folder"));
@@ -417,20 +417,20 @@ class KTFolderUtil { @@ -417,20 +417,20 @@ class KTFolderUtil {
417 // 417 //
418 $oPerm = KTPermission::getByName('ktcore.permissions.read'); 418 $oPerm = KTPermission::getByName('ktcore.permissions.read');
419 $oBaseFolderPerm = KTPermission::getByName('ktcore.permissions.addFolder'); 419 $oBaseFolderPerm = KTPermission::getByName('ktcore.permissions.addFolder');
420 - 420 +
421 if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oBaseFolderPerm, $oDestFolder)) { 421 if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oBaseFolderPerm, $oDestFolder)) {
422 return PEAR::raiseError(_kt('You are not allowed to create folders in the destination.')); 422 return PEAR::raiseError(_kt('You are not allowed to create folders in the destination.'));
423 } 423 }
424 - 424 +
425 $aFolderIds = array(); // of oFolder 425 $aFolderIds = array(); // of oFolder
426 $aDocuments = array(); // of oDocument 426 $aDocuments = array(); // of oDocument
427 $aFailedDocuments = array(); // of String 427 $aFailedDocuments = array(); // of String
428 $aFailedFolders = array(); // of String 428 $aFailedFolders = array(); // of String
429 - 429 +
430 $aRemainingFolders = array($oSrcFolder->getId()); 430 $aRemainingFolders = array($oSrcFolder->getId());
431 - 431 +
432 DBUtil::startTransaction(); 432 DBUtil::startTransaction();
433 - 433 +
434 while (!empty($aRemainingFolders)) { 434 while (!empty($aRemainingFolders)) {
435 $iFolderId = array_pop($aRemainingFolders); 435 $iFolderId = array_pop($aRemainingFolders);
436 $oFolder = Folder::get($iFolderId); 436 $oFolder = Folder::get($iFolderId);
@@ -438,14 +438,14 @@ class KTFolderUtil { @@ -438,14 +438,14 @@ class KTFolderUtil {
438 DBUtil::rollback(); 438 DBUtil::rollback();
439 return PEAR::raiseError(sprintf(_kt('Failure resolving child folder with id = %d.'), $iFolderId)); 439 return PEAR::raiseError(sprintf(_kt('Failure resolving child folder with id = %d.'), $iFolderId));
440 } 440 }
441 - 441 +
442 // don't just stop ... plough on. 442 // don't just stop ... plough on.
443 if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oFolder)) { 443 if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oFolder)) {
444 $aFolderIds[] = $iFolderId; 444 $aFolderIds[] = $iFolderId;
445 } else { 445 } else {
446 $aFailedFolders[] = $oFolder->getName(); 446 $aFailedFolders[] = $oFolder->getName();
447 } 447 }
448 - 448 +
449 // child documents 449 // child documents
450 $aChildDocs = Document::getList(array('folder_id = ?',array($iFolderId))); 450 $aChildDocs = Document::getList(array('folder_id = ?',array($iFolderId)));
451 foreach ($aChildDocs as $oDoc) { 451 foreach ($aChildDocs as $oDoc) {
@@ -455,12 +455,12 @@ class KTFolderUtil { @@ -455,12 +455,12 @@ class KTFolderUtil {
455 $aFailedDocuments[] = $oDoc->getName(); 455 $aFailedDocuments[] = $oDoc->getName();
456 } 456 }
457 } 457 }
458 - 458 +
459 // child folders. 459 // child folders.
460 $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true)); 460 $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true));
461 $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds); 461 $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds);
462 } 462 }
463 - 463 +
464 if ((!empty($aFailedDocuments) || (!empty($aFailedFolders)))) { 464 if ((!empty($aFailedDocuments) || (!empty($aFailedFolders)))) {
465 $sFD = ''; 465 $sFD = '';
466 $sFF = ''; 466 $sFF = '';
@@ -472,15 +472,15 @@ class KTFolderUtil { @@ -472,15 +472,15 @@ class KTFolderUtil {
472 } 472 }
473 return PEAR::raiseError(_kt('You do not have permission to copy these items. ') . $sFD . $sFF); 473 return PEAR::raiseError(_kt('You do not have permission to copy these items. ') . $sFD . $sFF);
474 } 474 }
475 - 475 +
476 // first we walk the tree, creating in the new location as we go. 476 // first we walk the tree, creating in the new location as we go.
477 // essentially this is an "ok" pass. 477 // essentially this is an "ok" pass.
478 -  
479 -  
480 - $oStorage =& KTStorageManagerUtil::getSingleton();  
481 - 478 +
  479 +
  480 + $oStorage =& KTStorageManagerUtil::getSingleton();
  481 +
482 $aFolderMap = array(); 482 $aFolderMap = array();
483 - 483 +
484 $sTable = KTUtil::getTableName('folders'); 484 $sTable = KTUtil::getTableName('folders');
485 $sGetQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ? '; 485 $sGetQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ? ';
486 $aParams = array($oSrcFolder->getId()); 486 $aParams = array($oSrcFolder->getId());
@@ -501,18 +501,18 @@ class KTFolderUtil { @@ -501,18 +501,18 @@ class KTFolderUtil {
501 return $res; 501 return $res;
502 } 502 }
503 $aRemainingFolders = Folder::getList(array('parent_id = ?', array($oSrcFolder->getId())), array('ids' => true)); 503 $aRemainingFolders = Folder::getList(array('parent_id = ?', array($oSrcFolder->getId())), array('ids' => true));
504 -  
505 - 504 +
  505 +
506 while (!empty($aRemainingFolders)) { 506 while (!empty($aRemainingFolders)) {
507 $iFolderId = array_pop($aRemainingFolders); 507 $iFolderId = array_pop($aRemainingFolders);
508 - 508 +
509 $aParams = array($iFolderId); 509 $aParams = array($iFolderId);
510 $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams)); 510 $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams));
511 unset($aRow['id']); 511 unset($aRow['id']);
512 - 512 +
513 // since we are nested, we will have solved the parent first. 513 // since we are nested, we will have solved the parent first.
514 - $aRow['parent_id'] = $aFolderMap[$aRow['parent_id']];  
515 - 514 + $aRow['parent_id'] = $aFolderMap[$aRow['parent_id']];
  515 +
516 $id = DBUtil::autoInsert($sTable, $aRow); 516 $id = DBUtil::autoInsert($sTable, $aRow);
517 if (PEAR::isError($id)) { 517 if (PEAR::isError($id)) {
518 $oStorage->removeFolder($oNewBaseFolder); 518 $oStorage->removeFolder($oNewBaseFolder);
@@ -520,7 +520,7 @@ class KTFolderUtil { @@ -520,7 +520,7 @@ class KTFolderUtil {
520 return $id; 520 return $id;
521 } 521 }
522 $aFolderMap[$iFolderId] = $id; 522 $aFolderMap[$iFolderId] = $id;
523 - 523 +
524 $oNewFolder = Folder::get($id); 524 $oNewFolder = Folder::get($id);
525 $res = $oStorage->createFolder($oNewFolder); 525 $res = $oStorage->createFolder($oNewFolder);
526 if (PEAR::isError($res)) { 526 if (PEAR::isError($res)) {
@@ -529,18 +529,18 @@ class KTFolderUtil { @@ -529,18 +529,18 @@ class KTFolderUtil {
529 DBUtil::rollback(); 529 DBUtil::rollback();
530 return $res; 530 return $res;
531 } 531 }
532 - 532 +
533 $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true)); 533 $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true));
534 $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds); 534 $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds);
535 } 535 }
536 -  
537 -  
538 - // var_dump($aFolderMap);  
539 - 536 +
  537 +
  538 + // var_dump($aFolderMap);
  539 +
540 // now we can go ahead. 540 // now we can go ahead.
541 foreach ($aDocuments as $oDocument) { 541 foreach ($aDocuments as $oDocument) {
542 $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]); 542 $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]);
543 -// var_dump($oDocument->getFolderID()); 543 + // var_dump($oDocument->getFolderID());
544 $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder); 544 $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder);
545 if (PEAR::isError($res) || ($res === false)) { 545 if (PEAR::isError($res) || ($res === false)) {
546 $oStorage->removeFolder($oNewBaseFolder); 546 $oStorage->removeFolder($oNewBaseFolder);
@@ -548,33 +548,33 @@ class KTFolderUtil { @@ -548,33 +548,33 @@ class KTFolderUtil {
548 return PEAR::raiseError(_kt('Delete Aborted. Unexpected failure to copydocument: ') . $oDocument->getName() . $res->getMessage()); 548 return PEAR::raiseError(_kt('Delete Aborted. Unexpected failure to copydocument: ') . $oDocument->getName() . $res->getMessage());
549 } 549 }
550 } 550 }
551 - 551 +
552 // and store 552 // and store
553 DBUtil::commit(); 553 DBUtil::commit();
554 -  
555 - return true; 554 +
  555 + return true;
556 } 556 }
557 - 557 +
558 function updateSearchableText($oFolder) { 558 function updateSearchableText($oFolder) {
559 - // very simple function to rebuild the searchable text for this 559 + // very simple function to rebuild the searchable text for this
560 // folder. 560 // folder.
561 - 561 +
562 // MyISAM table for fulltext index - no transactions. 562 // MyISAM table for fulltext index - no transactions.
563 - 563 +
564 // get the folder text 564 // get the folder text
565 // XXX replace this with a trigger / producer set. 565 // XXX replace this with a trigger / producer set.
566 $sSearchableText = $oFolder->getName(); 566 $sSearchableText = $oFolder->getName();
567 - 567 +
568 // do the update. 568 // do the update.
569 $iFolderId = KTUtil::getId($oFolder); 569 $iFolderId = KTUtil::getId($oFolder);
570 $sTable = KTUtil::getTableName('folder_searchable_text'); 570 $sTable = KTUtil::getTableName('folder_searchable_text');
571 $aDelete = array( 571 $aDelete = array(
572 - "folder_id" => $iFolderId, 572 + "folder_id" => $iFolderId,
573 ); 573 );
574 DBUtil::whereDelete($sTable, $aDelete); 574 DBUtil::whereDelete($sTable, $aDelete);
575 $aInsert = array( 575 $aInsert = array(
576 - "folder_id" => $iFolderId,  
577 - "folder_text" => $sSearchableText, 576 + "folder_id" => $iFolderId,
  577 + "folder_text" => $sSearchableText,
578 ); 578 );
579 return DBUtil::autoInsert($sTable, $aInsert, array('noid' => true)); 579 return DBUtil::autoInsert($sTable, $aInsert, array('noid' => true));
580 } 580 }