vendor/simpledot/edm-bundle/AWEdmBundle/Command/AwsS3MigrationCommand.php line 20

Open in your IDE?
  1. <?php
  2. namespace AWEdmBundle\Command;
  3. use AWEdmBundle\Entity\File;
  4. use AWEdmBundle\Exception\MigrationException;
  5. use AWEdmBundle\Factory\FileSystemFactory;
  6. use AWEdmBundle\Manager\DocumentManager;
  7. use AWEdmBundle\Migration\CmsMigration;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Helper\ProgressBar;
  12. use Symfony\Component\Console\Input\InputArgument;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. /**
  16.  * Script de migration des fichiers du CMS vers le GED.
  17.  */
  18. class AwsS3MigrationCommand extends ContainerAwareCommand
  19. {
  20.     /**
  21.      * @inheritdoc
  22.      */
  23.     protected function configure()
  24.     {
  25.         $this
  26.             ->setName('awedm:aws_s3:migration')
  27.             ->setDescription('Lance la migration des fichiers de la GED vers S3 ou inversement')
  28.             ->addArgument('action'InputArgument::OPTIONAL'upload (default) or download')
  29.         ;
  30.     }
  31.     /**
  32.      * @inheritdoc
  33.      */
  34.     protected function execute(InputInterface $inputOutputInterface $output)
  35.     {
  36.         /** @var File[] $files */
  37.         $files $this->getContainer()->get('doctrine')->getManager()->getRepository("AWEdmBundle:File")->findAll();
  38.         /** @var DocumentManager $documentManger */
  39.         $documentManger $this->getContainer()->get('awedm.manager.document');
  40.         if($input->getArgument('action') == null or $input->getArgument('action') == 'upload'){
  41.             $progress = new ProgressBar($outputcount($files));
  42.             foreach ($files as $file){
  43.                 if($file->getStorage() !== FileSystemFactory::AMAZON_S3){
  44.                     $saved $documentManger->changeStorageTo($fileFileSystemFactory::AMAZON_S3);
  45.                     if($saved){
  46.                         $output->writeln($file->getStorage().' =>'$file->getPath().' #'.$file->getId());
  47.                     }else{
  48.                         $output->writeln('<bg=yellow;fg=black>'.$file->getStorage().' =>'$file->getPath().' #'.$file->getId().'</>');
  49.                     }
  50.                 }
  51.                 $progress->advance();
  52.             }
  53.             $progress->finish();
  54.         }
  55.         elseif ($input->getArgument('action') == 'download'){
  56.             $progress = new ProgressBar($outputcount($files));
  57.             $progress->start();
  58.             foreach ($files as $file){
  59.                 if($file->getStorage() !== FileSystemFactory::LOCAL){
  60.                     $saved $documentManger->changeStorageTo($fileFileSystemFactory::LOCAL);
  61.                     if($saved){
  62.                         $output->writeln($file->getStorage().' => '$file->getPath().' #'.$file->getId());
  63.                     }else{
  64.                         $output->writeln('<bg=yellow;fg=black>'.$file->getStorage().' =>'$file->getPath().' #'.$file->getId().'</>');
  65.                     }
  66.                 }
  67.                 $progress->advance();
  68.             }
  69.             $progress->finish();
  70.         }
  71.         $output->writeln('');
  72.     }
  73. }