Skip to content
Snippets Groups Projects
Commit 7f1b2a13 authored by Camille Simiand's avatar Camille Simiand
Browse files

Replace video URL with a new one

parent 07eb9611
No related branches found
No related tags found
1 merge request!48tuleap-133-change-the-video-url-of-a-capsule
......@@ -7,6 +7,7 @@ use App\Entity\PendingEditorInvitation;
use App\Exception\ZipArchiveNotOpeningException;
use App\Form\EditVideoUrlFormType;
use App\Form\RemoveEditorFormType;
use App\Repository\CapsuleRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Component\Config\Util\Exception\XmlParsingException;
......@@ -51,7 +52,7 @@ class ProjectController extends AbstractController
$this->extractZipArchiveInNewCapsuleDirectory($capsule_directory);
$this->addProjectVideoUrlInXMLProjectFile($capsule_directory, $video_url);
$this->setVideoUrlNodeAttributeInXMLProjectFile($capsule_directory, $video_url);
$this->createOrUpdatePasswordFile($capsule_directory, $capsule->getPassword());
......@@ -130,9 +131,9 @@ class ProjectController extends AbstractController
$zip->close();
}
private function addProjectVideoUrlInXMLProjectFile(string $capsule_directory, string $video_url): void
private function setVideoUrlNodeAttributeInXMLProjectFile(string $project_directory, string $video_url): void
{
$project_xml_file = $capsule_directory . "/file/project.xml";
$project_xml_file = $project_directory . "/file/project.xml";
$xml_file_content = simplexml_load_file($project_xml_file);
if (false === $xml_file_content) {
......@@ -171,16 +172,32 @@ class ProjectController extends AbstractController
/**
* @Route("/capsule/{capsule_id}/edit_video_url", name="edit_video_url")
*/
public function editVideoUrl(int $capsule_id, Request $request, TranslatorInterface $translator): Response
{
public function editVideoUrl(
int $capsule_id,
Request $request,
TranslatorInterface $translator,
CapsuleRepository $capsule_repository
): Response {
$capsule = $capsule_repository->findOneBy(['id' => $capsule_id]);
if (! $capsule instanceof Capsule) {
throw new \Exception('The retrieved capsule is not an instance of Capsule.');
}
$form = $this->createForm(EditVideoUrlFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$new_video_url = $form->get('new_video_url')->getData();
$project_directory = $capsule->getLinkPath();
chdir('../legacy/');
$this->setVideoUrlNodeAttributeInXMLProjectFile($project_directory, $new_video_url);
// $this->rescheduleProjectAnnotations($project_XML_file_path);
$this->addFlash(
'success',
$translator->trans(
'editors.remove.pending_editor.success'
'capsule.edit.video_url.success'
)
);
......@@ -190,8 +207,7 @@ class ProjectController extends AbstractController
}
return $this->render('project/edit_video_url.html.twig', [
'editVideoUrlForm' => $form->createView(),
// 'capsule_id' => $capsule_id
'editVideoUrlForm' => $form->createView()
]);
}
}
......@@ -16,7 +16,7 @@ class EditVideoUrlFormType extends AbstractType
{
$builder
->add(
'video_url',
'new_video_url',
UrlType::class,
[
'constraints' => [new NotBlank(['message' => 'capsule.video_url.not_blank'])],
......
......@@ -16,7 +16,7 @@
</div>
{{ form_start(editVideoUrlForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-column justify-content-center'}}) }}
{{ form_row(editVideoUrlForm.video_url, {'row_attr': {'class' : 'm-auto mb-4 col-6'}}) }}
{{ form_row(editVideoUrlForm.new_video_url, {'row_attr': {'class' : 'm-auto mb-4 col-6'}}) }}
{{ form_row(editVideoUrlForm.save, {'row_attr': {'class' : 'm-auto mb-5 col-2'}}) }}
{{ form_end(editVideoUrlForm) }}
......
......@@ -75,6 +75,7 @@ capsule:
link: Edit video URL
text: Enter a new video URL from Youtube or Vimeo
title: Edit video URL
success: The video URL of the project has been updated successfully
duplicate:
link: Duplicate capsule
title: Duplicate capsule
......
......@@ -72,6 +72,7 @@ capsule:
link: Modifier l'URL de la vidéo
text: Saisir l'URL de la nouvelle vidéo Youtube ou Vimeo
title: Modifier l'URL de la vidéo
success: L'URL de la vidéo du projet a bien été mise à jour
duplicate:
link: Dupliquer la capsule
title: Dupliquer la capsule
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment