diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index 1186b4d88c00c2b20b6b6d3f94edc85b968dfc0f..62273a223632dec7c72a867afd04c81de0357614 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -22,12 +22,18 @@ use ZipArchive; class ProjectController extends AbstractController { + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + /** * @Route("/project/create", name="create_project", methods={"POST"}) * @throws ZipArchiveNotOpeningException */ public function create( - TranslatorInterface $translator, Capsule $capsule, string $video_url ): Response { @@ -39,7 +45,7 @@ class ProjectController extends AbstractController if (file_exists($capsule_directory)) { $this->addFlash( 'warning', - $translator->trans( + $this->translator->trans( 'project.already_exists', [ 'capsule_name' => $capsule_name @@ -58,7 +64,7 @@ class ProjectController extends AbstractController $this->addFlash( 'success', - $translator->trans( + $this->translator->trans( 'capsule.created_success', [ 'capsule_name' => $capsule_name @@ -74,7 +80,6 @@ class ProjectController extends AbstractController * @throws ZipArchiveNotOpeningException */ public function duplicate( - TranslatorInterface $translator, Capsule $capsule, string $parent_directory, Filesystem $file_system @@ -87,7 +92,7 @@ class ProjectController extends AbstractController if (file_exists($capsule_directory)) { $this->addFlash( 'warning', - $translator->trans( + $this->translator->trans( 'project.already_exists', [ 'capsule_name' => $capsule_name @@ -104,7 +109,7 @@ class ProjectController extends AbstractController $this->addFlash( 'success', - $translator->trans( + $this->translator->trans( 'capsule.duplicate.success', [ 'capsule_name' => $capsule_name @@ -175,7 +180,6 @@ class ProjectController extends AbstractController public function editVideoUrl( int $capsule_id, Request $request, - TranslatorInterface $translator, CapsuleRepository $capsule_repository ): Response { $capsule = $capsule_repository->findOneBy(['id' => $capsule_id]); @@ -183,6 +187,24 @@ class ProjectController extends AbstractController throw new \Exception('The retrieved capsule is not an instance of Capsule.'); } + $file_system = new Filesystem(); + $parent_directory_name = $capsule->getLinkPath(); + $parent_directory_exists = $file_system->exists('../legacy/' . $parent_directory_name); + + if (! $parent_directory_exists) { + $this->addFlash( + 'warning', + $this->translator->trans( + 'project.not_exist', + [ + 'capsule_name' => $capsule->getName() + ] + ) + ); + + return $this->redirectToRoute('capsule_list'); + } + $form = $this->createForm(EditVideoUrlFormType::class); $form->handleRequest($request); @@ -192,11 +214,10 @@ class ProjectController extends AbstractController chdir('../legacy/'); $this->setVideoUrlNodeAttributeInXMLProjectFile($project_directory, $new_video_url); -// $this->rescheduleProjectAnnotations($project_XML_file_path); $this->addFlash( 'success', - $translator->trans( + $this->translator->trans( 'capsule.edit.video_url.success' ) ); diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 415057818a94148cae7e1ce71722e87e0a8c5a7d..dca9f64e3b542dc44664919219c6ea725cb0c09b 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -93,7 +93,7 @@ capsule: project: already_exists: Project capsule_name already exists so the capsule could not be created - not_exist: The project to duplicate does not exist + not_exist: The project does not exist preview: loading: Project loading diff --git a/translations/messages.fr.yaml b/translations/messages.fr.yaml index 68b09993160217c67060d56105cd971ff936982c..a6502ad168de0a1998946982b5345b0e7fe95e2b 100644 --- a/translations/messages.fr.yaml +++ b/translations/messages.fr.yaml @@ -91,7 +91,7 @@ capsule: project: already_exists: Le projet capsule_name existe déjà. La capsule n'a pas pu être créée - not_exist: Le projet a dupliquer n'existe pas + not_exist: Le projet n'existe pas preview: loading: Projet en cours de chargement