Skip to content

Commit

Permalink
Merge pull request #32 from CottaCush/features/action-upgrades
Browse files Browse the repository at this point in the history
Allow for extra fields update while deleting
  • Loading branch information
netwox committed Nov 3, 2017
2 parents f4958a6 + 563509a commit cf08523
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Action/DeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class DeleteAction extends BaseAction
public $deleteStatus = 0;
public $errorMessage = 'Record not found';

public $extraFields = null;
public $formName = '';

/**
* @author Adegoke Obasa <goke@cottacush.com>
* @author Akinwunmi Taiwo <taiwo@cottacush.com>
Expand All @@ -33,16 +36,18 @@ public function run()
$controller->isPostCheck($referrerUrl);

if (!$this->model) {
$controller->flashError($this->errorMessage);
} else {
$this->model->{$this->deleteAttribute} = $this->deleteStatus;
if (!$this->model->save()) {
$controller->flashError($this->model->getErrors());
} else {
$controller->flashSuccess($this->successMessage);
}
return $controller->returnError($this->errorMessage, $this->returnUrl);
}

$this->model->{$this->deleteAttribute} = $this->deleteStatus;
if ($this->extraFields) {
$this->model->load($this->extraFields,$this->formName);
}

if (!$this->model->save()) {
return $controller->returnError($this->model->getErrors(), $this->returnUrl);
}

return $controller->redirect($this->returnUrl);
return $controller->returnSuccess($this->successMessage, $this->returnUrl);
}
}

0 comments on commit cf08523

Please sign in to comment.