projectDir = $kernel->getProjectDir(); $this->params = $params; $this->container = $container; $this->templateRepository = $templateRepository; $this->exportsRepository = $exportsRepository; $this->fileTypeRepository = $fileTypeRepository; $this->templateCollect = $templateCollect; $this->templateQuery = $templateQuery; $this->entityManager = $entityManager; } protected function configure() { $this // the name of the command (the part after "bin/console") ->setName('transfert:dedicatedfile') // the short description shown while running "php bin/console list" ->setDescription('Transfert all Dedicated file from Template to Project'); } public function execute(InputInterface $input, OutputInterface $output) { $response = ''; $templates = $this->templateRepository->list(); if (!empty($templates)) { foreach($templates as $template){ $output->writeln("recherche pour : " . $template->getName()); $viewId = new CommonIdView($template->getId()); $templateFiles = $this->getFiles($viewId, $template->getTwig()->getExportType()); if(isset($templateFiles['files'])){ foreach($templateFiles['files'] as $templateFile){ if(!empty($templateFile)){ $output->writeln($templateFile['originalName']); // $fileType = $this->fileTypeRepository->findByNameAndExtension($templateFiles['extension'], $templateFile['extension']); // if(empty($fileType)){ // dump("extension inconnu dans la base"); // } // else{ // try { // $dedicatedFile = $this->setDedicatedFile($templateFile['file'],$templateFile['originalName'],$fileType, $template); // $this->entityManager->persist($dedicatedFile); // $output->writeln("transfert de ".$templateFile['originalName']." fini"); // } catch (Exception $e) { // $output->writeln($e->getMessage()); // } // } } } } $output->writeln("-------------------------------------"); } $this->entityManager->flush(); } $output->writeln($response); return $response; } /** * @param CommonIdView $templateView [description] * * @return array|Exception [description] */ private function getFiles(CommonIdView $templateView, int $export) { $result = []; $exportType = $this->exportsRepository::EXPORT_TYPE[$export]; if ($exportType === 'HTML') { $files = $this->templateCollect->getHTMLTemplateFilesGenerationData($templateView->id); // $view = new CommonIdView( // $id // ); // $pictosIds = $this->templateQuery->getPictoIds($view); // $dedicatedFiles = $this->templateQuery->geTHTMLFile($id); // $files = $dedicatedFiles; // $files['pictoIds'] = $pictosIds; if(isset($files['html'])) { $result['extension'] = "HTML"; $result['files'] = array_values($files['html']); } } else { // $view = new CommonIdView( // $id // ); // $pictosIds = $this->templateQuery->getPictoIds($view); // $dedicatedFiles = $this->templateQuery->getDedicatedFiles($view); // $files = ["pictoIds" => $pictosIds, "templateFiles" => $dedicatedFiles]; $files = $this->templateCollect->getTemplateFilesGenerationData($templateView->id); if(isset($files['templateFiles'])){ $result['extension'] = "Indesign"; $result['files'] = array_values($files['templateFiles']); } } return $result; } /** * @param string $file [description] * @param string $originalName [description] * @param string $sextension [description] * * @return void [description] */ private function setDedicatedFile(string $file, string $originalName, FileType $fileType, Template $template) { // if ($template->getId()) { // $this->archiveOldDedicatedFile($template->getId(), $fileType->getId()); // } $dedicatedFile = new DedicatedFile(); // $fileOriginalName = $file->getClientOriginalName(); $fileUniqName = $this->getUniqName($originalName); $dedicatedFile->setFileName($fileUniqName); $dedicatedFile->setOriginalName($originalName); // $tmpFile = $file->getRealPath(); // $fileContent = file_get_contents($tmpFile); $dedicatedFile->setFile($file); // $dedicatedFile->setUploadedFile($file); // TODO : If not useful remove from entity $dedicatedFile->setFileType($fileType); $dedicatedFile->setTemplate($template); return $dedicatedFile; } /** * @param string $name [description] * * @return string [description] */ private function getUniqName(string $name): string { $result = uniqid($name); return $result; } }