em = $om; $this->jo_cache = $jo_cache; parent::__construct(); } protected function configure() { $this->setName('joborder:refresh_latest_cache') ->setDescription('Refresh latest active job order cache from database.') ->setHelp('Refresh latest active job order cache from database.'); } protected function execute(InputInterface $input, OutputInterface $output) { // for logging purposes $tmp_cache_log = fopen('/tmp/cache_logs.txt', 'a'); // remove all entries in cache $this->jo_cache->clearLatestActiveJobOrderCache(); fwrite($tmp_cache_log, 'Cleared latest active jo cache...' . "\n"); $date = new DateTime(); $date->modify('-5 hour'); $status_list = [ JOStatus::PENDING, JOStatus::RIDER_ASSIGN, JOStatus::ASSIGNED, JOStatus::IN_TRANSIT, JOStatus::IN_PROGRESS, ]; $qb = $this->em->getRepository(JobOrder::class) ->createQueryBuilder('jo'); $res = $qb->select('jo') ->where('jo.status IN (:statuses)') ->andWhere('jo.date_schedule >= :date') ->setParameter('statuses', $status_list, Connection::PARAM_STR_ARRAY) ->setParameter('date', $date) ->getQuery() ->execute(); // add each to latest active cache foreach ($res as $jo) { $this->jo_cache->addLatestActiveJoborder($jo); } fwrite($tmp_cache_log, 'Refreshed latest active jo cache...' . "\n"); fclose($tmp_cache_log); return 0; } }