/**
  * @param $contractId
  * @return bool
  */
 public function execute($contractId)
 {
     $this->contract_id = $contractId;
     $contract = $this->contract->find($contractId);
     $startTime = Carbon::now();
     try {
         $this->logger->info("processing Contract", ['contractId' => $contractId]);
         list($writeFolderPath, $readFilePath) = $this->setup($contract);
         if ($this->process($writeFolderPath, $readFilePath)) {
             $pages = $this->page->buildPages($writeFolderPath);
             $this->page->savePages($contractId, $pages);
             $this->updateContractPdfStructure($contract, $writeFolderPath);
             $contract->text_status = Contract::STATUS_DRAFT;
             $contract->save();
             $this->logger->info("processing contract completed.", ['contractId' => $contractId]);
             $this->mailer->send(['email' => $contract->created_user->email, 'name' => $contract->created_user->name], "{$contract->title} processing contract completed.", 'emails.process_success', ['contract_title' => $contract->title, 'contract_id' => $contract->id, 'contract_detail_url' => route('contract.show', $contract->id), 'start_time' => $startTime->toDayDateTimeString(), 'end_time' => Carbon::now()->toDayDateTimeString()]);
             $this->contract->moveS3File($contract->file, sprintf('%s/%s', $contract->id, $contract->getS3PdfName()));
             $this->contract->updateFileName($contract);
             $this->uploadPdfsToS3($contract->id);
             $this->deleteContractFolder($contract->id);
             $this->contract->updateWordFile($contract->id);
             return true;
         }
     } catch (\Exception $e) {
         $this->processStatus(Contract::PROCESSING_FAILED);
         $this->mailer->send(['email' => $contract->created_user->email, 'name' => $contract->created_user->name], "{$contract->title} processing error.", 'emails.process_error', ['contract_title' => $contract->title, 'contract_id' => $contract->id, 'contract_detail_url' => route('contract.show', $contract->id), 'start_time' => $startTime->toDayDateTimeString(), 'error' => $e->getMessage()]);
         $this->logger->error("error processing contract.{$e->getMessage()}", ['contractId' => $contractId]);
         return false;
     }
     return false;
 }
 /**
  * Move pdf file
  *
  * @param null $contract_id
  * @return bool
  */
 public function movePdFToFolder($contract_id = null)
 {
     if (is_null($contract_id)) {
         $contracts = $this->contract->getProcessCompleted();
         foreach ($contracts as $contract) {
             $file = $contract->file;
             $moveTo = sprintf('%s/%s', $contract->id, $contract->file);
             if ($this->contract->moveS3File($file, $moveTo)) {
                 $this->info(sprintf('Contract %s : completed.', $contract_id));
                 continue;
             }
             $this->info(sprintf('Contract %s : failed.', $contract_id));
         }
         return true;
     }
     $contract = $this->contract->find($contract_id);
     $file = $contract->file;
     $moveTo = sprintf('%s/%s', $contract->id, $contract->file);
     if ($this->contract->moveS3File($file, $moveTo)) {
         $this->info(sprintf('Contract %s : completed.', $contract_id));
         return true;
     }
     $this->info(sprintf('Contract %s : failed.', $contract_id));
     return true;
 }