Beispiel #1
0
 /**
  *
  * @param integer $usr_to
  * @param String  $host
  * @param String  $login
  * @param String  $password
  * @param integer $ssl
  * @param integer $retry
  * @param integer $passif
  * @param String  $destfolder
  * @param String  $makedirectory
  * @param String  $logfile
  *
  * @return boolean
  */
 public function export_ftp($usr_to, $host, $login, $password, $ssl, $retry, $passif, $destfolder, $makedirectory, $logfile)
 {
     $email_dest = '';
     if ($usr_to) {
         $user_t = $this->app['repo.users']->find($usr_to);
         $email_dest = $user_t->getEmail();
     }
     $text_mail_receiver = "Bonjour,\n" . "L'utilisateur " . $this->app['authentication']->getUser()->getDisplayName() . " (login : "******") " . "a fait un transfert FTP sur le serveur ayant comme adresse \"" . $host . "\" avec le login \"" . $login . "\"  " . "et pour repertoire de destination \"" . $destfolder . "\"\n";
     $text_mail_sender = "Bonjour,\n" . "Vous avez fait un export FTP  avec les caracteristiques " . "de connexion suivantes\n" . "- adresse du serveur : \"" . $host . "\"\n" . "- login utilisé \"" . $login . "\"\n" . "- repertoire de destination \"" . $destfolder . "\"\n" . "\n";
     $export = new FtpExport();
     $export->setNbretry((int) $retry * 1 > 0 ? (int) $retry : 5)->setMail($email_dest)->setLogfile($logfile)->setFoldertocreate($makedirectory)->setUser($this->app['authentication']->getUser())->setTextMailSender($text_mail_sender)->setTextMailReceiver($text_mail_receiver)->setSendermail($this->app['authentication']->getUser()->getEmail())->setDestfolder($destfolder)->setPassif($passif == '1')->setPwd($password)->setSsl($ssl == '1')->setLogin($login)->setAddr($host);
     $this->app['EM']->persist($export);
     foreach ($this->list['files'] as $file) {
         foreach ($file['subdefs'] as $subdef => $properties) {
             $filename = $file['export_name'] . $properties["ajout"] . '.' . $properties['exportExt'];
             $bfields = isset($properties['businessfields']) ? $properties['businessfields'] : null;
             $element = new FtpExportElement();
             $element->setBaseId($file['base_id'])->setBusinessfields($bfields)->setExport($export)->setFilename($filename)->setFolder($properties['folder'])->setRecordId($file['record_id'])->setSubdef($subdef);
             $export->addElement($element);
             $this->app['EM']->persist($element);
         }
     }
     $this->app['EM']->flush();
     return true;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     $sql = 'DELETE FROM FtpExports';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = 'DELETE FROM FtpExportElements';
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $conn = $app->getApplicationBox()->get_connection();
     $em = $app['orm.em'];
     $em->getEventManager()->removeEventSubscriber(new TimestampableListener());
     $sql = 'SELECT `id`, `crash`, `nbretry`, `mail`, `addr`, `ssl`,
                 `login`, `pwd`, `passif`,
                 `destfolder`, `sendermail`, `text_mail_sender`,
                 `text_mail_receiver`, `usr_id`, `date`, `foldertocreate`,
                 `logfile`
             FROM ftp_export';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $sql = 'SELECT base_id, record_id, subdef, filename, folder, error, done, businessfields
             FROM ftp_export_elements
             WHERE ftp_export_id = :export_id';
     $stmt = $conn->prepare($sql);
     $n = 0;
     foreach ($rs as $row) {
         if (null === ($user = $this->loadUser($app['orm.em'], $row['usr_id']))) {
             continue;
         }
         $export = new FtpExport();
         $export->setAddr($row['addr'])->setCrash($row['crash'])->setNbretry($row['nbretry'])->setMail($row['mail'])->setSsl($row['ssl'])->setLogin($row['login'])->setPwd($row['pwd'])->setPassif($row['passif'])->setDestfolder($row['destfolder'])->setSendermail($row['sendermail'])->setTextMailReceiver($row['text_mail_sender'])->setTextMailSender($row['text_mail_reveiver'])->setUser($user)->setCreated(new \DateTime($row['date']))->setUpdated(new \DateTime($row['date']))->setFoldertocreate($row['foldertocreate'])->setLogfile($row['logfile']);
         $em->persist($export);
         $stmt->execute(['export_id' => $row['id']]);
         $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($rs as $element) {
             $element = new FtpExportElement();
             $element->setBaseId($row['base_id'])->setRecordId($row['record_id'])->setBusinessfields($row['businessfields'])->setCreated(new \DateTime($row['date']))->setUpdated(new \DateTime($row['date']))->setDone(!!$row['done'])->setError(!!$row['error'])->setFilename($row['filename'])->setFolder($row['folder'])->setSubdef($row['subdef'])->setExport($export);
             $export->addElement($element);
             $em->persist($element);
         }
         $n++;
         if ($n % 200 === 0) {
             $em->flush();
             $em->clear();
         }
     }
     $stmt->closeCursor();
     $em->flush();
     $em->clear();
     $em->getEventManager()->addEventSubscriber(new TimestampableListener());
     return true;
 }
 public function testFindByUser()
 {
     $match1 = new FtpExport();
     $match1->setAddr('Match 1')->setUser(self::$DI['user']);
     $match2 = new FtpExport();
     $match2->setAddr('Match 2')->setUser(self::$DI['user']);
     $noMatch1 = new FtpExport();
     $noMatch1->setAddr('No match 1')->setUser(self::$DI['user_alt1']);
     self::$DI['app']['orm.em']->persist($match1);
     self::$DI['app']['orm.em']->persist($match2);
     self::$DI['app']['orm.em']->persist($noMatch1);
     self::$DI['app']['orm.em']->flush();
     $exports = self::$DI['app']['orm.em']->getRepository('Phraseanet:FtpExport')->findByUser(self::$DI['user']);
     $this->assertCount(2, $exports);
     $this->assertContains($match1, $exports);
     $this->assertContains($match2, $exports);
 }
 /**
  * {@inheritDoc}
  */
 public function getElements()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getElements', array());
     return parent::getElements();
 }
Beispiel #5
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()));
     }
 }