diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-29 01:28:38 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-29 01:28:38 +0200 |
commit | 35e428c077dac7e57e6f6833562c88ae4a9867da (patch) | |
tree | ff4dae3dbd993ccf9e7af2807e007a8943ee8062 /app/class/Controllermedia.php | |
parent | 1e6eb30dbb3cb546f30650edd6c1db43167fdb53 (diff) | |
download | wcms-35e428c077dac7e57e6f6833562c88ae4a9867da.tar.gz wcms-35e428c077dac7e57e6f6833562c88ae4a9867da.zip |
feature : rename media fix #82
Diffstat (limited to 'app/class/Controllermedia.php')
-rw-r--r-- | app/class/Controllermedia.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php index c6e5d6c..0d75de7 100644 --- a/app/class/Controllermedia.php +++ b/app/class/Controllermedia.php @@ -3,6 +3,7 @@ namespace Wcms; use Exception; +use InvalidArgumentException; use LogicException; class Controllermedia extends Controller @@ -116,6 +117,33 @@ class Controllermedia extends Controller $this->mediamanager->multimovefile($_POST['id'], $_POST['dir']); } } - $this->redirect($this->generate('media') . '?path=/' . $_POST['path']); + $this->redirect($this->generate('media') . $_POST['route']); + } + + public function rename() + { + if ( + $this->user->issupereditor() + && isset($_POST['oldid']) + && isset($_POST['newid']) + && isset($_POST['oldextension']) + && isset($_POST['newextension']) + && isset($_POST['path']) + ) { + $newid = idclean($_POST['newid']); + $newextension = idclean($_POST['newextension']); + if (!empty($newid) && !empty($newextension)) { + $oldname = $_POST['path'] . $_POST['oldid'] . '.' . $_POST['oldextension']; + $newname = $_POST['path'] . $newid . '.' . $newextension; + try { + $this->mediamanager->rename($oldname, $newname); + } catch (InvalidArgumentException $e) { + Model::sendflashmessage($e->getMessage(), 'error'); + } + } else { + Model::sendflashmessage('Invalid name or extension', 'warning'); + } + } + $this->redirect($this->generate('media') . $_POST['route']); } } |