From d773f100991cd39f55ad02089582e91a734ce325 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 8 Jul 2020 17:17:05 +0200 Subject: [PATCH] correctif purgeFile --- .../src/Command/PurgeFileCommand.php | 153 +----------------- 1 file changed, 2 insertions(+), 151 deletions(-) diff --git a/src/nineskeletor-1.0/src/Command/PurgeFileCommand.php b/src/nineskeletor-1.0/src/Command/PurgeFileCommand.php index d485ded..53b81b4 100644 --- a/src/nineskeletor-1.0/src/Command/PurgeFileCommand.php +++ b/src/nineskeletor-1.0/src/Command/PurgeFileCommand.php @@ -52,31 +52,9 @@ class PurgeFileCommand extends Command $now=new \DateTime('now'); - // /uploads/document/activity - $this->writelnred(''); - $this->writelnred('== Directory = Activity'); - $this->purgeDocuemnt("activity"); + $directory=$this->container->get('kernel')->getProjectDir()."/public/uploads/avatar"; + echo $directory; - // /uploads/document/corrected - $this->writelnred(''); - $this->writelnred('== Directory = Corrected'); - $this->purgeDocuemnt("corrected"); - - // /uploads/document/answer - $this->writelnred(''); - $this->writelnred('== Directory = Answer'); - $this->purgeDocuemnt("answer"); - - // /uploads/document/answercorrected - $this->writelnred(''); - $this->writelnred('== Directory = Answercorrected'); - $this->purgeDocuemnt("answercorrected"); - - // /public/uploads/avatar - $this->writelnred(''); - $this->writelnred('== Directory = Avatar'); - - $directory=$this->container->get('kernel')->getRootDir()."/../public/uploads/avatar"; $files=[]; $fs = new Filesystem(); @@ -110,137 +88,10 @@ class PurgeFileCommand extends Command } } - // /public/uploads/ckeditor - $this->writelnred(''); - $this->writelnred('== Directory = Ckeditor'); - $directory=$this->container->get('kernel')->getRootDir()."/../public/uploads/ckeditor"; - $files=[]; - $fs = new Filesystem(); - - if($fs->exists($directory)) { - $finder = new Finder(); - $finder->in($directory)->files(); - - foreach (iterator_to_array($finder) as $file) { - $name = $file->getRelativePathname(); - $tofind = "/".$alias."/uploads/ckeditor/".$name; - $find=false; - - // On recherche l'image dans les activity.activity - $result = $this->em - ->getRepository("App:Activity")->createQueryBuilder('activity') - ->where('activity.activity LIKE :tofind') - ->setParameter('tofind', '%'.$tofind.'%') - ->getQuery()->getResult(); - if($result) $find=true; - - // Si pas trouvé on la cherche dans les activity.correctd - if(!$find) { - $result = $this->em - ->getRepository("App:Activity")->createQueryBuilder('activity') - ->where('activity.corrected LIKE :tofind') - ->setParameter('tofind', '%'.$tofind.'%') - ->getQuery()->getResult(); - if($result) $find=true; - } - - // Si pas trouvé on la cherche dans les answer.answer - if(!$find) { - $result = $this->em - ->getRepository("App:Answer")->createQueryBuilder('answer') - ->where('answer.answer LIKE :tofind') - ->setParameter('tofind', '%'.$tofind.'%') - ->getQuery()->getResult(); - if($result) $find=true; - } - - // Si pas trouvé on la cherche dans les answer.answercorrected - if(!$find) { - $result = $this->em - ->getRepository("App:Answer")->createQueryBuilder('answer') - ->where('answer.answercorrected LIKE :tofind') - ->setParameter('tofind', '%'.$tofind.'%') - ->getQuery()->getResult(); - if($result) $find=true; - } - - // Si pas trouvé on la cherche dans les document.description - if(!$find) { - $result = $this->em - ->getRepository("App:Document")->createQueryBuilder('document') - ->where('document.description LIKE :tofind') - ->setParameter('tofind', '%'.$tofind.'%') - ->getQuery()->getResult(); - if($result) $find=true; - } - - // Si pas trouvé on supprime - if(!$find) { - $this->writeln($name); - $url=$directory."/".$name; - if($fs->exists($url)) { - $fs->remove($url); - } - } - - } - } - - $this->writeln(''); return 1; } - private function purgeDocuemnt($entityname) { - $directory=$this->container->get('kernel')->getRootDir()."/../uploads/document/".$entityname; - $files=[]; - $fs = new Filesystem(); - - if($fs->exists($directory)) { - $finder = new Finder(); - $finder->in($directory)->directories()->exclude("thumb")->exclude("thumbmini"); - - foreach (iterator_to_array($finder) as $file) { - $name = $file->getRelativePathname(); - switch($entityname) { - case "activity" : $entity=$this->em->getRepository("App:Activity")->find($name); break; - case "corrected" : $entity=$this->em->getRepository("App:Activity")->find($name); break; - case "answer" : $entity=$this->em->getRepository("App:Answer")->find($name); break; - case "answercorrected" : $entity=$this->em->getRepository("App:Answer")->find($name); break; - - } - - if(!$entity) { - $url=$directory."/".$name; - if($fs->exists($url)) { - $this->writeln($name); - $fs->remove($url); - } - } - else { - $finder2 = new Finder(); - $finder2->in($directory."/".$name)->files()->exclude("thumb")->exclude("thumbmini"); - foreach (iterator_to_array($finder2) as $file2) { - $namefile = $file2->getRelativePathname(); - $entity=$this->em->getRepository("App:Document")->findOneBy(["entity"=>$entityname,"filename"=>$namefile]); - if(!$entity) { - $url=$directory."/".$name."/".$namefile; - $fs->remove($url); - - $url=$directory."/".$name."/thumb/".$namefile; - $fs->remove($url); - - $url=$directory."/".$name."/thumbmini/".$namefile; - $fs->remove($url); - - $this->writeln($namefile); - } - } - } - } - } - } - private function writelnred($string) { $this->output->writeln(''.$string.''); $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");