mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-04-05 12:18:49 +02:00
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user