mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
c706dbdcc1
commit
4acd84a837
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user