From 0b22ca6c591450cff00e182719714eb72856d143 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sun, 12 Jan 2014 20:54:55 +1300 Subject: [PATCH] FIX: Ignore current instance when checking for duplicate records (Fixes #1927) --- filesystem/File.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/filesystem/File.php b/filesystem/File.php index 026a7bf63..f2ea6d625 100644 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -596,9 +596,14 @@ class File extends DataObject { $base = pathinfo($name, PATHINFO_BASENAME); $ext = self::get_file_extension($name); $suffix = 1; - while(DataObject::get_one("File", "\"Name\" = '" . Convert::raw2sql($name) - . "' AND \"ParentID\" = " . (int)$this->ParentID)) { + while(File::get()->filter(array( + 'Name' => $name, + 'ParentID' => (int) $this->ParentID + ))->exclude(array( + 'ID' => $this->ID + ))->first() + ) { $suffix++; $name = "$base-$suffix$ext"; }