Exemple #1
0
 private function send_mails(Application $app, FtpExport $export)
 {
     $transferts = [];
     $transfert_status = $this->translator->trans('task::ftp:Tous les documents ont ete transferes avec succes');
     foreach ($export->getElements() as $element) {
         if (!$element->isError() && $element->isDone()) {
             $transferts[] = '<li>' . $this->translator->trans('task::ftp:Record %recordid% - %filename% de la base (%databoxname% - %collectionname%) - %subdefname%', ['%recordid%' => $element->getRecordId(), '%filename%' => $element->getFilename(), '%databoxname%' => \phrasea::sbas_labels(\phrasea::sbasFromBas($app, $element->getBaseId()), $app), '%collectionname%' => \phrasea::bas_labels($element->getBaseId(), $app), $element->getSubdef(), '%subdefname%' => $element->getSubdef()]) . ' : ' . $this->translator->trans('Transfert OK') . '</li>';
         } else {
             $transferts[] = '<li>' . $this->translator->trans('task::ftp:Record %recordid% - %filename% de la base (%databoxname% - %collectionname%) - %subdefname%', ['%recordid%' => $element->getRecordId(), '%filename%' => $element->getFilename(), '%databoxname%' => \phrasea::sbas_labels(\phrasea::sbasFromBas($app, $element->getBaseId()), $app), '%collectionname%' => \phrasea::bas_labels($element->getBaseId(), $app), $element->getSubdef(), '%subdefname%' => $element->getSubdef()]) . ' : ' . $this->translator->trans('Transfert Annule') . '</li>';
             $transfert_status = $this->translator->trans('task::ftp:Certains documents n\'ont pas pu etre tranferes');
         }
     }
     if ($export->getCrash() >= $export->getNbretry()) {
         $connection_status = $this->translator->trans('Des difficultes ont ete rencontres a la connection au serveur distant');
     } else {
         $connection_status = $this->translator->trans('La connection vers le serveur distant est OK');
     }
     $text_mail_sender = $export->getTextMailSender();
     $text_mail_receiver = $export->getTextMailReceiver();
     $sendermail = $export->getSendermail();
     $ftp_server = $export->getAddr();
     $message = "\n\n----------------------------------------\n\n";
     $message = $connection_status . "\n";
     $message .= $transfert_status . "\n";
     $message .= $this->translator->trans("task::ftp:Details des fichiers") . "\n\n";
     $message .= implode("\n", $transferts);
     $sender_message = $text_mail_sender . $message;
     $receiver_message = $text_mail_receiver . $message;
     try {
         $receiver = new Receiver(null, $sendermail);
         $mail = MailSuccessFTPSender::create($app, $receiver, null, $sender_message);
         $mail->setServer($ftp_server);
         $app['notification.deliverer']->deliver($mail);
     } catch (InvalidArgumentException $e) {
     }
     try {
         $receiver = new Receiver(null, $export->getMail());
         $mail = MailSuccessFTPReceiver::create($app, $receiver, null, $receiver_message);
         $mail->setServer($ftp_server);
         $app['notification.deliverer']->deliver($mail);
     } catch (\Exception $e) {
         $this->log('debug', sprintf('Unable to deliver success message : %s', $e->getMessage()));
     }
 }
 public function getMail()
 {
     $mail = MailSuccessFTPSender::create($this->getApplication(), $this->getReceiverMock(), $this->getEmitterMock(), $this->getMessage());
     $mail->setServer('ftp://example.com');
     return $mail;
 }