correctif purgeFile
This commit is contained in:
parent
afb74179f8
commit
d773f10099
|
@ -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('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
|
|
Loading…
Reference in New Issue