protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tools = new Tools();
     $import = time();
     $providers = ['theonyxpath'];
     $articles = [];
     foreach ($providers as $provider) {
         $output->writeln('Getting articles for provider: <info>' . $provider . '</info>');
         $site = $this->getContainer()->get('doctrine')->getRepository('OrcosSiteBundle:Site')->findOneBySlug($provider);
         $rawArticles = $this->getContainer()->get('orcos.providers')->getProvider($provider)->fetchArticles();
         $insertedArticles = 0;
         foreach ($rawArticles as $rawArticle) {
             $article = $rawArticle->getArticle($site);
             $article->setImport($import);
             $articleExists = $this->getContainer()->get('doctrine')->getRepository('OrcosSiteBundle:Article')->findOneBy(['site' => $site, 'hash' => $article->getHash()]);
             if (!$articleExists) {
                 $insertedArticles++;
                 $this->getContainer()->get('doctrine')->getManager()->persist($article);
                 // Save Image
                 foreach ($rawArticle->getImages() as $imageHash => $imageUrl) {
                     $saveDir = $this->getContainer()->getParameter('kernel.root_dir') . '/../web/assets/' . $site->getSlug() . '/';
                     if (!is_dir($saveDir)) {
                         mkdir($saveDir);
                     }
                     file_put_contents($saveDir . $imageHash, $this->getContainer()->get('orcos.fetcher')->fetchContent($imageUrl));
                     $tools->optimizeImage($saveDir . $imageHash);
                 }
             }
         }
         $output->writeln('New articles: <info>' . $insertedArticles . '</info>');
     }
     $this->getContainer()->get('doctrine')->getManager()->flush();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tools = new Tools();
     $finder = new Finder();
     foreach ($finder->files()->in($this->getContainer()->getParameter('kernel.root_dir') . '/../web/assets/') as $file) {
         try {
             $tools->optimizeImage($file->getPathName());
         } catch (\Exception $e) {
         }
     }
 }