mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 14:03:27 +00:00
Add FtpCredentials entity
This commit is contained in:
@@ -13,6 +13,7 @@ use Alchemy\Phrasea\Application;
|
||||
|
||||
use Alchemy\Phrasea\Exception\SessionNotFound;
|
||||
use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface;
|
||||
use Entities\FtpCredential;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -246,58 +247,15 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
* @var FtpCredential
|
||||
*/
|
||||
protected $defaultftpdatas;
|
||||
|
||||
protected $ftpCredential;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mail_notifications;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $activeftp;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ftp_address;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ftp_login;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ftp_password;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ftp_passif;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ftp_dir;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ftp_dir_prefix;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
@@ -559,22 +517,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
return $usr_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $datas
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function set_defaultftpdatas($datas)
|
||||
{
|
||||
$sql = 'UPDATE usr SET defaultftpdatasent = :defaultftpdatas WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':defaultftpdatas' => $datas, ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->defaultftpdatas = $datas;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bollean $boolean
|
||||
@@ -593,23 +535,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $boolean
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function set_activeftp($boolean)
|
||||
{
|
||||
$value = $boolean ? '1' : '0';
|
||||
$sql = 'UPDATE usr SET activeftp = :activeftp WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':activeftp' => $value, ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->activeftp = $boolean;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $boolean
|
||||
@@ -627,91 +552,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $address
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function set_ftp_address($address)
|
||||
{
|
||||
$sql = 'UPDATE usr SET addrftp = :addrftp WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':addrftp' => $address, ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->ftp_address = $address;
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $login
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function set_ftp_login($login)
|
||||
{
|
||||
$sql = 'UPDATE usr SET loginftp = :loginftp WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':loginftp' => $login, ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->ftp_login = $login;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $password
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function set_ftp_password($password)
|
||||
{
|
||||
$sql = 'UPDATE usr SET pwdFTP = :passwordftp WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':passwordftp' => $password, ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->ftp_password = $password;
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_ftp_passif($boolean)
|
||||
{
|
||||
$value = $boolean ? '1' : '0';
|
||||
$sql = 'UPDATE usr SET passifftp = :passifftp WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':passifftp' => $value, ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->ftp_passif = !!$boolean;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_ftp_dir($ftp_dir)
|
||||
{
|
||||
$sql = 'UPDATE usr SET destftp = :destftp WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':destftp' => $ftp_dir, ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->ftp_dir = $ftp_dir;
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_ftp_dir_prefix($ftp_dir_prefix)
|
||||
{
|
||||
$sql = 'UPDATE usr SET prefixFTPfolder = :prefixftp WHERE usr_id = :usr_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':prefixftp' => $ftp_dir_prefix, ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->ftp_dir_prefix = $ftp_dir_prefix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_firstname($firstname)
|
||||
{
|
||||
$sql = 'UPDATE usr SET usr_prenom = :usr_prenom WHERE usr_id = :usr_id';
|
||||
@@ -891,18 +731,12 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
$stmt->execute(array(':owner_id' => $owner->get_id(), ':usr_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->set_ftp_address('')
|
||||
->set_activeftp(false)
|
||||
$this
|
||||
->set_city('')
|
||||
->set_company('')
|
||||
->set_email(null)
|
||||
->set_fax('')
|
||||
->set_firstname('')
|
||||
->set_ftp_dir('')
|
||||
->set_ftp_dir_prefix('')
|
||||
->set_ftp_login('')
|
||||
->set_ftp_passif('')
|
||||
->set_ftp_password('')
|
||||
->set_gender('')
|
||||
->set_geonameid('')
|
||||
->set_job('')
|
||||
@@ -913,11 +747,28 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
->set_zip('')
|
||||
->set_tel('');
|
||||
|
||||
$this->ftpCredential = new FtpCredential();
|
||||
$this->ftpCredential->setUsrId($this->get_id());
|
||||
$this->app['EM']->persist($this->ftpCredential);
|
||||
$this->app['EM']->flush();
|
||||
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFtpCredential()
|
||||
{
|
||||
if (null === $this->ftpCredential) {
|
||||
/* @var $ftpCredential \Entities\FtpCredential */
|
||||
$this->ftpCredential = $this->app['EM']->getRepository('Entities\FtpCredential')->findOneBy(array(
|
||||
'usrId' => $this->get_id()
|
||||
));
|
||||
}
|
||||
|
||||
return $this->ftpCredential;
|
||||
}
|
||||
|
||||
public function is_template()
|
||||
{
|
||||
return $this->is_template;
|
||||
@@ -1023,52 +874,11 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function get_defaultftpdatas()
|
||||
{
|
||||
return $this->defaultftpdatas;
|
||||
}
|
||||
|
||||
public function get_mail_notifications()
|
||||
{
|
||||
return $this->mail_notifications;
|
||||
}
|
||||
|
||||
public function get_activeftp()
|
||||
{
|
||||
return $this->activeftp;
|
||||
}
|
||||
|
||||
public function get_ftp_address()
|
||||
{
|
||||
return $this->ftp_address;
|
||||
}
|
||||
|
||||
public function get_ftp_login()
|
||||
{
|
||||
return $this->ftp_login;
|
||||
}
|
||||
|
||||
public function get_ftp_password()
|
||||
{
|
||||
return $this->ftp_password;
|
||||
}
|
||||
|
||||
public function get_ftp_passif()
|
||||
{
|
||||
return $this->ftp_passif;
|
||||
}
|
||||
|
||||
public function get_ftp_dir()
|
||||
{
|
||||
return $this->ftp_dir;
|
||||
}
|
||||
|
||||
public function get_ftp_dir_prefix()
|
||||
{
|
||||
return $this->ftp_dir_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $id
|
||||
@@ -1079,8 +889,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
$sql = 'SELECT usr_id, ldap_created, create_db, usr_login, usr_password, usr_nom, activite,
|
||||
usr_prenom, usr_sexe as gender, usr_mail, adresse, usr_creationdate, usr_modificationdate,
|
||||
ville, cpostal, tel, fax, fonction, societe, geonameid, lastModel, invite,
|
||||
defaultftpdatasent, mail_notifications, activeftp, addrftp, loginftp,
|
||||
pwdFTP, passifftp, destftp, prefixFTPfolder, mail_locked, model_of, locale
|
||||
mail_notifications, mail_locked, model_of, locale
|
||||
FROM usr WHERE usr_id= :id ';
|
||||
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
@@ -1100,15 +909,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
|
||||
$this->ldap_created = $row['ldap_created'];
|
||||
|
||||
$this->defaultftpdatas = $row['defaultftpdatasent'];
|
||||
$this->mail_notifications = $row['mail_notifications'];
|
||||
$this->activeftp = $row['activeftp'];
|
||||
$this->ftp_address = $row['addrftp'];
|
||||
$this->ftp_login = $row['loginftp'];
|
||||
$this->ftp_password = $row['pwdFTP'];
|
||||
$this->ftp_passif = $row['passifftp'];
|
||||
$this->ftp_dir = $row['destftp'];
|
||||
$this->ftp_dir_prefix = $row['prefixFTPfolder'];
|
||||
|
||||
$this->mail_locked = !!$row['mail_locked'];
|
||||
|
||||
@@ -1725,6 +1526,11 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
|
||||
$usr_id = $conn->lastInsertId();
|
||||
|
||||
$ftpCredential = new FtpCredential();
|
||||
$ftpCredential->setUsrId($usr_id);
|
||||
$app['EM']->persist($ftpCredential);
|
||||
$app['EM']->flush();
|
||||
|
||||
if ($invite) {
|
||||
$sql = 'UPDATE usr SET usr_login = "invite' . $usr_id . '" WHERE usr_id="' . $usr_id . '"';
|
||||
$stmt = $conn->prepare($sql);
|
||||
|
@@ -34,24 +34,8 @@ interface User_Interface
|
||||
|
||||
public function get_country();
|
||||
|
||||
public function set_defaultftpdatas($datas);
|
||||
|
||||
public function set_mail_notifications($boolean);
|
||||
|
||||
public function set_activeftp($boolean);
|
||||
|
||||
public function set_ftp_address($address);
|
||||
|
||||
public function set_ftp_login($login);
|
||||
|
||||
public function set_ftp_password($password);
|
||||
|
||||
public function set_ftp_passif($boolean);
|
||||
|
||||
public function set_ftp_dir($ftp_dir);
|
||||
|
||||
public function set_ftp_dir_prefix($ftp_dir_prefix);
|
||||
|
||||
public function set_firstname($firstname);
|
||||
|
||||
public function set_lastname($lastname);
|
||||
@@ -78,24 +62,8 @@ interface User_Interface
|
||||
|
||||
public function delete();
|
||||
|
||||
public function get_defaultftpdatas();
|
||||
|
||||
public function get_mail_notifications();
|
||||
|
||||
public function get_activeftp();
|
||||
|
||||
public function get_ftp_address();
|
||||
|
||||
public function get_ftp_login();
|
||||
|
||||
public function get_ftp_password();
|
||||
|
||||
public function get_ftp_passif();
|
||||
|
||||
public function get_ftp_dir();
|
||||
|
||||
public function get_ftp_dir_prefix();
|
||||
|
||||
public function load($id);
|
||||
|
||||
public function set_last_template(User_Interface $template);
|
||||
|
89
lib/classes/patch/390.php
Normal file
89
lib/classes/patch/390.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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\FtpCredential;
|
||||
|
||||
class patch_390 implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0.a1';
|
||||
|
||||
/** @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();
|
||||
$sql = 'SELECT usr_id, activeFTP, addrFTP, loginFTP,
|
||||
retryFTP, passifFTP, pwdFTP, destFTP, prefixFTPfolder
|
||||
FROM usr';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$n = 0;
|
||||
$em = $app['EM'];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$credential = new FtpCredential();
|
||||
$credential->setActive($row['activeFTP']);
|
||||
$credential->setAddress($row['addrFTP']);
|
||||
$credential->setLogin($row['loginFTP']);
|
||||
$credential->setMaxRetry((Integer) $row['retryFTP']);
|
||||
$credential->setPassive($row['passifFTP']);
|
||||
$credential->setPassword($row['pwdFTP']);
|
||||
$credential->setReceptionFolder($row['destFTP']);
|
||||
$credential->setRepositoryPrefixName($row['prefixFTPfolder']);
|
||||
$credential->setUsrId($row['usr_id']);
|
||||
|
||||
$em->persist($credential);
|
||||
|
||||
$n++;
|
||||
|
||||
if ($n % 100 === 0) {
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
}
|
@@ -235,12 +235,12 @@ class set_export extends set_abstract
|
||||
$lst_base_id = array_keys($app['authentication']->getUser()->ACL()->get_granted_base());
|
||||
|
||||
if ($hasadminright) {
|
||||
$sql = "SELECT usr.usr_id,usr_login,usr.addrFTP,usr.loginFTP,usr.sslFTP,
|
||||
usr.pwdFTP,usr.destFTP,prefixFTPfolder,usr.passifFTP,
|
||||
usr.retryFTP,usr.usr_mail
|
||||
FROM (usr INNER JOIN basusr
|
||||
ON ( activeFTP=1
|
||||
AND usr.usr_id=basusr.usr_id
|
||||
$sql = "SELECT usr.usr_id,usr_login,usr.usr_mail, FtpCredential.*
|
||||
FROM (
|
||||
FtpCredential INNER JOIN usr ON (
|
||||
FtpCredential.active = 1 AND FtpCredential.usrId = usr.usr_id
|
||||
) INNER JOIN basusr ON (
|
||||
usr.usr_id=basusr.usr_id
|
||||
AND (basusr.base_id=
|
||||
'" . implode("' OR basusr.base_id='", $lst_base_id) . "'
|
||||
)
|
||||
@@ -249,12 +249,13 @@ class set_export extends set_abstract
|
||||
GROUP BY usr_id ";
|
||||
$params = array();
|
||||
} elseif ($this->app['phraseanet.registry']->get('GV_ftp_for_user')) {
|
||||
$sql = "SELECT usr.usr_id,usr_login,usr.addrFTP,usr.loginFTP,usr.sslFTP,
|
||||
usr.pwdFTP,usr.destFTP,prefixFTPfolder,
|
||||
usr.passifFTP,usr.retryFTP,usr.usr_mail
|
||||
FROM (usr INNER JOIN basusr
|
||||
ON ( activeFTP=1 AND usr.usr_id=basusr.usr_id
|
||||
AND usr.usr_id = :usr_id
|
||||
$sql = "SELECT usr.usr_id,usr_login,usr.usr_mail, FtpCredential.*
|
||||
FROM (
|
||||
FtpCredential INNER JOIN usr ON (
|
||||
FtpCredential.active = 1 AND FtpCredential.usrId = usr.usr_id
|
||||
) INNER JOIN basusr ON (
|
||||
usr.usr_id=basusr.usr_id
|
||||
AND usr.usr_id = :usr_id
|
||||
AND (basusr.base_id=
|
||||
'" . implode("' OR basusr.base_id='", $lst_base_id) . "'
|
||||
)
|
||||
@@ -265,18 +266,17 @@ class set_export extends set_abstract
|
||||
}
|
||||
|
||||
$datas[] = array(
|
||||
'name' => _('export::ftp: reglages manuels'),
|
||||
'usr_id' => '0',
|
||||
'addrFTP' => '',
|
||||
'loginFTP' => '',
|
||||
'pwdFTP' => '',
|
||||
'ssl' => '0',
|
||||
'destFTP' => '',
|
||||
'prefixFTPfolder' => 'Export_' . date("Y-m-d_H.i.s"),
|
||||
'passifFTP' => false,
|
||||
'retryFTP' => 5,
|
||||
'mailFTP' => '',
|
||||
'sendermail' => $app['authentication']->getUser()->get_email()
|
||||
'name' => _('export::ftp: reglages manuels'),
|
||||
'usr_id' => '0',
|
||||
'address' => '',
|
||||
'login' => '',
|
||||
'password' => '',
|
||||
'ssl' => false,
|
||||
'dest_folder' => '',
|
||||
'prefix_folder' => 'Export_' . date("Y-m-d_H.i.s"),
|
||||
'passive' => false,
|
||||
'max_retry' => 5,
|
||||
'sendermail' => $app['authentication']->getUser()->get_email()
|
||||
);
|
||||
|
||||
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
@@ -286,21 +286,21 @@ class set_export extends set_abstract
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$datas[] = array(
|
||||
'name' => $row["usr_login"],
|
||||
'usr_id' => $row['usr_id'],
|
||||
'addrFTP' => $row['addrFTP'],
|
||||
'loginFTP' => $row['loginFTP'],
|
||||
'pwdFTP' => $row['pwdFTP'],
|
||||
'ssl' => $row['sslFTP'],
|
||||
'destFTP' => $row['destFTP'],
|
||||
'prefixFTPfolder' =>
|
||||
(strlen(trim($row['prefixFTPfolder'])) > 0 ?
|
||||
trim($row['prefixFTPfolder']) :
|
||||
'name' => $row["usr_login"],
|
||||
'usr_id' => $row['usr_id'],
|
||||
'address' => $row['address'],
|
||||
'login' => $row['login'],
|
||||
'password' => $row['password'],
|
||||
'ssl' => !! $row['tls'],
|
||||
'dest_folder' => $row['reception_folder'],
|
||||
'prefix_folder' =>
|
||||
(strlen(trim($row['repository_prefix_name'])) > 0 ?
|
||||
trim($row['repository_prefix_name']) :
|
||||
'Export_' . date("Y-m-d_H.i.s")),
|
||||
'passifFTP' => ($row['passifFTP'] > 0),
|
||||
'retryFTP' => $row['retryFTP'],
|
||||
'mailFTP' => $row['usr_mail'],
|
||||
'sendermail' => $app['authentication']->getUser()->get_email()
|
||||
'passive' => !! $row['passive'],
|
||||
'max_retry' => $row['max_retry'],
|
||||
'usr_mail' => $row['usr_mail'],
|
||||
'sender_mail' => $app['authentication']->getUser()->get_email()
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user