An error occurred while loading the file. Please try again.
-
Guillaume Perréal authored
Utilisation des scripts composer.
5b1bde2c
<?php declare(strict_types=1);
/*
* irstea/file-upload-bundle - Bundle de gestion de fichiers intégrée à Symfony et Twitter-Bootstrap.
* Copyright (C) 2015-2019 Irstea <dsi.poleis.contact@lists.irstea.fr>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
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\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Description of GarbageCollectorCommand.
*/
class CollectGarbageCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('irstea:file-upload:collect-garbage')
->setDescription('Nettoie les fichiers orphelins et partiels.')
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Affiche ce qui devrait être fait, sans le faire');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var FileManagerInterface $manager */
$manager = $this->getContainer()->get('irstea_file_upload.file_manager');
$files = $manager->findGarbage();
if (count($files) === 0) {
$output->writeln('Aucun fichier à supprimer.');
return;
}
if ($input->getOption('dry-run')) {
$output->writeln(sprintf('%d fichier(s) à supprimer.', count($files)));
return;
}
$output->writeln('Suppression des fichiers');
$progress = new ProgressBar($output, count($files));
$progress->start();
7172737475767778798081
foreach ($files as $file) {
$manager->delete($file);
$progress->advance();
}
$progress->finish();
$output->writeln('');
}
}