public function settingsCustomAction($settingsName)
{
$config = app('itemconfig');
$actionFactory = app('admin_action_factory');
$actionName = $this->request->input('action_name', false);
//get the action and perform the custom action
$action = $actionFactory->getByName($actionName);
$data = $config->getDataModel();
$result = $action->perform($data);
//override the config options so that we can get the latest
app('admin_config_factory')->updateConfigOptions();
//if the result is a string, return that as an error.
if (is_string($result)) {
return response()->json(array('success' => false, 'error' => $result));
} elseif (!$result) {
$messages = $action->getOption('messages');
return response()->json(array('success' => false, 'error' => $messages['error']));
} else {
$response = array('success' => true, 'actions' => $actionFactory->getActionsOptions(true));
//if it's a download response, flash the response to the session and return the download link
if (is_a($result, 'Symfony\\Component\\HttpFoundation\\BinaryFileResponse')) {
$file = $result->getFile()->getRealPath();
$headers = $result->headers->all();
$this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers));
$response['download'] = route('admin_file_download');
} elseif (is_a($result, '\\Illuminate\\Http\\RedirectResponse')) {
$response['redirect'] = $result->getTargetUrl();
}
return response()->json($response);
}
}