adaptation pour minio
This commit is contained in:
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use App\Entity\Tallyday as Tallyday;
|
||||
|
||||
|
||||
class CleanCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('app:Clean')
|
||||
->setDescription('Nettoyage des données obsolètes')
|
||||
->setHelp('Nettoyage des données obsolètes')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->rootlog = $this->container->get('kernel')->getLogDir()."/";
|
||||
$alias = $this->container->getParameter('appAlias');
|
||||
|
||||
$this->writelnred('');
|
||||
$this->writelnred('== app:Clean');
|
||||
$this->writelnred('==========================================================================================================');
|
||||
|
||||
$now=new \DateTime('now');
|
||||
|
||||
$directory=$this->container->get('kernel')->getProjectDir()."/public/uploads/avatar";
|
||||
$this->writeln($directory);
|
||||
|
||||
$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();
|
||||
if($name!="admin.jpg"&&$name!="noavatar.png"&&$name!="system.jpg") {
|
||||
$entity=$this->em->getRepository("App\Entity\User")->findBy(["avatar"=>$name]);
|
||||
if(!$entity) {
|
||||
$this->writeln($name);
|
||||
$url=$directory."/".$name;
|
||||
if($fs->exists($url)) {
|
||||
$fs->remove($url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fs = new Filesystem();
|
||||
$users=$this->em->getRepository("App\Entity\User")->findAll();
|
||||
foreach($users as $user) {
|
||||
if(!$fs->exists($directory."/".$user->getAvatar())) {
|
||||
$this->writeln($user->getUsername());
|
||||
$user->setAvatar("noavatar.png");
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeln('');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
private function writeln($string) {
|
||||
$this->output->writeln($string);
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
}
|
||||
}
|
@ -487,22 +487,7 @@ class InitCommand extends Command
|
||||
);
|
||||
$output->writeln('');
|
||||
|
||||
|
||||
// Job de purge des fichiers obsolète
|
||||
// Toute les 24h à 3h00
|
||||
$entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(["command"=>"app:Clean"]);
|
||||
if(!$entity) {
|
||||
$entity = new Cron;
|
||||
$nextdate=$entity->getSubmitdate();
|
||||
$nextdate->setTime(3,0);
|
||||
$entity->setCommand("app:Clean");
|
||||
$entity->setDescription("Nettoyage des données obsolètes");
|
||||
$entity->setStatut(1);
|
||||
$entity->setRepeatinterval(86400);
|
||||
$entity->setNextexecdate($nextdate);
|
||||
$this->em->persist($entity);
|
||||
}
|
||||
|
||||
|
||||
// Job synchronisation des comptes utilisateur
|
||||
// Toute les 24h à 3h00
|
||||
$entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(["command"=>"app:Synchro"]);
|
||||
|
Reference in New Issue
Block a user