Fix removing responsive image from page media re #111 re #952

This commit is contained in:
Flavio Copes
2017-02-06 18:03:14 +01:00
parent b580e86fbe
commit b775ff934d
2 changed files with 37 additions and 19 deletions

View File

@@ -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 = [