Skip to content

Commit

Permalink
Fix removing responsive image from page media re #111 re #952
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed Feb 6, 2017
1 parent b580e86 commit b775ff9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 33 additions & 16 deletions classes/admincontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1540,34 +1540,51 @@ protected function taskDelmedia()
}

$targetPath = $page->path() . '/' . $filename;
$fileParts = pathinfo($filename);

if (!file_exists($targetPath)) {
$this->admin->json_response = [
'status' => 'error',
'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_NOT_FOUND') . ': ' . $filename
];
$found = false;

return 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;
}
}

$fileParts = pathinfo($filename);
$result = unlink($targetPath);

if (!$result) {
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_COULD_NOT_BE_DELETED') . ': ' . $filename
'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_NOT_FOUND') . ': ' . $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 = [
Expand Down

0 comments on commit b775ff9

Please sign in to comment.