/**
  * Performs the logo transfer cron
  *
  * @throws \Exception
  */
 public function run()
 {
     $legacyContainer = new LegacyContainer();
     $rrpContainer = new RRPContainer();
     /** @var \Datasource_Core_Agents $agentClient */
     $agentClient = $legacyContainer->get('rrp.legacy.datasource.agent');
     $sftpLogoPath = $rrpContainer->get('rrp.config.sftp_logo_path');
     // Login to the SFTP server
     $sftp = $rrpContainer->get('rrp.sftp_client');
     if (!$sftp) {
         error_log(__FILE__ . ':' . __LINE__ . ':Remote Login Failed');
         throw new \Exception('Remote Login Failed');
     }
     // Get the list of logos to transfer
     $transferList = $agentClient->getAllDocumentLogoTransfers();
     // Attempt to put each file then check the size on the remote server matches to validate the transfer
     $successList = array();
     $failureList = array();
     foreach ($transferList as $sftpFileName => $uploadFileName) {
         $uploadFile = $sftpLogoPath . $sftpFileName;
         $sftp->put($sftpFileName, $uploadFile, NET_SFTP_LOCAL_FILE);
         $uploadSize = filesize($uploadFile);
         $sftpSize = $sftp->size($sftpFileName);
         if ($uploadSize == $sftpSize) {
             $successList[] = $sftpFileName;
         } else {
             $failureList[] = $sftpFileName;
         }
     }
     // Update the list of successful transfers
     if (count($successList) > 0) {
         if (!$agentClient->updateDocumentLogoTransfers($successList)) {
             $message = 'Failed to mark the successful logo transfers';
             error_log(__FILE__ . ':' . __LINE__ . ':' . $message);
             throw new \Exception($message);
         }
     }
     if (count($failureList) > 0) {
         $message = 'Failed to transfer files: ' . implode(', ', $failureList);
         error_log(__FILE__ . ':' . __LINE__ . ':' . $message);
         throw new \Exception($message);
     }
 }
 /**
  * Send the migration report
  */
 private function sendReport()
 {
     $subject = $this->rrpContainer->get('rrp.config.migration_report.email_subject');
     $message = '';
     $lineBreak = "\r\n";
     for ($type = self::POLICY_TYPE_MIGRATED; $type <= self::POLICY_TYPE_EXCEPTION; $type++) {
         if (count($this->reportPolicies[$type]) > 0) {
             $message .= $this->reportDescriptions[$type] . $lineBreak;
             foreach ($this->reportPolicies[$type] as $rrpPolicyNumber => $newPolicyNumber) {
                 if ($newPolicyNumber) {
                     $message .= sprintf('%s => %s%s', $rrpPolicyNumber, $newPolicyNumber, $lineBreak);
                 } else {
                     $message .= sprintf('%s error in database or rates not set up%s', $rrpPolicyNumber, $lineBreak);
                 }
             }
             $message .= $lineBreak . $lineBreak;
         }
     }
     if (empty($message)) {
         $message = 'No policies were migrated today.';
     }
     $mailManager = $this->legacyContainer->get('rrp.legacy.mailer');
     $mailManager->setTo($this->rrpContainer->get('rrp.config.migration_report.email_to_address'), $this->rrpContainer->get('rrp.config.migration_report.email_to_name'))->setFrom($this->rrpContainer->get('rrp.config.migration_report.email_from_address'), $this->rrpContainer->get('rrp.config.migration_report.email_from_name'))->setSubject($subject)->setBodyText($message)->send();
 }
 /**
  * Initialise from the params file
  */
 private function initialiseParams()
 {
     $rrpContainer = new RRPContainer();
     // Initialise from config file
     $this->username = $rrpContainer->get('rrp.config.survey.username');
     $this->password = $rrpContainer->get('rrp.config.survey.password');
     $this->userAgent = $rrpContainer->get('rrp.config.survey.userAgent');
     $this->cookieFile = $rrpContainer->get('rrp.config.survey.cookieFile');
     $this->loginUrl = $rrpContainer->get('rrp.config.survey.loginUrl');
     $this->loginQuery = $rrpContainer->get('rrp.config.survey.loginQuery');
     $this->reportUrl = $rrpContainer->get('rrp.config.survey.reportUrl');
     $this->csvFileUrl = $rrpContainer->get('rrp.config.survey.csvFileUrl');
     $this->sleepTime = $rrpContainer->get('rrp.config.survey.sleepTime');
     $this->csvFile = $rrpContainer->get('rrp.config.survey.csvFile');
     $this->dateFormat = $rrpContainer->get('rrp.config.survey.dateFormat');
     $this->surveyDetails = array();
     foreach (array(self::INCEPTION_SURVEY, self::RENEWAL_SURVEY) as $surveyType) {
         $this->surveyDetails[$surveyType] = array('surveyID' => $rrpContainer->get(sprintf('rrp.config.survey.%s.survey_id', $surveyType)), 'reportData' => $rrpContainer->get(sprintf('rrp.config.survey.%s.report_data', $surveyType)), 'reportMatch' => $rrpContainer->get(sprintf('rrp.config.survey.%s.report_match', $surveyType)), 'csvFileData' => $rrpContainer->get(sprintf('rrp.config.survey.%s.csv_file_data', $surveyType)), 'csvFileMatch' => $rrpContainer->get(sprintf('rrp.config.survey.%s.csv_file_match', $surveyType)), 'delimiter' => $rrpContainer->get(sprintf('rrp.config.survey.%s.delimiter', $surveyType)), 'policyColumnName' => $rrpContainer->get(sprintf('rrp.config.survey.%s.policy_column_name', $surveyType)), 'completeColumnName' => $rrpContainer->get(sprintf('rrp.config.survey.%s.complete_column_name', $surveyType)), 'emailDuration' => array('First' => $rrpContainer->get(sprintf('rrp.config.survey.%s.email_duration1', $surveyType)), 'Second' => $rrpContainer->get(sprintf('rrp.config.survey.%s.email_duration2', $surveyType))), 'emailFrom' => $rrpContainer->get(sprintf('rrp.config.survey.%s.email_from', $surveyType)), 'emailSubject' => $rrpContainer->get(sprintf('rrp.config.survey.%s.email_subject', $surveyType)), 'emailSurveyLink' => $rrpContainer->get(sprintf('rrp.config.survey.%s.email_surveyLink', $surveyType)));
     }
 }