public function remove(File $file, $anyway = false) { if ($anyway || $file->getProgram()) { // remove database entry $this->em->remove($file); } else { // set file as deleted $file->setDeleted(true); } $this->em->flush(); // Remove file from project $project = $file->getProject(); $this->pm->removeFile($project, $file); // Remove files $projectPath = $this->pm->getProjectPath($project); $fs = new Filesystem(); $storageName = $this->getFilePath($file); if ($file->getProgram()) { // File is a program $codePath = $projectPath . "/" . $storageName . "_code"; $statementsPath = $projectPath . "/" . $storageName . "_statements"; if ($fs->exists($codePath)) { $fs->remove($codePath); } if ($fs->exists($statementsPath)) { $fs->remove($statementsPath); } } else { // File is not a program $filePath = $projectPath . "/" . $storageName; if ($fs->exists($filePath)) { $fs->remove($filePath); } } }
public function updateFile(Project $project, File $file) { // Update log $entry = new Log(); $entry->setProject($project); $entry->setOperation("update"); $entry->setData(json_encode(array('name' => $file->getName(), 'program' => $file->getProgram()))); $entry->setUser($this->user); $this->em->persist($entry); $this->em->flush(); }