mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 14:33:14 +00:00
Switch to FtpExport entities
This commit is contained in:
@@ -18,7 +18,7 @@ namespace Alchemy\Phrasea\Core;
|
||||
*/
|
||||
class Version
|
||||
{
|
||||
protected static $number = '3.9.0.a5';
|
||||
protected static $number = '3.9.0.a6';
|
||||
protected static $name = 'Diplodocus';
|
||||
|
||||
public static function getNumber()
|
||||
|
@@ -50,7 +50,7 @@ class FtpExport
|
||||
private $addr;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @ORM\Column(type="boolean", name="use_ssl")
|
||||
*/
|
||||
private $ssl = false;
|
||||
|
||||
@@ -145,6 +145,7 @@ class FtpExport
|
||||
* Set crash
|
||||
*
|
||||
* @param integer $crash
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setCrash($crash)
|
||||
@@ -180,6 +181,7 @@ class FtpExport
|
||||
* Set nbretry
|
||||
*
|
||||
* @param integer $nbretry
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setNbretry($nbretry)
|
||||
@@ -203,6 +205,7 @@ class FtpExport
|
||||
* Set mail
|
||||
*
|
||||
* @param string $mail
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setMail($mail)
|
||||
@@ -226,6 +229,7 @@ class FtpExport
|
||||
* Set addr
|
||||
*
|
||||
* @param string $addr
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setAddr($addr)
|
||||
@@ -249,11 +253,12 @@ class FtpExport
|
||||
* Set ssl
|
||||
*
|
||||
* @param boolean $ssl
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setSsl($ssl)
|
||||
{
|
||||
$this->ssl = $ssl;
|
||||
$this->ssl = (Boolean) $ssl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -263,7 +268,7 @@ class FtpExport
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getSsl()
|
||||
public function isSsl()
|
||||
{
|
||||
return $this->ssl;
|
||||
}
|
||||
@@ -272,6 +277,7 @@ class FtpExport
|
||||
* Set login
|
||||
*
|
||||
* @param string $login
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setLogin($login)
|
||||
@@ -295,6 +301,7 @@ class FtpExport
|
||||
* Set pwd
|
||||
*
|
||||
* @param string $pwd
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setPwd($pwd)
|
||||
@@ -318,11 +325,12 @@ class FtpExport
|
||||
* Set passif
|
||||
*
|
||||
* @param boolean $passif
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setPassif($passif)
|
||||
{
|
||||
$this->passif = $passif;
|
||||
$this->passif = (Boolean) $passif;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -332,7 +340,7 @@ class FtpExport
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getPassif()
|
||||
public function isPassif()
|
||||
{
|
||||
return $this->passif;
|
||||
}
|
||||
@@ -341,6 +349,7 @@ class FtpExport
|
||||
* Set destfolder
|
||||
*
|
||||
* @param string $destfolder
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setDestfolder($destfolder)
|
||||
@@ -364,6 +373,7 @@ class FtpExport
|
||||
* Set sendermail
|
||||
*
|
||||
* @param string $sendermail
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setSendermail($sendermail)
|
||||
@@ -387,6 +397,7 @@ class FtpExport
|
||||
* Set textMailSender
|
||||
*
|
||||
* @param string $textMailSender
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setTextMailSender($textMailSender)
|
||||
@@ -410,6 +421,7 @@ class FtpExport
|
||||
* Set textMailReceiver
|
||||
*
|
||||
* @param string $textMailReceiver
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setTextMailReceiver($textMailReceiver)
|
||||
@@ -433,6 +445,7 @@ class FtpExport
|
||||
* Set usrId
|
||||
*
|
||||
* @param integer $usrId
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setUsrId($usrId)
|
||||
@@ -466,6 +479,7 @@ class FtpExport
|
||||
* Set user
|
||||
*
|
||||
* @param \User_Adapter $user
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setUser(\User_Adapter $user)
|
||||
@@ -479,6 +493,7 @@ class FtpExport
|
||||
* Set foldertocreate
|
||||
*
|
||||
* @param string $foldertocreate
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setFoldertocreate($foldertocreate)
|
||||
@@ -502,11 +517,12 @@ class FtpExport
|
||||
* Set logfile
|
||||
*
|
||||
* @param boolean $logfile
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setLogfile($logfile)
|
||||
{
|
||||
$this->logfile = $logfile;
|
||||
$this->logfile = (Boolean) $logfile;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -516,7 +532,7 @@ class FtpExport
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getLogfile()
|
||||
public function isLogfile()
|
||||
{
|
||||
return $this->logfile;
|
||||
}
|
||||
@@ -525,9 +541,10 @@ class FtpExport
|
||||
* Set created
|
||||
*
|
||||
* @param \DateTime $created
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setCreated($created)
|
||||
public function setCreated(\DateTime $created)
|
||||
{
|
||||
$this->created = $created;
|
||||
|
||||
@@ -548,9 +565,10 @@ class FtpExport
|
||||
* Set updated
|
||||
*
|
||||
* @param \DateTime $updated
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function setUpdated($updated)
|
||||
public function setUpdated(\DateTime $updated)
|
||||
{
|
||||
$this->updated = $updated;
|
||||
|
||||
@@ -570,10 +588,11 @@ class FtpExport
|
||||
/**
|
||||
* Add elements
|
||||
*
|
||||
* @param \Entities\FtpExportElement $elements
|
||||
* @param FtpExportElement $elements
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function addElement(\Entities\FtpExportElement $elements)
|
||||
public function addElement(FtpExportElement $elements)
|
||||
{
|
||||
$this->elements[] = $elements;
|
||||
|
||||
@@ -583,17 +602,21 @@ class FtpExport
|
||||
/**
|
||||
* Remove elements
|
||||
*
|
||||
* @param \Entities\FtpExportElement $elements
|
||||
* @param FtpExportElement $elements
|
||||
*
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function removeElement(\Entities\FtpExportElement $elements)
|
||||
public function removeElement(FtpExportElement $elements)
|
||||
{
|
||||
$this->elements->removeElement($elements);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
* @return FtpExportElement[]
|
||||
*/
|
||||
public function getElements()
|
||||
{
|
||||
|
@@ -109,6 +109,7 @@ class FtpExportElement
|
||||
* Set recordId
|
||||
*
|
||||
* @param integer $recordId
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setRecordId($recordId)
|
||||
@@ -132,6 +133,7 @@ class FtpExportElement
|
||||
* Set baseId
|
||||
*
|
||||
* @param integer $baseId
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setBaseId($baseId)
|
||||
@@ -155,6 +157,7 @@ class FtpExportElement
|
||||
* Set subdef
|
||||
*
|
||||
* @param string $subdef
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setSubdef($subdef)
|
||||
@@ -178,6 +181,7 @@ class FtpExportElement
|
||||
* Set filename
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setFilename($filename)
|
||||
@@ -201,6 +205,7 @@ class FtpExportElement
|
||||
* Set folder
|
||||
*
|
||||
* @param string $folder
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setFolder($folder)
|
||||
@@ -224,11 +229,12 @@ class FtpExportElement
|
||||
* Set error
|
||||
*
|
||||
* @param boolean $error
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setError($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
$this->error = (Boolean) $error;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -247,11 +253,12 @@ class FtpExportElement
|
||||
* Set done
|
||||
*
|
||||
* @param boolean $done
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setDone($done)
|
||||
{
|
||||
$this->done = $done;
|
||||
$this->done = (Boolean) $done;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -270,11 +277,12 @@ class FtpExportElement
|
||||
* Set businessfields
|
||||
*
|
||||
* @param boolean $businessfields
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setBusinessfields($businessfields)
|
||||
{
|
||||
$this->businessfields = $businessfields;
|
||||
$this->businessfields = (Boolean) $businessfields;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -284,7 +292,7 @@ class FtpExportElement
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getBusinessfields()
|
||||
public function isBusinessfields()
|
||||
{
|
||||
return $this->businessfields;
|
||||
}
|
||||
@@ -293,9 +301,10 @@ class FtpExportElement
|
||||
* Set created
|
||||
*
|
||||
* @param \DateTime $created
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setCreated($created)
|
||||
public function setCreated(\DateTime $created)
|
||||
{
|
||||
$this->created = $created;
|
||||
|
||||
@@ -316,9 +325,10 @@ class FtpExportElement
|
||||
* Set updated
|
||||
*
|
||||
* @param \DateTime $updated
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setUpdated($updated)
|
||||
public function setUpdated(\DateTime $updated)
|
||||
{
|
||||
$this->updated = $updated;
|
||||
|
||||
@@ -338,10 +348,11 @@ class FtpExportElement
|
||||
/**
|
||||
* Set export
|
||||
*
|
||||
* @param \Entities\FtpExport $export
|
||||
* @param FtpExport $export
|
||||
*
|
||||
* @return FtpExportElement
|
||||
*/
|
||||
public function setExport(\Entities\FtpExport $export = null)
|
||||
public function setExport(FtpExport $export = null)
|
||||
{
|
||||
$this->export = $export;
|
||||
|
||||
@@ -351,7 +362,7 @@ class FtpExportElement
|
||||
/**
|
||||
* Get export
|
||||
*
|
||||
* @return \Entities\FtpExport
|
||||
* @return FtpExport
|
||||
*/
|
||||
public function getExport()
|
||||
{
|
||||
|
@@ -111,10 +111,10 @@ class FtpExport extends \Entities\FtpExport implements \Doctrine\ORM\Proxy\Proxy
|
||||
return parent::setSsl($ssl);
|
||||
}
|
||||
|
||||
public function getSsl()
|
||||
public function isSsl()
|
||||
{
|
||||
$this->__load();
|
||||
return parent::getSsl();
|
||||
return parent::isSsl();
|
||||
}
|
||||
|
||||
public function setLogin($login)
|
||||
@@ -147,10 +147,10 @@ class FtpExport extends \Entities\FtpExport implements \Doctrine\ORM\Proxy\Proxy
|
||||
return parent::setPassif($passif);
|
||||
}
|
||||
|
||||
public function getPassif()
|
||||
public function isPassif()
|
||||
{
|
||||
$this->__load();
|
||||
return parent::getPassif();
|
||||
return parent::isPassif();
|
||||
}
|
||||
|
||||
public function setDestfolder($destfolder)
|
||||
@@ -243,10 +243,10 @@ class FtpExport extends \Entities\FtpExport implements \Doctrine\ORM\Proxy\Proxy
|
||||
return parent::setLogfile($logfile);
|
||||
}
|
||||
|
||||
public function getLogfile()
|
||||
public function isLogfile()
|
||||
{
|
||||
$this->__load();
|
||||
return parent::getLogfile();
|
||||
return parent::isLogfile();
|
||||
}
|
||||
|
||||
public function setCreated($created)
|
||||
|
@@ -141,10 +141,10 @@ class FtpExportElement extends \Entities\FtpExportElement implements \Doctrine\O
|
||||
return parent::setBusinessfields($businessfields);
|
||||
}
|
||||
|
||||
public function getBusinessfields()
|
||||
public function isBusinessfields()
|
||||
{
|
||||
$this->__load();
|
||||
return parent::getBusinessfields();
|
||||
return parent::isBusinessfields();
|
||||
}
|
||||
|
||||
public function setCreated($created)
|
||||
|
@@ -26,7 +26,7 @@ class FtpExportRepository extends EntityRepository
|
||||
$qb->where($qb->expr()->gte('e.crash', 'e.nbretry'));
|
||||
|
||||
if (null !== $before) {
|
||||
$qb->where($qb->expr()->lte('e.created', ':created'));
|
||||
$qb->andWhere($qb->expr()->lte('e.created', ':created'));
|
||||
$qb->setParameter(':created', $before);
|
||||
}
|
||||
|
||||
|
@@ -759,11 +759,15 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
public function delete()
|
||||
{
|
||||
$repo = $this->app['EM']->getRepository('Entities\UsrAuthProvider');
|
||||
|
||||
foreach ($repo->findByUser($this) as $provider) {
|
||||
$this->app['EM']->remove($provider);
|
||||
}
|
||||
|
||||
$repo = $this->app['EM']->getRepository('Entities\FtpExport');
|
||||
foreach ($repo->findByUser($this) as $export) {
|
||||
$this->app['EM']->remove($export);
|
||||
}
|
||||
|
||||
$this->app['EM']->flush();
|
||||
|
||||
$sql = 'UPDATE usr SET usr_login = :usr_login , usr_mail = null
|
||||
@@ -792,11 +796,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
$stmt->execute(array(':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = 'DELETE FROM ftp_export WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = 'DELETE FROM `order` WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':usr_id' => $this->get_id()));
|
||||
|
143
lib/classes/patch/3906.php
Normal file
143
lib/classes/patch/3906.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Entities\FtpExport;
|
||||
use Entities\FtpExportElement;
|
||||
use Gedmo\Timestampable\TimestampableListener;
|
||||
|
||||
class patch_3906 implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0.a6';
|
||||
|
||||
/** @var array */
|
||||
private $concern = array(base::APPLICATION_BOX);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $appbox, Application $app)
|
||||
{
|
||||
$conn = $app['phraseanet.appbox']->get_connection();
|
||||
|
||||
$em = $app['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) {
|
||||
try {
|
||||
$user = \User_Adapter::getInstance($row['usr_id'], $app);
|
||||
} catch (\Exception $e) {
|
||||
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(array('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());
|
||||
}
|
||||
}
|
@@ -9,15 +9,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Entities\FtpExport;
|
||||
use Entities\FtpExportElement;
|
||||
|
||||
class set_exportftp extends set_export
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param integer $usr_to
|
||||
@@ -59,95 +55,44 @@ class set_exportftp extends set_export
|
||||
. "- repertoire de destination \"" . $destfolder . "\"\n"
|
||||
. "\n";
|
||||
|
||||
$fn = "id";
|
||||
$fv = "null";
|
||||
$fn .= ",crash";
|
||||
$fv .= ",0";
|
||||
$fn .= ",nbretry";
|
||||
$fv .= ",:nbretry";
|
||||
$fn .= ",mail";
|
||||
$fv .= ",:mail";
|
||||
$fn .= ",addr";
|
||||
$fv .= ",:addr";
|
||||
$fn .= ",login";
|
||||
$fv .= ",:login";
|
||||
$fn .= ",`ssl`";
|
||||
$fv .= ",:ssl";
|
||||
$fn .= ",pwd";
|
||||
$fv .= ",:pwd";
|
||||
$fn .= ",passif";
|
||||
$fv .= ",:passif";
|
||||
$fn .= ",destfolder";
|
||||
$fv .= ",:destfolder";
|
||||
$fn .= ",sendermail";
|
||||
$fv .= ",:sendermail";
|
||||
$fn .= ",text_mail_receiver";
|
||||
$fv .= ",:text_mail_receiver";
|
||||
$fn .= ",text_mail_sender";
|
||||
$fv .= ",:text_mail_sender";
|
||||
$fn .= ",usr_id";
|
||||
$fv .= ",:usr_id";
|
||||
$fn .= ",date";
|
||||
$fv .= ", NOW()";
|
||||
$fn .= ",foldertocreate";
|
||||
$fv .= ",:foldertocreate";
|
||||
$fn .= ",logfile";
|
||||
$fv .= ",:logfile";
|
||||
$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()->get_email())
|
||||
->setDestfolder($destfolder)
|
||||
->setPassif($passif == '1')
|
||||
->setPwd($password)
|
||||
->setSsl($ssl == '1')
|
||||
->setLogin($login)
|
||||
->setAddr($host);
|
||||
|
||||
$params = array(
|
||||
':nbretry' => (((int) $retry * 1) > 0 ? (int) $retry : 5)
|
||||
, ':mail' => $email_dest
|
||||
, ':addr' => $host
|
||||
, ':login' => $login
|
||||
, ':ssl' => ($ssl == '1' ? '1' : '0')
|
||||
, ':pwd' => $password
|
||||
, ':passif' => ($passif == "1" ? "1" : "0")
|
||||
, ':destfolder' => $destfolder
|
||||
, ':sendermail' => $this->app['authentication']->getUser()->get_email()
|
||||
, ':text_mail_receiver' => $text_mail_receiver
|
||||
, ':text_mail_sender' => $text_mail_sender
|
||||
, ':usr_id' => $this->app['authentication']->getUser()->get_id()
|
||||
, ':foldertocreate' => $makedirectory
|
||||
, ':logfile' => ( ! ! $logfile ? '1' : '0')
|
||||
);
|
||||
|
||||
$sql = "INSERT INTO ftp_export ($fn) VALUES ($fv)";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ftp_export_id = $conn->lastInsertId();
|
||||
|
||||
$sql = 'INSERT INTO ftp_export_elements
|
||||
(id, ftp_export_id, base_id, record_id, subdef, filename, folder, businessfields)
|
||||
VALUES
|
||||
(null, :ftp_export_id, :base_id, :record_id, :subdef,
|
||||
:filename, :folder, :businessfields)';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$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'];
|
||||
|
||||
$filename = $file['export_name'] . $properties["ajout"] . '.' . $properties['exportExt'];
|
||||
$bfields = isset($properties['businessfields']) ? $properties['businessfields'] : null;
|
||||
|
||||
$params = array(
|
||||
':ftp_export_id' => $ftp_export_id
|
||||
, ':base_id' => $file['base_id']
|
||||
, ':record_id' => $file['record_id']
|
||||
, ':subdef' => $subdef
|
||||
, ':filename' => $filename
|
||||
, ':folder' => $properties['folder']
|
||||
, ':businessfields' => $bfields
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
$this->app['EM']->flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -12,6 +12,8 @@ use Alchemy\Phrasea\Core\Configuration\Configuration;
|
||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||
use Alchemy\Phrasea\Notification\Mail\MailSuccessFTPSender;
|
||||
use Alchemy\Phrasea\Notification\Receiver;
|
||||
use Entities\FtpExport;
|
||||
use Entities\FtpExportElement;
|
||||
|
||||
class task_period_ftp extends task_appboxAbstract
|
||||
{
|
||||
@@ -258,88 +260,39 @@ class task_period_ftp extends task_appboxAbstract
|
||||
|
||||
protected function retrieveContent(appbox $appbox)
|
||||
{
|
||||
$conn = $appbox->get_connection();
|
||||
|
||||
$time2sleep = null;
|
||||
$ftp_exports = array();
|
||||
|
||||
$period = $this->period;
|
||||
$time2sleep = (int) ($period);
|
||||
|
||||
$sql = "SELECT id FROM ftp_export WHERE crash>=nbretry
|
||||
AND date < :date";
|
||||
|
||||
$params = array(':date' => $this->dependencyContainer['date-formatter']->format_mysql(new DateTime('-30 days')));
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $rowtask) {
|
||||
$sql = "DELETE FROM ftp_export WHERE id = :export_id";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $rowtask['id']));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = "DELETE FROM ftp_export_elements WHERE ftp_export_id = :export_id";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $rowtask['id']));
|
||||
$stmt->closeCursor();
|
||||
foreach ($this->dependencyContainer['EM']
|
||||
->getRepository('Entities\FtpExport')
|
||||
->findCrashedExports(new \DateTime('-1 month')) as $export) {
|
||||
$this->dependencyContainer['EM']->remove($export);
|
||||
}
|
||||
$this->dependencyContainer['EM']->flush();
|
||||
|
||||
$sql = "SELECT * FROM ftp_export WHERE crash<nbretry ORDER BY id";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$ftp_exports[$row["id"]] = array_merge(array('files' => array()), $row);
|
||||
}
|
||||
|
||||
$sql = "SELECT e.* from ftp_export f
|
||||
INNER JOIN ftp_export_elements e
|
||||
ON (f.id=e.ftp_export_id AND f.crash<f.nbretry
|
||||
AND (e.done = 0 or error=1))
|
||||
ORDER BY f.id";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $rowtask) {
|
||||
if (isset($ftp_exports[$rowtask["ftp_export_id"]])) {
|
||||
$ftp_exports[$rowtask["ftp_export_id"]]["files"][] = $rowtask;
|
||||
}
|
||||
}
|
||||
|
||||
return $ftp_exports;
|
||||
return $this->dependencyContainer['EM']
|
||||
->getRepository('Entities\FtpExport')
|
||||
->findDoableExports();
|
||||
}
|
||||
|
||||
protected function processOneContent(appbox $appbox, $ftp_export)
|
||||
protected function processOneContent(appbox $appbox, $export)
|
||||
{
|
||||
$conn = $appbox->get_connection();
|
||||
|
||||
$id = $ftp_export['id'];
|
||||
$ftp_export[$id]["crash"] = $ftp_export["crash"];
|
||||
$ftp_export[$id]["nbretry"] = $ftp_export["nbretry"] < 1 ? 3 : (int) $ftp_export["nbretry"];
|
||||
$id = $export->getId();
|
||||
|
||||
$state = "";
|
||||
$ftp_server = $ftp_export["addr"];
|
||||
$ftp_user_name = $ftp_export["login"];
|
||||
$ftp_user_pass = $ftp_export["pwd"];
|
||||
$usr_id = (int) $ftp_export["usr_id"];
|
||||
$ftp_server = $export->getAddr();
|
||||
$ftp_user_name = $export->getLogin();
|
||||
$ftp_user_pass = $export->getPwd();
|
||||
$usr_id = $export->getUsrId();
|
||||
|
||||
$ftpLog = $ftp_user_name . "@" . p4string::addEndSlash($ftp_server) . $ftp_export["destfolder"];
|
||||
$ftpLog = $ftp_user_name . "@" . p4string::addEndSlash($ftp_server) . $export->getDestfolder();
|
||||
|
||||
if ($ftp_export["crash"] == 0) {
|
||||
if ($export->getCrash() == 0) {
|
||||
$line = sprintf(
|
||||
_('task::ftp:Etat d\'envoi FTP vers le serveur' .
|
||||
' "%1$s" avec le compte "%2$s" et pour destination le dossier : "%3$s"') . PHP_EOL
|
||||
, $ftp_server
|
||||
, $ftp_user_name
|
||||
, $ftp_export["destfolder"]
|
||||
, $export->getDestfolder()
|
||||
);
|
||||
$state .= $line;
|
||||
$this->logger->addDebug($line);
|
||||
@@ -347,18 +300,18 @@ class task_period_ftp extends task_appboxAbstract
|
||||
|
||||
$state .= $line = sprintf(
|
||||
_("task::ftp:TENTATIVE no %s, %s")
|
||||
, $ftp_export["crash"] + 1
|
||||
, $export->getCrash() + 1
|
||||
, " (" . date('r') . ")"
|
||||
) . PHP_EOL;
|
||||
|
||||
$this->logger->addDebug($line);
|
||||
|
||||
try {
|
||||
$ssl = ($ftp_export['ssl'] == '1');
|
||||
$ssl = $export->isSsl();
|
||||
$ftp_client = $this->dependencyContainer['phraseanet.ftp.client']($ftp_server, 21, 300, $ssl, $this->proxy, $this->proxyport);
|
||||
$ftp_client->login($ftp_user_name, $ftp_user_pass);
|
||||
|
||||
if ($ftp_export["passif"] == "1") {
|
||||
if ($export->isPassif()) {
|
||||
try {
|
||||
$ftp_client->passive(true);
|
||||
} catch (Exception $e) {
|
||||
@@ -366,26 +319,26 @@ class task_period_ftp extends task_appboxAbstract
|
||||
}
|
||||
}
|
||||
|
||||
if (trim($ftp_export["destfolder"]) != '') {
|
||||
if (trim($export->getDestfolder()) != '') {
|
||||
try {
|
||||
$ftp_client->chdir($ftp_export["destfolder"]);
|
||||
$ftp_export["destfolder"] = '/' . $ftp_export["destfolder"];
|
||||
$ftp_client->chdir($export->getDestFolder());
|
||||
$export->setDestfolder('/' . $export->getDestfolder());
|
||||
} catch (Exception $e) {
|
||||
$this->logger->addDebug($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
$ftp_export["destfolder"] = '/';
|
||||
$export->setDestfolder('/');
|
||||
}
|
||||
|
||||
if (trim($ftp_export["foldertocreate"]) != '') {
|
||||
if (trim($export->getFoldertocreate()) != '') {
|
||||
try {
|
||||
$ftp_client->mkdir($ftp_export["foldertocreate"]);
|
||||
$ftp_client->mkdir($export->getFoldertocreate());
|
||||
} catch (Exception $e) {
|
||||
$this->logger->addDebug($e->getMessage());
|
||||
}
|
||||
try {
|
||||
$new_dir = $ftp_client->add_end_slash($ftp_export["destfolder"])
|
||||
. $ftp_export["foldertocreate"];
|
||||
$new_dir = $ftp_client->add_end_slash($export->getDestfolder())
|
||||
. $export->getFoldertocreate();
|
||||
$ftp_client->chdir($new_dir);
|
||||
} catch (Exception $e) {
|
||||
$this->logger->addDebug($e->getMessage());
|
||||
@@ -395,38 +348,43 @@ class task_period_ftp extends task_appboxAbstract
|
||||
$obj = array();
|
||||
|
||||
$basefolder = '';
|
||||
if (!in_array(trim($ftp_export["destfolder"]), array('.', './', ''))) {
|
||||
$basefolder = p4string::addEndSlash($ftp_export["destfolder"]);
|
||||
if (!in_array(trim($export->getDestfolder()), array('.', './', ''))) {
|
||||
$basefolder = p4string::addEndSlash($export->getDestfolder());
|
||||
}
|
||||
|
||||
$basefolder .= $ftp_export["foldertocreate"];
|
||||
$basefolder .= $export->getFoldertocreate();
|
||||
|
||||
if (in_array(trim($basefolder), array('.', './', ''))) {
|
||||
$basefolder = '/';
|
||||
}
|
||||
|
||||
foreach ($ftp_export['files'] as $fileid => $file) {
|
||||
$base_id = $file["base_id"];
|
||||
$record_id = $file["record_id"];
|
||||
$subdef = $file['subdef'];
|
||||
foreach ($export->getElements() as $exportElement) {
|
||||
if ($exportElement->isDone()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$base_id = $exportElement->getBaseId();
|
||||
$record_id = $exportElement->getRecordId();
|
||||
$subdef = $exportElement->getSubdef();
|
||||
$localfile = null;
|
||||
|
||||
try {
|
||||
$sbas_id = phrasea::sbasFromBas($this->dependencyContainer, $base_id);
|
||||
$record = new record_adapter($this->dependencyContainer, $sbas_id, $record_id);
|
||||
|
||||
$sdcaption = $record->get_caption()->serialize(caption_record::SERIALIZE_XML, $ftp_export["businessfields"]);
|
||||
$sdcaption = $record->get_caption()->serialize(caption_record::SERIALIZE_XML, $exportElement->isBusinessfields());
|
||||
|
||||
$remotefile = $file["filename"];
|
||||
$remotefile = $exportElement->getFilename();
|
||||
|
||||
if ($subdef == 'caption') {
|
||||
$desc = $record->get_caption()->serialize(\caption_record::SERIALIZE_XML, $ftp_export["businessfields"]);
|
||||
$desc = $record->get_caption()->serialize(\caption_record::SERIALIZE_XML, $exportElement->isBusinessfields());
|
||||
|
||||
$localfile = $this->dependencyContainer['root.path'] . '/tmp/' . md5($desc . time() . mt_rand());
|
||||
if (file_put_contents($localfile, $desc) === false) {
|
||||
throw new Exception('Impossible de creer un fichier temporaire');
|
||||
}
|
||||
} elseif ($subdef == 'caption-yaml') {
|
||||
$desc = $record->get_caption()->serialize(\caption_record::SERIALIZE_YAML, $ftp_export["businessfields"]);
|
||||
$desc = $record->get_caption()->serialize(\caption_record::SERIALIZE_YAML, $exportElement->isBusinessfields());
|
||||
|
||||
$localfile = $this->dependencyContainer['root.path'] . '/tmp/' . md5($desc . time() . mt_rand());
|
||||
if (file_put_contents($localfile, $desc) === false) {
|
||||
@@ -445,7 +403,7 @@ class task_period_ftp extends task_appboxAbstract
|
||||
}
|
||||
}
|
||||
|
||||
$current_folder = p4string::delEndSlash(str_replace('//', '/', $basefolder . $file['folder']));
|
||||
$current_folder = p4string::delEndSlash(str_replace('//', '/', $basefolder . $exportElement->getFolder()));
|
||||
|
||||
if ($ftp_client->pwd() != $current_folder) {
|
||||
try {
|
||||
@@ -466,11 +424,11 @@ class task_period_ftp extends task_appboxAbstract
|
||||
unlink($localfile);
|
||||
}
|
||||
|
||||
$sql = "UPDATE ftp_export_elements"
|
||||
. " SET done='1', error='0' WHERE id = :file_id";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':file_id' => $file['id']));
|
||||
$stmt->closeCursor();
|
||||
$exportElement
|
||||
->setDone(true)
|
||||
->setError(false);
|
||||
$this->dependencyContainer['EM']->persist($exportElement);
|
||||
$this->dependencyContainer['EM']->flush();
|
||||
$this->logexport($record, $obj, $ftpLog);
|
||||
} catch (Exception $e) {
|
||||
$state .= $line = sprintf(_('task::ftp:File "%1$s" (record %2$s) de la base "%3$s"' .
|
||||
@@ -480,39 +438,28 @@ class task_period_ftp extends task_appboxAbstract
|
||||
|
||||
$this->logger->addDebug($line);
|
||||
|
||||
$done = $file['error'];
|
||||
|
||||
$sql = "UPDATE ftp_export_elements"
|
||||
. " SET done = :done, error='1' WHERE id = :file_id";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':done' => $done, ':file_id' => $file['id']));
|
||||
$stmt->closeCursor();
|
||||
// One failure max
|
||||
$exportElement
|
||||
->setDone($exportElement->isError())
|
||||
->setError(true);
|
||||
$this->dependencyContainer['EM']->persist($exportElement);
|
||||
$this->dependencyContainer['EM']->flush();
|
||||
}
|
||||
}
|
||||
|
||||
if ($ftp_export['logfile']) {
|
||||
if ($export->isLogfile()) {
|
||||
$this->logger->addDebug("logfile ");
|
||||
|
||||
$date = new DateTime();
|
||||
$remote_file = $date->format('U');
|
||||
|
||||
$sql = 'SELECT filename, folder'
|
||||
. ' FROM ftp_export_elements'
|
||||
. ' WHERE ftp_export_id = :ftp_export_id'
|
||||
. ' AND error = "0" AND done="1"';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':ftp_export_id' => $id));
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$buffer = '#transfert finished ' . $date->format(DATE_ATOM) . "\n\n";
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$filename = $row['filename'];
|
||||
$folder = $row['folder'];
|
||||
|
||||
$root = $ftp_export['foldertocreate'];
|
||||
foreach ($export->getElements() as $exportElement) {
|
||||
if (!$exportElement->isDone() || $exportElement->isError()) {
|
||||
continue;
|
||||
}
|
||||
$filename = $exportElement->getFilename();
|
||||
$folder = $exportElement->getFilename();
|
||||
$root = $export->getFoldertocreate();
|
||||
|
||||
$buffer .= $root . '/' . $folder . $filename . "\n";
|
||||
}
|
||||
@@ -522,11 +469,8 @@ class task_period_ftp extends task_appboxAbstract
|
||||
file_put_contents($tmpfile, $buffer);
|
||||
|
||||
$remotefile = $date->format('U') . '-transfert.log';
|
||||
|
||||
$ftp_client->chdir($ftp_export["destfolder"]);
|
||||
|
||||
$ftp_client->chdir($export->getDestFolder());
|
||||
$ftp_client->put($remotefile, $tmpfile);
|
||||
|
||||
unlink($tmpfile);
|
||||
}
|
||||
|
||||
@@ -537,15 +481,14 @@ class task_period_ftp extends task_appboxAbstract
|
||||
|
||||
$this->logger->addDebug($line);
|
||||
|
||||
$sql = "UPDATE ftp_export SET crash=crash+1,date=now()"
|
||||
. " WHERE id = :export_id";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $ftp_export['id']));
|
||||
$stmt->closeCursor();
|
||||
$export->incrementCrash();
|
||||
$this->dependencyContainer['EM']->persist($export);
|
||||
$this->dependencyContainer['EM']->flush();
|
||||
|
||||
unset($ftp_client);
|
||||
}
|
||||
$this->finalize($appbox, $id);
|
||||
|
||||
$this->finalize($appbox, $export);
|
||||
}
|
||||
|
||||
protected function postProcessOneContent(appbox $appbox, $row)
|
||||
@@ -553,112 +496,78 @@ class task_period_ftp extends task_appboxAbstract
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function finalize(appbox $appbox, $id)
|
||||
public function finalize(appbox $appbox, FtpExport $export)
|
||||
{
|
||||
$conn = $appbox->get_connection();
|
||||
|
||||
$sql = 'SELECT crash, nbretry FROM ftp_export WHERE id = :export_id';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row && $row['crash'] >= $row['nbretry']) {
|
||||
$this->send_mails($appbox, $id);
|
||||
if ($export->getCrash() >= $export->getNbretry()) {
|
||||
$this->send_mails($appbox, $export);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$sql = 'SELECT count(id) as total, sum(error) as errors, sum(done) as done'
|
||||
. ' FROM ftp_export_elements WHERE ftp_export_id = :export_id';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$total = count($export->getElements());
|
||||
$done = count($export->getElements()->filter(function (FtpExportElement $element) {
|
||||
return $element->isDone();
|
||||
}));
|
||||
$error = count($export->getElements()->filter(function (FtpExportElement $element) {
|
||||
return $element->isError();
|
||||
}));
|
||||
|
||||
if ($row && $row['done'] == (int) $row['total']) {
|
||||
$this->send_mails($appbox, $id);
|
||||
if ($done === $total) {
|
||||
$this->send_mails($appbox, $export);
|
||||
|
||||
if ((int) $row['errors'] === 0) {
|
||||
$sql = 'DELETE FROM ftp_export WHERE id = :export_id';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $id));
|
||||
$stmt->closeCursor();
|
||||
$sql = 'DELETE FROM ftp_export_elements WHERE ftp_export_id = :export_id';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $id));
|
||||
$stmt->closeCursor();
|
||||
if ((int) $error === 0) {
|
||||
$this->dependencyContainer['EM']->remove($export);
|
||||
$this->dependencyContainer['EM']->flush();
|
||||
} else {
|
||||
$sql = 'UPDATE ftp_export SET crash = nbretry';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
$sql = 'DELETE FROM ftp_export_elements WHERE ftp_export_id = :export_id AND error="0"';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $id));
|
||||
$stmt->closeCursor();
|
||||
$export->setCrash($export->getNbretry());
|
||||
foreach ($export->getElements() as $element) {
|
||||
if (!$element->isError()) {
|
||||
$this->dependencyContainer['EM']->remove($export);
|
||||
}
|
||||
}
|
||||
$this->dependencyContainer['EM']->flush();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function send_mails(appbox $appbox, $id)
|
||||
public function send_mails(appbox $appbox, FtpExport $export)
|
||||
{
|
||||
$conn = $appbox->get_connection();
|
||||
|
||||
$sql = 'SELECT filename, base_id, record_id, subdef, error, done'
|
||||
. ' FROM ftp_export_elements WHERE ftp_export_id = :export_id';
|
||||
|
||||
$transferts = array();
|
||||
|
||||
$transfert_status = _('task::ftp:Tous les documents ont ete transferes avec succes');
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $id));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if ($row['error'] == '0' && $row['done'] == '1') {
|
||||
foreach ($export->getElements() as $element) {
|
||||
if (!$element->isError() && $element->isDone()) {
|
||||
$transferts[] =
|
||||
'<li>' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s')
|
||||
, $row["record_id"], $row["filename"]
|
||||
, phrasea::sbas_labels(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer)
|
||||
, phrasea::bas_labels($row['base_id'], $this->dependencyContainer), $row['subdef']) . ' : ' . _('Transfert OK') . '</li>';
|
||||
, $element->getRecordId(), $element->getFilename()
|
||||
, phrasea::sbas_labels(phrasea::sbasFromBas($this->dependencyContainer, $element->getBaseId()), $this->dependencyContainer)
|
||||
, phrasea::bas_labels($element->getBaseId(), $this->dependencyContainer), $element->getSubdef()) . ' : ' . _('Transfert OK') . '</li>';
|
||||
} else {
|
||||
$transferts[] =
|
||||
'<li>' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s')
|
||||
, $row["record_id"], $row["filename"]
|
||||
, phrasea::sbas_labels(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer), phrasea::bas_labels($row['base_id'], $this->dependencyContainer)
|
||||
, $row['subdef']) . ' : ' . _('Transfert Annule') . '</li>';
|
||||
, $element->getRecordId(), $element->getFilename()
|
||||
, phrasea::sbas_labels(phrasea::sbasFromBas($this->dependencyContainer, $element->getBaseId()), $this->dependencyContainer), phrasea::bas_labels($element->getBaseId(), $this->dependencyContainer)
|
||||
, $element->getSubdef()) . ' : ' . _('Transfert Annule') . '</li>';
|
||||
$transfert_status = _('task::ftp:Certains documents n\'ont pas pu etre tranferes');
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'SELECT addr, crash, nbretry, sendermail, mail, text_mail_sender, text_mail_receiver'
|
||||
. ' FROM ftp_export WHERE id = :export_id';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':export_id' => $id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row) {
|
||||
if ($row['crash'] >= $row['nbretry']) {
|
||||
$connection_status = _('Des difficultes ont ete rencontres a la connection au serveur distant');
|
||||
} else {
|
||||
$connection_status = _('La connection vers le serveur distant est OK');
|
||||
}
|
||||
|
||||
$text_mail_sender = $row['text_mail_sender'];
|
||||
$text_mail_receiver = $row['text_mail_receiver'];
|
||||
$mail = $row['mail'];
|
||||
$sendermail = $row['sendermail'];
|
||||
$ftp_server = $row['addr'];
|
||||
if ($export->getCrash() >= $export->getNbretry()) {
|
||||
$connection_status = _('Des difficultes ont ete rencontres a la connection au serveur distant');
|
||||
} else {
|
||||
$connection_status = _('La connection vers le serveur distant est OK');
|
||||
}
|
||||
|
||||
$text_mail_sender = $export->getTextMailSender();
|
||||
$text_mail_receiver = $export->getTextMailReceiver();
|
||||
$mail = $export->getMail();
|
||||
$sendermail = $export->getSendermail();
|
||||
$ftp_server = $export->getAddr();
|
||||
|
||||
$message = "\n\n----------------------------------------\n\n";
|
||||
$message = $connection_status . "\n";
|
||||
$message .= $transfert_status . "\n";
|
||||
@@ -669,11 +578,10 @@ class task_period_ftp extends task_appboxAbstract
|
||||
$sender_message = $text_mail_sender . $message;
|
||||
$receiver_message = $text_mail_receiver . $message;
|
||||
|
||||
$receiver = null;
|
||||
try {
|
||||
$receiver = new Receiver(null, $sendermail);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
|
||||
$receiver = null;
|
||||
}
|
||||
|
||||
if ($receiver) {
|
||||
@@ -682,24 +590,20 @@ class task_period_ftp extends task_appboxAbstract
|
||||
$this->dependencyContainer['notification.deliverer']->deliver($mail);
|
||||
}
|
||||
|
||||
$receiver = null;
|
||||
try {
|
||||
$receiver = new Receiver(null, $mail);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
|
||||
}
|
||||
|
||||
if ($receiver) {
|
||||
$mail = MailSuccessFTP::create($this->dependencyContainer, $receiver, null, $receiver_message);
|
||||
$mail = MailSuccessFTPSender::create($this->dependencyContainer, $receiver, null, $receiver_message);
|
||||
$mail->setServer($ftp_server);
|
||||
$this->dependencyContainer['notification.deliverer']->deliver($mail);
|
||||
} catch (\Exception $e) {
|
||||
$this->log('Unable to deliver success message');
|
||||
}
|
||||
}
|
||||
|
||||
public function logexport(record_adapter $record, $obj, $ftpLog)
|
||||
{
|
||||
foreach ($obj as $oneObj) {
|
||||
$this->app['phraseanet.logger']($record->get_databox())
|
||||
$this->dependencyContainer['phraseanet.logger']($record->get_databox())
|
||||
->log($record, Session_Logger::EVENT_EXPORTFTP, $ftpLog, '');
|
||||
}
|
||||
|
||||
|
@@ -86,14 +86,16 @@ class FtpExportRepositoryTest extends \PhraseanetPHPUnitAbstract
|
||||
->setAddr('Good 2')
|
||||
->setUser(self::$DI['user'])
|
||||
->setCrash(2)
|
||||
->setNbretry(3);
|
||||
->setNbretry(3)
|
||||
->setCreated(new \DateTime('-9 days'));
|
||||
|
||||
$good3 = new FtpExport();
|
||||
$good3
|
||||
->setAddr('Good 3')
|
||||
->setUser(self::$DI['user'])
|
||||
->setCrash(12)
|
||||
->setNbretry(23);
|
||||
->setNbretry(23)
|
||||
->setCreated(new \DateTime('-6 days'));
|
||||
|
||||
self::$DI['app']['EM']->persist($failure1);
|
||||
self::$DI['app']['EM']->persist($failure2);
|
||||
@@ -181,10 +183,6 @@ class FtpExportRepositoryTest extends \PhraseanetPHPUnitAbstract
|
||||
self::$DI['app']['EM']->persist($notDoable2);
|
||||
self::$DI['app']['EM']->persist($doable1);
|
||||
self::$DI['app']['EM']->persist($doable2);
|
||||
self::$DI['app']['EM']->persist($elem1);
|
||||
self::$DI['app']['EM']->persist($elem2);
|
||||
self::$DI['app']['EM']->persist($elem3);
|
||||
self::$DI['app']['EM']->persist($elem4);
|
||||
|
||||
self::$DI['app']['EM']->flush();
|
||||
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user