Handle removing a media also if it's not a json request

Was not working after
https://github.com/getgrav/grav-plugin-admin/commit/6b343365996ce838759d
80fa3917d4d994f1aeb4
This commit is contained in:
Flavio Copes
2017-01-28 19:08:58 +01:00
parent 4faf0c0b95
commit 3627e0ec59
2 changed files with 22 additions and 8 deletions

View File

@@ -876,6 +876,9 @@ class AdminBaseController
}
$filename = base64_decode($this->grav['uri']->param('route'));
if (!$filename) {
$filename = base64_decode($this->route);
}
$file = File::instance($filename);
$resultRemoveMedia = false;
@@ -895,17 +898,27 @@ class AdminBaseController
}
if ($resultRemoveMedia && $resultRemoveMediaMeta) {
$this->admin->json_response = [
'status' => 'success',
'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL')
];
if ($this->grav['uri']->extension() === 'json') {
$this->admin->json_response = [
'status' => 'success',
'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL')
];
} else {
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL'), 'info');
$this->clearMediaCache();
$this->setRedirect('/media-manager');
}
return true;
} else {
$this->admin->json_response = [
'status' => 'success',
'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_FAILED')
];
if ($this->grav['uri']->extension() === 'json') {
$this->admin->json_response = [
'status' => 'success',
'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_FAILED')
];
} else {
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REMOVE_FAILED'), 'error');
}
return false;
}