mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-03 11:55:52 +01:00
Fixed a bug when deleting files via AJAX
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
1. [](#bugfix)
|
1. [](#bugfix)
|
||||||
* Fixed user login / remember me triggering before admin gets initialized
|
* Fixed user login / remember me triggering before admin gets initialized
|
||||||
|
* Fixed a bug when deleting files via AJAX
|
||||||
|
|
||||||
# v1.9.0-beta.6
|
# v1.9.0-beta.6
|
||||||
## 11/12/2018
|
## 11/12/2018
|
||||||
|
|||||||
@@ -882,13 +882,10 @@ class AdminPlugin extends Plugin
|
|||||||
|
|
||||||
public function onOutputGenerated()
|
public function onOutputGenerated()
|
||||||
{
|
{
|
||||||
// Clear flash objects for previously uploaded files
|
// Clear flash objects for previously uploaded files whenever the user switches page or reloads
|
||||||
// whenever the user switches page / reloads
|
|
||||||
// ignoring any JSON / extension call
|
// ignoring any JSON / extension call
|
||||||
if ($this->admin->task !== 'save' && empty($this->uri->extension())) {
|
if ($this->admin->task !== 'save' && empty($this->uri->extension())) {
|
||||||
// Discard any previously uploaded files session.
|
// Discard any previously uploaded files session and remove all uploaded files.
|
||||||
// and if there were any uploaded file, remove them from the filesystem
|
|
||||||
// FIXME:
|
|
||||||
if ($flash = $this->session->getFlashObject('files-upload')) {
|
if ($flash = $this->session->getFlashObject('files-upload')) {
|
||||||
$flash = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($flash));
|
$flash = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($flash));
|
||||||
foreach ($flash as $key => $value) {
|
foreach ($flash as $key => $value) {
|
||||||
|
|||||||
@@ -2,12 +2,10 @@
|
|||||||
namespace Grav\Plugin\Admin;
|
namespace Grav\Plugin\Admin;
|
||||||
|
|
||||||
use Grav\Common\Config\Config;
|
use Grav\Common\Config\Config;
|
||||||
use Grav\Common\Data\Data;
|
|
||||||
use Grav\Common\Filesystem\Folder;
|
use Grav\Common\Filesystem\Folder;
|
||||||
use Grav\Common\Grav;
|
use Grav\Common\Grav;
|
||||||
use Grav\Common\Media\Interfaces\MediaInterface;
|
use Grav\Common\Media\Interfaces\MediaInterface;
|
||||||
use Grav\Common\Page\Media;
|
use Grav\Common\Page\Media;
|
||||||
use Grav\Common\Page\Pages;
|
|
||||||
use Grav\Common\Utils;
|
use Grav\Common\Utils;
|
||||||
use Grav\Common\Plugin;
|
use Grav\Common\Plugin;
|
||||||
use Grav\Common\Theme;
|
use Grav\Common\Theme;
|
||||||
@@ -289,7 +287,7 @@ class AdminBaseController
|
|||||||
$this->admin->json_response = [
|
$this->admin->json_response = [
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'message' => sprintf($this->admin::translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD', null),
|
'message' => sprintf($this->admin::translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD', null),
|
||||||
$upload->file->name, $this->upload_errors[$upload->file->error])
|
$filename, $this->upload_errors[$upload->file->error])
|
||||||
];
|
];
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -312,7 +310,7 @@ class AdminBaseController
|
|||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
// Do not trust mimetype sent by the browser
|
// Do not trust mimetype sent by the browser
|
||||||
$mime = Utils::getMimeByFilename($upload->file->name);
|
$mime = Utils::getMimeByFilename($filename);
|
||||||
|
|
||||||
foreach ((array)$settings->accept as $type) {
|
foreach ((array)$settings->accept as $type) {
|
||||||
// Force acceptance of any file when star notation
|
// Force acceptance of any file when star notation
|
||||||
@@ -327,15 +325,15 @@ class AdminBaseController
|
|||||||
if ($isMime) {
|
if ($isMime) {
|
||||||
$match = preg_match('#' . $find . '$#', $mime);
|
$match = preg_match('#' . $find . '$#', $mime);
|
||||||
if (!$match) {
|
if (!$match) {
|
||||||
$errors[] = 'The MIME type "' . $mime . '" for the file "' . $upload->file->name . '" is not an accepted.';
|
$errors[] = 'The MIME type "' . $mime . '" for the file "' . $filename . '" is not an accepted.';
|
||||||
} else {
|
} else {
|
||||||
$accepted = true;
|
$accepted = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$match = preg_match('#' . $find . '$#', $upload->file->name);
|
$match = preg_match('#' . $find . '$#', $filename);
|
||||||
if (!$match) {
|
if (!$match) {
|
||||||
$errors[] = 'The File Extension for the file "' . $upload->file->name . '" is not an accepted.';
|
$errors[] = 'The File Extension for the file "' . $filename . '" is not an accepted.';
|
||||||
} else {
|
} else {
|
||||||
$accepted = true;
|
$accepted = true;
|
||||||
break;
|
break;
|
||||||
@@ -377,7 +375,6 @@ class AdminBaseController
|
|||||||
|
|
||||||
// Retrieve the current session of the uploaded files for the field
|
// Retrieve the current session of the uploaded files for the field
|
||||||
// and initialize it if it doesn't exist
|
// and initialize it if it doesn't exist
|
||||||
// FIXME:
|
|
||||||
$sessionField = base64_encode($this->grav['uri']->url());
|
$sessionField = base64_encode($this->grav['uri']->url());
|
||||||
$flash = $this->admin->session()->getFlashObject('files-upload');
|
$flash = $this->admin->session()->getFlashObject('files-upload');
|
||||||
if (!$flash) {
|
if (!$flash) {
|
||||||
@@ -452,10 +449,10 @@ class AdminBaseController
|
|||||||
if ($this->grav['uri']->extension() === 'json') {
|
if ($this->grav['uri']->extension() === 'json') {
|
||||||
$this->admin->json_response = [
|
$this->admin->json_response = [
|
||||||
'status' => 'unauthorized',
|
'status' => 'unauthorized',
|
||||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.'
|
'message' => $this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.'
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.',
|
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.',
|
||||||
'error');
|
'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,7 +549,7 @@ class AdminBaseController
|
|||||||
*/
|
*/
|
||||||
public function taskFilesSessionRemove()
|
public function taskFilesSessionRemove()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('save', $this->dataPermissions()) || !isset($_FILES)) {
|
if (!$this->authorizeTask('save', $this->dataPermissions())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,7 +564,6 @@ class AdminBaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the flash object and remove the requested file from it
|
// Retrieve the flash object and remove the requested file from it
|
||||||
// FIXME:
|
|
||||||
$flash = $this->admin->session()->getFlashObject('files-upload');
|
$flash = $this->admin->session()->getFlashObject('files-upload');
|
||||||
$endpoint = $flash[$request->sessionField][$request->field][$request->path];
|
$endpoint = $flash[$request->sessionField][$request->field][$request->path];
|
||||||
|
|
||||||
@@ -733,7 +729,6 @@ class AdminBaseController
|
|||||||
*/
|
*/
|
||||||
protected function storeFiles($obj)
|
protected function storeFiles($obj)
|
||||||
{
|
{
|
||||||
// FIXME: Add support for latest form plugin
|
|
||||||
// Process previously uploaded files for the current URI
|
// Process previously uploaded files for the current URI
|
||||||
// and finally store them. Everything else will get discarded
|
// and finally store them. Everything else will get discarded
|
||||||
$queue = $this->admin->session()->getFlashObject('files-upload');
|
$queue = $this->admin->session()->getFlashObject('files-upload');
|
||||||
@@ -753,7 +748,7 @@ class AdminBaseController
|
|||||||
$keys = explode('.', preg_replace('/^header./', '', $key));
|
$keys = explode('.', preg_replace('/^header./', '', $key));
|
||||||
$init_key = array_shift($keys);
|
$init_key = array_shift($keys);
|
||||||
if (count($keys) > 0) {
|
if (count($keys) > 0) {
|
||||||
$new_data = isset($obj->header()->{$init_key}) ? $obj->header()->{$init_key} : [];
|
$new_data = $obj->header()->{$init_key} ?? [];
|
||||||
Utils::setDotNotation($new_data, implode('.', $keys), $files, true);
|
Utils::setDotNotation($new_data, implode('.', $keys), $files, true);
|
||||||
} else {
|
} else {
|
||||||
$new_data = $files;
|
$new_data = $files;
|
||||||
@@ -807,7 +802,7 @@ class AdminBaseController
|
|||||||
if (!$data instanceof MediaInterface) {
|
if (!$data instanceof MediaInterface) {
|
||||||
$this->admin->json_response = [
|
$this->admin->json_response = [
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null), $folder)
|
'message' => sprintf($this->admin::translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null), $folder)
|
||||||
];
|
];
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -842,7 +837,6 @@ class AdminBaseController
|
|||||||
|
|
||||||
// Peak in the flashObject for optimistic filepicker updates
|
// Peak in the flashObject for optimistic filepicker updates
|
||||||
$pending_files = [];
|
$pending_files = [];
|
||||||
// FIXME:
|
|
||||||
$sessionField = base64_encode($this->grav['uri']->url());
|
$sessionField = base64_encode($this->grav['uri']->url());
|
||||||
$flash = $this->admin->session()->getFlashObject('files-upload');
|
$flash = $this->admin->session()->getFlashObject('files-upload');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user