コード例 #1
0
 public function uploadFiles(Container $container, OutputInterface $output)
 {
     $finder = new Finder();
     $finder->files()->in($this->getContainer()->getParameter("kernel.root_dir") . "/../web/bundles")->notName("*.ttf")->notName("*.eot")->notName("*.otf")->notName("*.woff")->notName("*.svg");
     $x = 0;
     $files = [];
     foreach ($finder as $file) {
         if ($x < 100) {
             $files[] = ["name" => sprintf("bundles/%s", $file->getRelativePathname()), "path" => $file->getRealPath()];
             $x++;
         }
         if ($x >= 100) {
             $uploaded = false;
             $tryes = 0;
             while (!$uploaded && $tryes < 5) {
                 try {
                     $tryes++;
                     $container->uploadObjects($files);
                     $uploaded = true;
                 } catch (\Exception $e) {
                     if ($tryes >= 5) {
                         $output->writeln(sprintf("<error>Guzzle Returned ServerErrorResponseException - Cancelled Upload </error>"));
                         throw $e;
                     }
                     $output->writeln(sprintf("<error>Guzzle ServerErrorResponseException We will try again in 5 seconds</error>"));
                     sleep(5);
                 }
             }
             $files = [];
             $output->writeln(sprintf("<comment>100 files uploaded</comment>"));
             $x = 0;
         }
     }
     if ($x != 0) {
         $container->uploadObjects($files);
         $output->writeln(sprintf("<comment>%s files uploaded</comment>", $x));
         $x = 0;
     }
 }