Cleaned the code for the unlink method (Is recordList used anywhere? Still checking)

This commit is contained in:
Mellisa Hankins 2013-02-02 08:38:08 +11:00
parent 7ddad1fe4b
commit 0cf1cf147d
1 changed files with 2 additions and 15 deletions

View File

@ -187,25 +187,12 @@ class GridFieldBulkManager_Request extends RequestHandler {
public function unlink(SS_HTTPRequest $request)
{
$recordList = $this->getPOSTRecordList($request);
$result = array();
if($this->gridField->list instanceof HasManyList) {
$recordClass = $this->gridField->list->dataClass;
$recordForeignKey = $this->gridField->list->foreignKey;
//$recordForeignID = $this->gridField->list->foreignID;
foreach ( $recordList as $id ) {
$record = DataObject::get_by_id($recordClass, $id);
$res = $record->setField($recordForeignKey, 0);
$record->write();
array_push($result, array($id => $res));
}
} else {
$result = $recordList;
if($this->gridField->list instanceof RelationList) {
$this->gridField->list->removeMany($recordList);
}
$response = new SS_HTTPResponse(Convert::raw2json(array($result)));
$response = new SS_HTTPResponse(Convert::raw2json(array($recordList)));
$response->addHeader('Content-Type', 'text/plain');
return $response;
}