projectRepository = $projectRepository; $this->exportRepository = $exportRepository; $this->container = $container; } /** * @param CommonIdView $projectIdView * * @throws \Exception * * @return bool */ public function delete(CommonIdView $projectIdView): bool { $project = $this->projectRepository->findById($projectIdView->id); if ($project) { $exportIds = array_column($this->exportRepository->listIdsByProjectId($project->getId()), 'id'); $result = $this->projectRepository->delete($project); } else { throw new \Exception("No project found for id : $projectIdView->id !"); } return $result; } /** * @param CommonIdView $projectIdView * * @throws \Exception * * @return bool */ public function deleteProjectDocument(CommonIdView $projectIdView): bool { $projectDocument = $this->projectRepository->findProjectDocumentById($projectIdView->id); if ($projectDocument) { $projectId = md5($projectDocument->getProject()->getId()); $filename = $projectDocument->getFilename(); $result = $this->projectRepository->deleteProjectDocument($projectDocument); $filePath = $this->container->getParameter('files_directory').$projectId.'/'.$filename; if (file_exists($filePath)) { unlink($filePath); } } else { throw new \Exception("No project document found for id : $projectIdView->id !"); } return $result; } }