An error occurred while loading the file. Please try again.
-
ada66055
<?php declare(strict_types=1);
/*
* Copyright (C) 2015-2017 IRSTEA
* All rights reserved.
*/
namespace Irstea\FileUploadBundle\Command;
use Irstea\FileUploadBundle\Model\FileManagerInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Description of GarbageCollectorCommand.
*/
class CheckCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('irstea:file-upload:check')
->setDescription("Vérifie l'intégrité des fichiers.");
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/* @var $manager FileManagerInterface */
$manager = $this->getContainer()->get('irstea_file_upload.file_manager');
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$files = $manager->findFilesToValidate();
if (count($files) == 0) {
$output->writeln('Aucun fichier à vérifier.');
return;
}
$output->writeln('Vérification des fichiers');
$progress = new ProgressBar($output, count($files));
$progress->start();
foreach ($files as $file) {
$file->validate();
if (!$file->isValid()) {
$output->writeln(sprintf("\nFichier %s: %s", $file->getEtat(), $file->getPath()));
$em->persist($file);
}
$progress->advance();
}
$progress->finish();
$em->flush();
$output->writeln('');
}
}