示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     ini_set('memory_limit', -1);
     set_time_limit(0);
     //$output->writeln('Timezone: ' . date_default_timezone_get());
     $availableFunctions = array('upsert_loan_to_los', 'upsert_loan_from_los', 'delete_loan', 'add_document', 'update_loans', 'delete_loans', 'cron', 'add_loan_prospects', 'upsert_milestones', 'add_queued_docs');
     $function = $input->getArgument('function');
     if (!in_array($function, $availableFunctions)) {
         throw new \Exception("Function does not exist");
     }
     $this->em = $this->getContainer()->get('doctrine')->getEntityManager();
     $this->logger = $this->getContainer()->get('logger');
     $this->output = $output;
     $loanId = $input->getOption('loan_id');
     if (isset($loanId)) {
         $this->loan = $this->em->getRepository('SudouxMortgageBundle:LoanApplication')->find($loanId);
         if (!isset($this->loan)) {
             throw new \Exception('Loan not found');
         }
     }
     $this->loanUtil = $this->getContainer()->get('sudoux_mortgage.los_util');
     $batchFunctions = array('update_loans', 'delete_loans', 'cron');
     if (in_array($function, $batchFunctions)) {
         $this->batchCommand = true;
         $this->batchJob = new BatchJob();
         $this->batchJob->setName('Loan Command: ' . $function);
         $this->em->persist($this->batchJob);
         $this->em->flush($this->batchJob);
     }
     switch ($function) {
         case 'upsert_loan_to_los':
             $this->loanUtil->upsertLoanToLos($this->loan);
             break;
         case 'upsert_loan_from_los':
             $this->loanUtil->upsertLoanFromLos($this->loan);
             break;
         case 'delete_loan':
             $this->loanUtil->deleteLoan($this->loan);
             break;
         case 'add_document':
             $documentId = $input->getOption('document_id');
             if (!isset($documentId)) {
                 throw new \Exception("add_document method requires the --document_id option");
             }
             $document = $this->em->getRepository('SudouxMortgageBundle:LoanDocument')->find($documentId);
             if (!isset($document)) {
                 throw new \Exception("Document not found.");
             }
             $response = $this->loanUtil->addDocument($this->loan, $document);
             if ($response['success']) {
                 $this->output->writeln($response['message']);
             } else {
                 $this->output->writeln(sprintf('Adding document %s failed: %s', $document->getId(), $response['message']));
             }
             break;
         case 'update_loans':
             $startDateOption = $input->getOption('start_date');
             if (!isset($startDateOption)) {
                 throw new \Exception("Start Date must be set");
             }
             $startDate = new \DateTime($startDateOption);
             //$startDate->modify('-1 day');
             //$startDate->setTimezone(new \DateTimeZone("UTC"));
             $this->processLoans($startDate, 'update');
             break;
         case 'delete_loans':
             $startDateOption = $input->getOption('start_date');
             if (!isset($startDateOption)) {
                 throw new \Exception("Start Date must be set");
             }
             $startDate = new \DateTime($startDateOption);
             //$startDate->modify('-1 day');
             //$startDate->setTimezone(new \DateTimeZone("UTC"));
             $this->processLoans('delete', $startDate);
             break;
         case 'add_loan_prospects':
             $this->loanUtil->addProspects($this->loan);
             break;
         case 'add_queued_docs':
             $startDateOption = $input->getOption('start_date');
             if (!isset($startDateOption)) {
                 throw new \Exception("Option --start_date must be set");
             }
             $startDate = new \DateTime($startDateOption);
             //$startDate->modify('-1 day');
             //$startDate->setTimezone(new \DateTimeZone("UTC"));
             $this->processLoans('add_docs', $startDate);
             break;
         case 'upsert_milestones':
             $siteId = $input->getOption('site_id');
             if (!isset($siteId)) {
                 throw new \Exception("Option --site_id must be set");
             }
             $site = $this->em->getRepository('SudouxCmsSiteBundle:Site')->find($siteId);
             if (isset($site)) {
                 $this->upsertMilestones($site);
             } else {
                 throw new \Exception("Site not found with ID: " . $siteId);
             }
             break;
         case 'cron':
             $this->processLoans('cron');
             break;
     }
     if ($this->batchCommand) {
         $completed = new \DateTime();
         $this->batchJob->setCompleted($completed);
         $this->batchJob->setStatus(1);
         $this->em->persist($this->batchJob);
         $this->em->flush($this->batchJob);
     }
 }