diff --git a/CHANGELOG.md b/CHANGELOG.md index 110bc35e..c5269fc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ 1. [](#bugfix) * Fixed issue `admin.super` or `admin.users` users changing the account when saving another user [#713](https://github.com/getgrav/grav-plugin-admin/issues/713) * Fix issue where non `admin.super`/`admin.users` users could see other users profiles [#713](https://github.com/getgrav/grav-plugin-admin/issues/713) + * Fix removing responsive image from page media [#111](https://github.com/getgrav/grav-plugin-admin/issues/111) [#952](https://github.com/getgrav/grav-plugin-admin/issues/952) # v1.2.10 ## 1/30/2017 diff --git a/classes/admincontroller.php b/classes/admincontroller.php index 4f8358c9..74edfc64 100644 --- a/classes/admincontroller.php +++ b/classes/admincontroller.php @@ -1540,8 +1540,43 @@ class AdminController extends AdminBaseController } $targetPath = $page->path() . '/' . $filename; + $fileParts = pathinfo($filename); - if (!file_exists($targetPath)) { + $found = false; + + if (file_exists($targetPath)) { + $found = true; + $result = unlink($targetPath); + + if (!$result) { + $this->admin->json_response = [ + 'status' => 'error', + 'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_COULD_NOT_BE_DELETED') . ': ' . $filename + ]; + + return false; + } + } + + + foreach (scandir($page->path()) as $file) { + if (preg_match("/{$fileParts['filename']}@\d+x\.{$fileParts['extension']}$/", $file)) { + $result = unlink($page->path() . '/' . $file); + + if (!$result) { + $this->admin->json_response = [ + 'status' => 'error', + 'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_COULD_NOT_BE_DELETED') . ': ' . $filename + ]; + + return false; + } + + $found = true; + } + } + + if (!$found) { $this->admin->json_response = [ 'status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_NOT_FOUND') . ': ' . $filename @@ -1550,24 +1585,6 @@ class AdminController extends AdminBaseController return false; } - $fileParts = pathinfo($filename); - $result = unlink($targetPath); - - if (!$result) { - $this->admin->json_response = [ - 'status' => 'error', - 'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_COULD_NOT_BE_DELETED') . ': ' . $filename - ]; - - return false; - } - - foreach (scandir($page->path()) as $file) { - if (preg_match("/{$fileParts['filename']}@\d+x\.{$fileParts['extension']}$/", $file)) { - unlink($page->path() . '/' . $file); - } - } - $this->grav->fireEvent('onAdminAfterDelMedia', new Event(['page' => $page])); $this->admin->json_response = [