/** * @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; }
/** * Display all the tasks for a specific contract * @param $contract_id * @return string */ public function process($contract_id) { $contract = $this->contract->findWithTasks($contract_id); $contract->tasks = $this->task->appendAssignment($contract->tasks); $tasks = $this->task->getTotalByStatus($contract_id); $tasks['total_pages'] = $contract->tasks->count(); if ($tasks['total_pending_approval'] > 0) { $this->mailer->send(['email' => $contract->created_user->email, 'name' => $contract->created_user->name], sprintf("Mturk assignments for your action for [%s]", $contract->title), 'mturk.email.notify', ['task' => $tasks, 'contract' => ['id' => $contract->id, 'title' => $contract->title]]); } }