src/Command/UpdateCommand.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Input\InputOption;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use App\Entity\Product;
  9. use App\Entity\Fx;
  10. use App\Controller\ProductController;
  11. class UpdateCommand extends ContainerAwareCommand {
  12.     protected function configure() {
  13.         $this
  14.                 ->setName('run:update')
  15.                 ->setDescription('Update product prices')
  16.         ;
  17.     }
  18.     protected function execute(InputInterface $inputOutputInterface $output) {
  19.         $updateService $this->getContainer()->get('product.update');
  20.         $em $this->getContainer()->get('doctrine')->getManager();
  21.         $updateService->updateFx();
  22.         $latestFx $em->getRepository('SAPriceMonitorBundle:Fx')->FindLatestFx();
  23.         $datetime = new \Datetime();
  24.         $now $datetime->format('Y-m-d H:i:s');
  25.         $now strtotime($now);
  26.         $allProducts $updateService->listProducts();
  27.         foreach ($allProducts as $product) {
  28.             $currentStatus $product->getStatuses()->first()->getStatus();
  29.             if ($currentStatus == || $currentStatus == || $currentStatus == 3) {
  30.                 $lastPriceUpdate $product->getPrices()->first()->getDate()->format('Y-m-d H:i:s');
  31.                 $lastPriceUpdate strtotime($lastPriceUpdate);
  32.                 $difference $now $lastPriceUpdate;
  33.                 $updateService->updateProduct($product$em$latestFx);
  34.                 //$output->writeln($product->getName() . ' updated');
  35.             }
  36.         }
  37.         $em->flush();
  38.     }
  39. }