diff --git a/.github/workflows/recipe.yaml b/.github/workflows/recipe.yaml
index 40a8222..9eaaa19 100644
--- a/.github/workflows/recipe.yaml
+++ b/.github/workflows/recipe.yaml
@@ -18,6 +18,10 @@ jobs:
matrix:
php: ['7.4' ,'8.0', '8.1']
sylius: [ "~1.9.0", "~1.10.0", "~1.11.0", "~1.12.0"]
+ include:
+ - php: '8.1'
+ sylius: '~1.12.0'
+ sylius_paypal: '~1.5.0'
exclude:
- php: 8.1
sylius: "~1.9.0"
@@ -73,6 +77,13 @@ jobs:
run: |
composer require --no-install --no-scripts --no-progress sylius/sylius="${{ matrix.sylius }}"
+ # Fix Paypal 1.5 on Sylius 1.12 and PHP 8.1
+ - name: Make sure to install the required version of Sylius Paypal Plugin
+ if: ${{ matrix.sylius_paypal }}
+ working-directory: ./sylius
+ run: |
+ composer require --no-install --no-scripts --no-progress sylius/paypal-plugin="${{ matrix.sylius_paypal }}" # @see https://github.com/Sylius/PayPalPlugin/issues/295
+
- name: Setup some requirements
working-directory: ./sylius
run: |
diff --git a/Makefile b/Makefile
index ecb31ab..affad11 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,7 @@
SHELL=/bin/bash
APP_DIR=tests/Application
SYLIUS_VERSION=1.12.0
+SYLIUS_PAYPAL_VERSION=1.5.0
SYMFONY=cd ${APP_DIR} && symfony
COMPOSER=symfony composer
CONSOLE=${SYMFONY} console
@@ -72,6 +73,7 @@ setup_application:
(cd ${APP_DIR} && ${COMPOSER} config --no-plugins allow-plugins true)
(cd ${APP_DIR} && ${COMPOSER} config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]')
(cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress sylius/sylius="~${SYLIUS_VERSION}") # Make sure to install the required version of sylius because the sylius-standard has a soft constraint
+ (cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress sylius/paypal-plugin="~${SYLIUS_PAYPAL_VERSION}") # @see https://github.com/Sylius/PayPalPlugin/issues/295
$(MAKE) ${APP_DIR}/.php-version
$(MAKE) ${APP_DIR}/php.ini
(cd ${APP_DIR} && ${COMPOSER} install --no-interaction)
diff --git a/src/Controller/BrowserController.php b/src/Controller/BrowserController.php
index afd47ca..4408ec8 100644
--- a/src/Controller/BrowserController.php
+++ b/src/Controller/BrowserController.php
@@ -21,6 +21,7 @@
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\FileTooBigException;
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\FolderNotCreatedException;
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\FolderNotDeletedException;
+use MonsieurBiz\SyliusMediaManagerPlugin\Exception\FolderNotRenamedException;
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\InvalidMimeTypeException;
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\InvalidTypeException;
use MonsieurBiz\SyliusMediaManagerPlugin\Helper\FileHelperInterface;
@@ -178,4 +179,25 @@ public function deleteFileAction(
return new JsonResponse(['folder' => '.' === $fileFolder ? '' : $fileFolder]);
}
+
+ public function renameFolderAction(
+ FileHelperInterface $fileHelper,
+ Request $request,
+ TranslatorInterface $translator
+ ): ?Response {
+ $newName = (string) $request->request->get('newName', '');
+ $path = (string) $request->request->get('path', '');
+ $folder = (string) $request->request->get('folder', '');
+ $newPath = $path;
+
+ try {
+ $newPath = $fileHelper->renameFolder($newName, $path, $folder);
+ } catch (FolderNotRenamedException $e) {
+ return new JsonResponse([
+ 'error' => $translator->trans('monsieurbiz_sylius_media_manager.error.cannot_rename_folder'),
+ ], Response::HTTP_BAD_REQUEST);
+ }
+
+ return new JsonResponse(['path' => $newPath]);
+ }
}
diff --git a/src/Exception/FolderNotRenamedException.php b/src/Exception/FolderNotRenamedException.php
new file mode 100644
index 0000000..9eac2a5
--- /dev/null
+++ b/src/Exception/FolderNotRenamedException.php
@@ -0,0 +1,32 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE.txt
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace MonsieurBiz\SyliusMediaManagerPlugin\Exception;
+
+use Exception;
+
+final class FolderNotRenamedException extends Exception
+{
+ private string $folder;
+
+ public function __construct(string $folder)
+ {
+ $this->folder = $folder;
+ parent::__construct(sprintf('Folder `%s` couldn\'t be renamed', $folder));
+ }
+
+ public function getFolder(): string
+ {
+ return $this->folder;
+ }
+}
diff --git a/src/Helper/FileHelper.php b/src/Helper/FileHelper.php
index cc95cc9..15382d5 100644
--- a/src/Helper/FileHelper.php
+++ b/src/Helper/FileHelper.php
@@ -21,6 +21,7 @@
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\FileTooBigException;
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\FolderNotCreatedException;
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\FolderNotDeletedException;
+use MonsieurBiz\SyliusMediaManagerPlugin\Exception\FolderNotRenamedException;
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\InvalidMimeTypeException;
use MonsieurBiz\SyliusMediaManagerPlugin\Exception\InvalidTypeException;
use MonsieurBiz\SyliusMediaManagerPlugin\Model\File;
@@ -292,6 +293,33 @@ public function deleteFile(string $path, ?string $folder = null): string
return $parentPath;
}
+ /**
+ * @SuppressWarnings(PHPMD.ErrorControlOperator)
+ */
+ public function renameFolder(string $newFolderName, string $path, ?string $folder = null): string
+ {
+ // Append the wanted folder from the root public media if necessary
+ if (!empty($folder)) {
+ $this->currentDirectory = $this->mediaDirectory . '/' . $this->cleanPath($folder);
+ }
+
+ // We remove the last part of the path to get the parent path
+ $arrayPath = explode('/', $path, -1);
+ $arrayPath[] = $newFolderName;
+ $newPath = implode('/', $arrayPath);
+
+ $oldPath = $this->getFullPath($path);
+ $newFolderName = (string) $this->slugger->slug($newFolderName);
+ $newFolderName = mb_strtolower($newFolderName, 'UTF-8');
+ $newFolderPath = $this->getFullPath($newPath);
+
+ if (!@rename($oldPath, $newFolderPath)) {
+ throw new FolderNotRenamedException($newFolderName);
+ }
+
+ return $newPath;
+ }
+
/**
* Clean path to avoid server intrusions.
*/
diff --git a/src/Helper/FileHelperInterface.php b/src/Helper/FileHelperInterface.php
index 7188bc2..2b0a123 100644
--- a/src/Helper/FileHelperInterface.php
+++ b/src/Helper/FileHelperInterface.php
@@ -94,6 +94,8 @@ public function deleteFolder(string $path, ?string $folder = null): string;
public function deleteFile(string $path, ?string $folder = null): string;
+ public function renameFolder(string $newFolderName, string $path, ?string $folder = null): string;
+
/**
* Clean path to avoid server intrusions.
*/
diff --git a/src/Resources/config/routes/admin.yaml b/src/Resources/config/routes/admin.yaml
index b79a9a3..6f309af 100644
--- a/src/Resources/config/routes/admin.yaml
+++ b/src/Resources/config/routes/admin.yaml
@@ -40,3 +40,10 @@ monsieurbiz_sylius_media_manager_admin_browser_delete_file:
defaults:
_controller: 'MonsieurBiz\SyliusMediaManagerPlugin\Controller\BrowserController::deleteFileAction'
condition: 'request.headers.get("X-Requested-With") == "XMLHttpRequest"'
+
+monsieurbiz_sylius_media_manager_admin_browser_rename_folder:
+ path: browser/renameFolder
+ methods: [ POST ]
+ defaults:
+ _controller: 'MonsieurBiz\SyliusMediaManagerPlugin\Controller\BrowserController::renameFolderAction'
+ condition: 'request.headers.get("X-Requested-With") == "XMLHttpRequest"'
diff --git a/src/Resources/translations/messages.en.yaml b/src/Resources/translations/messages.en.yaml
index 6ffbf47..14eb7e2 100644
--- a/src/Resources/translations/messages.en.yaml
+++ b/src/Resources/translations/messages.en.yaml
@@ -10,12 +10,16 @@ monsieurbiz_sylius_media_manager:
choose_video: Choose a video
create_folder: New folder
delete_folder: Delete this folder
+ rename_folder: Rename this folder
delete_file: Delete this file
create: Create
+ rename: Rename
upload_file_in_this_folder: New file in this folder
delete_folder_confirm: Are you sure you want to delete the folder `%path%` ?
delete_file_confirm: Are you sure you want to delete the file `%path%` ?
delete_file_confirm_bis: If it is used it will no longer be accessible, do you confirm this?
+ rename_folder_confirm: Are you sure you want to rename the folder `%path%` ?
+ rename_folder_confirm_bis: If files are in this folder or subfolders they will not be accessible anymore, do you confirm this ?
remove_file: Remove file
remove_image: Remove image
remove_video: Remove video
@@ -27,6 +31,7 @@ monsieurbiz_sylius_media_manager:
cannot_find_input: Form input cannot be found.
cannot_find_type: Cannot find type of file.
cannot_upload_file: Cannot upload the file.
+ cannot_rename_folder: Cannot rename the folder.
invalid_type_input: Invalid file type in input.
file_not_found: File not found.
folder_not_readable: Cannot read the folder '%folder%'.
@@ -37,4 +42,4 @@ monsieurbiz_sylius_media_manager:
pdf: The chosen file is not a PDF.
favicon: The chosen file is not a favicon.
file: The chosen file is not a valid file.
- max_file_size: The file is bigger than the maxc allowed size of %maxSize%.
+ max_file_size: The file is bigger than the max allowed size of %maxSize%.
diff --git a/src/Resources/translations/messages.fr.yaml b/src/Resources/translations/messages.fr.yaml
index aa10492..4359687 100644
--- a/src/Resources/translations/messages.fr.yaml
+++ b/src/Resources/translations/messages.fr.yaml
@@ -10,12 +10,16 @@ monsieurbiz_sylius_media_manager:
choose_video: Choisir une vidéo
create_folder: Nouveau dossier
delete_folder: Supprimer ce dossier
+ rename_folder: Renommer le dossier
delete_file: Supprimer ce fichier
create: Créer
+ rename: Renommer
upload_file_in_this_folder: Nouveau fichier dans ce dossier
delete_folder_confirm: Êtes-vous sûr de vouloir supprimer le dossier `%path%` ?
delete_file_confirm: Êtes-vous sûr de vouloir supprimer le fichier `%path%` ?
delete_file_confirm_bis: S'il est utilisé il ne sera plus accessible, confirmez-vous cela ?
+ rename_folder_confirm: Êtes-vous sûr de vouloir renommer le dossier `%path%` ?
+ rename_folder_confirm_bis: Si des fichiers sont contenus dans ce dossier ou ses enfants, ils ne seront plus accessibles, confirmez-vous cela ?
remove_file: Retirer le fichier
remove_image: Retirer l'image
remove_video: Retirer la video
@@ -27,6 +31,7 @@ monsieurbiz_sylius_media_manager:
cannot_find_input: Champ de formulaire introuvable.
cannot_find_type: Type de fichier introuvable.
cannot_upload_file: Impossible d'ajouter le fichier.
+ cannot_rename_folder: Impossible de renommer le dossier.
invalid_type_input: Type de fichier invalide dans le champ.
file_not_found: Fichier introuvable.
folder_not_readable: Impossible de lire le dossier '%folder%'.
diff --git a/src/Resources/views/Admin/MediaManager/Modal/Content/_newFolder.html.twig b/src/Resources/views/Admin/MediaManager/Modal/Content/_newFolder.html.twig
index 94493e6..8aa57fb 100644
--- a/src/Resources/views/Admin/MediaManager/Modal/Content/_newFolder.html.twig
+++ b/src/Resources/views/Admin/MediaManager/Modal/Content/_newFolder.html.twig
@@ -4,7 +4,7 @@
{# Button to create folder #}