From d036fa7f9111c21887a09d950fbb11b9c3e82867 Mon Sep 17 00:00:00 2001 From: Christopher Darling Date: Thu, 9 Aug 2012 13:26:21 +0200 Subject: [PATCH 1/2] BUGFIX: fixes sort order of newly uploaded & attached files #43 When new files are uploaded and attached via the 'From your computer' button the new files were pushed to the top of the stack resulting in the sort order being messed up, this doesn't happen when attaching files that are already uploaded. Believe this should fix bug #43 --- code/MultipleFileAttachmentField.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/MultipleFileAttachmentField.php b/code/MultipleFileAttachmentField.php index 0b55f36..7155fbd 100644 --- a/code/MultipleFileAttachmentField.php +++ b/code/MultipleFileAttachmentField.php @@ -67,7 +67,8 @@ public function setValue($value = null, $data = null) { public function refresh(SS_HTTPRequest $r) { if($r->requestVar('ids')) { $ids = array_unique($r->requestVar('ids')); - $files = new DataObjectSet(); + $files = $this->Files(); + if(!$files) $files = new DataObjectSet(); $implodestring = implode(',',$ids); $implodestring = preg_replace("/^[,]/", "", $implodestring); if($set = DataObject::get("File", "`ID` IN ($implodestring)")) { @@ -75,7 +76,6 @@ public function refresh(SS_HTTPRequest $r) { $this->processFile($file); $files->push($file); } - $files->merge($this->Files()); $files->removeDuplicates(); } else { From ded8ad18436f3533b6073b96e5f5f5db876f8983 Mon Sep 17 00:00:00 2001 From: Christopher Darling Date: Thu, 18 Oct 2012 22:53:16 +0200 Subject: [PATCH 2/2] BUGFIX: fixes the sort order of newly uploaded files --- code/MultipleFileAttachmentField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/MultipleFileAttachmentField.php b/code/MultipleFileAttachmentField.php index 7155fbd..a17e3bd 100644 --- a/code/MultipleFileAttachmentField.php +++ b/code/MultipleFileAttachmentField.php @@ -71,7 +71,7 @@ public function refresh(SS_HTTPRequest $r) { if(!$files) $files = new DataObjectSet(); $implodestring = implode(',',$ids); $implodestring = preg_replace("/^[,]/", "", $implodestring); - if($set = DataObject::get("File", "`ID` IN ($implodestring)")) { + if($set = DataObject::get("File", "`ID` IN ($implodestring)", "ID ASC")) { foreach($set as $file) { $this->processFile($file); $files->push($file);