Select Git revision
ProjectController.php 7.45 KiB
<?php
namespace App\Controller;
use App\Entity\Capsule;
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;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
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(
Capsule $capsule,
string $video_url
): Response {
chdir('../legacy/');
$capsule_name = $capsule->getName();
$capsule_directory = $capsule->getLinkPath();
if (file_exists($capsule_directory)) {
$this->addFlash(
'warning',
$this->translator->trans(
'project.already_exists',
[
'capsule_name' => $capsule_name
]
)
);
return $this->redirectToRoute('capsule_list');
}
$this->extractZipArchiveInNewCapsuleDirectory($capsule_directory);
$this->setVideoUrlNodeAttributeInXMLProjectFile($capsule_directory, $video_url);
$this->createOrUpdatePasswordFile($capsule_directory, $capsule->getPassword());
$this->addFlash(
'success',
$this->translator->trans(
'capsule.created_success',
[
'capsule_name' => $capsule_name