Trap potential data-integrity bug

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60778 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-08-14 22:20:14 +00:00
parent c706dbdcc1
commit 4acd84a837

View File

@ -85,12 +85,15 @@ class Folder extends File {
$childName = addslashes($childName);
// Note, we do this in the database rather than object-model; otherwise we get all sorts of problems about deleting files
$children = DB::query("SELECT ID FROM `File` WHERE Name = '$childName' AND ParentID = $parentID")->column();
if($children) {
$keptChild = array_shift($children);
foreach($children as $removedChild) {
DB::query("UPDATE `File` SET ParentID = $keptChild WHERE ParentID = $removedChild");
DB::query("DELETE FROM `File` WHERE ID = $removedChild");
}
} else {
user_error("Inconsistent database issue: SELECT ID FROM `File` WHERE Name = '$childName' AND ParentID = $parentID should have returned data", E_USER_WARNING);
}
}