From bc8f2bda5904be13f39ad9665a756f06553cead8 Mon Sep 17 00:00:00 2001 From: colymba Date: Mon, 4 Mar 2013 11:44:53 +0200 Subject: [PATCH] FIX #3, FIX #11 should work with all RelationList --- code/GridFieldBulkImageUpload_Request.php | 8 +++----- code/GridFieldBulkManager_Request.php | 15 ++------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/code/GridFieldBulkImageUpload_Request.php b/code/GridFieldBulkImageUpload_Request.php index d8d9f70..371bbab 100644 --- a/code/GridFieldBulkImageUpload_Request.php +++ b/code/GridFieldBulkImageUpload_Request.php @@ -273,16 +273,14 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { */ public function upload(SS_HTTPRequest $request) { - $recordClass = $this->gridField->list->dataClass; - $recordForeignKey = $this->gridField->list->foreignKey; - $recordForeignID = $this->gridField->list->foreignID; - + $recordClass = $this->gridField->list->dataClass; $record = Object::create($recordClass); - $record->setField($recordForeignKey, $recordForeignID); + // passes the current gridfield-instance to a call-back method on the new object $record->extend("onBulkImageUpload", $this->gridField); $record->write(); + $this->gridField->list->add($record->ID); $upload = new Upload(); $tmpfile = $request->postVar('BulkImageUploadField'); diff --git a/code/GridFieldBulkManager_Request.php b/code/GridFieldBulkManager_Request.php index f238e17..a8cbbb5 100644 --- a/code/GridFieldBulkManager_Request.php +++ b/code/GridFieldBulkManager_Request.php @@ -187,20 +187,9 @@ class GridFieldBulkManager_Request extends RequestHandler { public function unlink(SS_HTTPRequest $request) { $recordList = $this->getPOSTRecordList($request); - $recordClass = $this->gridField->list->dataClass; - $recordForeignKey = $this->gridField->list->foreignKey; - //$recordForeignID = $this->gridField->list->foreignID; - $result = array(); + $this->gridField->list->removeMany($recordList); - foreach ( $recordList as $id ) - { - $record = DataObject::get_by_id($recordClass, $id); - $res = $record->setField($recordForeignKey, 0); - $record->write(); - array_push($result, array($id => $res)); - } - - $response = new SS_HTTPResponse(Convert::raw2json(array($result))); + $response = new SS_HTTPResponse(Convert::raw2json(array($recordList))); $response->addHeader('Content-Type', 'text/plain'); return $response; }