コード例 #1
0
ファイル: exportftp.php プロジェクト: nlegoff/Phraseanet
 /**
  *
  * @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;
 }
コード例 #2
0
ファイル: 390alpha6a.php プロジェクト: luisbrito/Phraseanet
 /**
  * {@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;
 }
 /**
  * {@inheritDoc}
  */
 public function setBaseId($baseId)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setBaseId', array($baseId));
     return parent::setBaseId($baseId);
 }