diff --git a/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php b/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php index 4f36152a2c..ec44c85b68 100644 --- a/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php +++ b/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php @@ -3,6 +3,7 @@ namespace Alchemy\Phrasea\Command\Developer; use Alchemy\Phrasea\Command\Command; +use Alchemy\Phrasea\Core\Provider\ORMServiceProvider; use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\Configuration as ORMConfiguration; use Doctrine\ORM\Tools\SchemaTool; @@ -33,34 +34,19 @@ class RegenerateSqliteDb extends Command $source = __DIR__ . '/../../../../../tests/db-ref.sqlite'; $target = __DIR__ . '/../../../../../tests/db-ref.sqlite.bkp'; - $fs->rename($source, $target); + if (is_file($source)) { + $fs->rename($source, $target); + } try { $dbParams = $this->container['phraseanet.configuration']->getTestConnectionParameters(); $dbParams['path'] = $source; - $config = new ORMConfiguration(); - AnnotationRegistry::registerFile( - $this->container['root.path'].'/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' - ); + $this->container->register(new ORMServiceProvider()); + $this->container['EM.dbal-conf'] = $dbParams; - $annotationReader = new AnnotationReader(); - $driverChain = new DriverChain(); - $annotationDriver = new AnnotationDriver( - $annotationReader, - array($this->container['root.path'].'/lib/Doctrine/Entities') - ); - $driverChain->addDriver($annotationDriver, 'Entities'); - - $config->setAutoGenerateProxyClasses(true); - $config->setMetadataDriverImpl($driverChain); - $config->setProxyDir($this->container['root.path'] . '/lib/Doctrine/Proxies'); - $config->setProxyNamespace('Proxies'); - - $em = EntityManager::create($dbParams, $config, new EventManager()); - - $metadatas = $em->getMetadataFactory()->getAllMetadata(); - $schemaTool = new SchemaTool($em); + $metadatas = $this->container['EM']->getMetadataFactory()->getAllMetadata(); + $schemaTool = new SchemaTool($this->container['EM']); $schemaTool->createSchema($metadatas); } catch (\Exception $e) { $fs->rename($target, $source); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index e25f989dea..a77b2e26fc 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\Controller\Admin; use Alchemy\Phrasea\Helper\User as UserHelper; +use Entities\FtpCredential; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; @@ -797,23 +798,23 @@ class Users implements ControllerProviderInterface && false === \User_Adapter::get_usr_id_from_email($app, $curUser['usr_mail'])) { $NewUser = \User_Adapter::create($app, $curUser['usr_login'], $curUser['usr_password'], $curUser['usr_mail'], false); - if (isset($curUser['defaultftpdatasent'])) { - $NewUser->set_defaultftpdatas($curUser['defaultftpdatasent']); - } + $ftpCredential = new FtpCredential(); + $ftpCredential->setUsrId($NewUser->get_id()); + if (isset($curUser['activeFTP'])) { - $NewUser->set_activeftp((int) ($curUser['activeFTP'])); + $ftpCredential->setActive((int) $curUser['activeFTP']); } if (isset($curUser['addrFTP'])) { - $NewUser->set_ftp_address($curUser['addrFTP']); + $ftpCredential->setAddress((string) $curUser['addrFTP']); } if (isset($curUser['passifFTP'])) { - $NewUser->set_ftp_passif((int) ($curUser['passifFTP'])); + $ftpCredential->setPassive((int) $curUser['passifFTP']); } if (isset($curUser['destFTP'])) { - $NewUser->set_ftp_dir($curUser['destFTP']); + $ftpCredential->setReceptionFolder($curUser['destFTP']); } if (isset($curUser['prefixFTPfolder'])) { - $NewUser->set_ftp_dir_prefix($curUser['prefixFTPfolder']); + $ftpCredential->setRepositoryPrefixName($curUser['prefixFTPfolder']); } if (isset($curUser['usr_prenom'])) { $NewUser->set_firstname($curUser['usr_prenom']); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Export.php b/lib/Alchemy/Phrasea/Controller/Prod/Export.php index fc299acc9c..03c2cfa479 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Export.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Export.php @@ -168,7 +168,7 @@ class Export implements ControllerProviderInterface { $download = new \set_exportftp($app, $request->request->get('lst'), $request->request->get('ssttid')); - $mandatoryParameters = array('addr', 'login', 'destfolder', 'NAMMKDFOLD', 'obj'); + $mandatoryParameters = array('address', 'login', 'dest_folder', 'prefix_folder', 'obj'); foreach ($mandatoryParameters as $parameter) { if (!$request->request->get($parameter)) { @@ -194,14 +194,14 @@ class Export implements ControllerProviderInterface $download->export_ftp( $request->request->get('user_dest'), - $request->request->get('addr'), + $request->request->get('address'), $request->request->get('login'), - $request->request->get('pwd', ''), + $request->request->get('password', ''), $request->request->get('ssl'), - $request->request->get('nbretry'), - $request->request->get('passif'), - $request->request->get('destfolder'), - $request->request->get('NAMMKDFOLD'), + $request->request->get('max_retry'), + $request->request->get('passive'), + $request->request->get('dest_folder'), + $request->request->get('prefix_folder'), $request->request->get('logfile') ); diff --git a/lib/Alchemy/Phrasea/Controller/Root/Account.php b/lib/Alchemy/Phrasea/Controller/Root/Account.php index 5a3ff52d31..61021fac9d 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Account.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Account.php @@ -17,6 +17,7 @@ use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Mail\MailRequestEmailUpdate; use Alchemy\Phrasea\Form\Login\PhraseaRenewPasswordForm; +use Entities\FtpCredential; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -363,7 +364,7 @@ class Account implements ControllerProviderInterface 'form_company', 'form_activity', 'form_geonameid', - 'form_addrFTP', + 'form_addressFTP', 'form_loginFTP', 'form_pwdFTP', 'form_destFTP', @@ -372,26 +373,11 @@ class Account implements ControllerProviderInterface ); if (0 === count(array_diff($accountFields, array_keys($request->request->all())))) { - $defaultDatas = 0; - - if ($datas = (array) $request->request->get("form_defaultdataFTP", array())) { - if (in_array('document', $datas)) { - $defaultDatas += 4; - } - - if (in_array('preview', $datas)) { - $defaultDatas += 2; - } - - if (in_array('caption', $datas)) { - $defaultDatas += 1; - } - } - try { $app['phraseanet.appbox']->get_connection()->beginTransaction(); - $app['authentication']->getUser()->set_gender($request->request->get("form_gender")) + $app['authentication']->getUser() + ->set_gender($request->request->get("form_gender")) ->set_firstname($request->request->get("form_firstname")) ->set_lastname($request->request->get("form_lastname")) ->set_address($request->request->get("form_address")) @@ -402,18 +388,30 @@ class Account implements ControllerProviderInterface ->set_company($request->request->get("form_company")) ->set_position($request->request->get("form_function")) ->set_geonameid($request->request->get("form_geonameid")) - ->set_mail_notifications((bool) $request->request->get("mail_notifications")) - ->set_activeftp($request->request->get("form_activeFTP")) - ->set_ftp_address($request->request->get("form_addrFTP")) - ->set_ftp_login($request->request->get("form_loginFTP")) - ->set_ftp_password($request->request->get("form_pwdFTP")) - ->set_ftp_passif($request->request->get("form_passifFTP")) - ->set_ftp_dir($request->request->get("form_destFTP")) - ->set_ftp_dir_prefix($request->request->get("form_prefixFTPfolder")) - ->set_defaultftpdatas($defaultDatas); + ->set_mail_notifications((bool) $request->request->get("mail_notifications")); + + /* @var $ftpCredential \Entities\FtpCredential */ + $ftpCredential = $app['EM']->getRepository('Entities\FtpCredential')->findOneBy(array( + 'usrId' => $app['authentication']->getUser()->get_id() + )); + + if (null === $ftpCredential) { + $ftpCredential = new \Entities\FtpCredential(); + $ftpCredential->setUsrId($app['authentication']->getUser()->get_id()); + } + + $ftpCredential->setActive($request->request->get("form_activeFTP")); + $ftpCredential->setAddress($request->request->get("form_addressFTP")); + $ftpCredential->setLogin($request->request->get("form_loginFTP")); + $ftpCredential->setPassword($request->request->get("form_pwdFTP")); + $ftpCredential->setPassive($request->request->get("form_passifFTP")); + $ftpCredential->setReceptionFolder($request->request->get("form_destFTP")); + $ftpCredential->setRepositoryPrefixName($request->request->get("form_prefixFTPfolder")); - $app->addFlash('success', _('login::notification: Changements enregistres')); $app['phraseanet.appbox']->get_connection()->commit(); + $app['EM']->persist($ftpCredential); + $app['EM']->flush(); + $app->addFlash('success', _('login::notification: Changements enregistres')); } catch (Exception $e) { $app->addFlash('error', _('forms::erreurs lors de l\'enregistrement des modifications')); $app['phraseanet.appbox']->get_connection()->rollBack(); diff --git a/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php index e602080d57..bce5d5fd9a 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php @@ -44,24 +44,11 @@ class ORMServiceProvider implements ServiceProviderInterface return new MonologSQLLogger($logger, 'yaml'); }); - $app['EM'] = $app->share(function(Application $app) { - - $config = new ORMConfiguration(); - - if ($app['debug']) { - $config->setSQLLogger($app['EM.sql-logger']); - } - + $app['EM.driver'] = $app->share(function(Application $app) { AnnotationRegistry::registerFile( $app['root.path'].'/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' ); - $opCodeCacheType = $app['phraseanet.configuration']['main']['opcodecache']['type']; - $opCodeCacheOptions = $app['phraseanet.configuration']['main']['opcodecache']['options']; - - $cacheType = $app['phraseanet.configuration']['main']['cache']['type']; - $cacheOptions = $app['phraseanet.configuration']['main']['cache']['options']; - $annotationReader = new AnnotationReader(); $fileCacheReader = new FileCacheReader( $annotationReader, @@ -82,35 +69,68 @@ class ORMServiceProvider implements ServiceProviderInterface $driverChain->addDriver($annotationDriver, 'Entities'); + return $driverChain; + }); + + $app['EM.config'] = $app->share(function(Application $app) { + $config = new ORMConfiguration(); + + if ($app['debug']) { + $config->setSQLLogger($app['EM.sql-logger']); + } + $config->setMetadataCacheImpl($app['phraseanet.cache-service']->factory( - 'ORMmetadata', $opCodeCacheType, $opCodeCacheOptions + 'ORMmetadata', $app['EM.opcode-cache-type'], $app['EM.opcode-cache-options'] )); $config->setQueryCacheImpl($app['phraseanet.cache-service']->factory( - 'ORMquery', $opCodeCacheType, $opCodeCacheOptions + 'ORMquery', $app['EM.opcode-cache-type'], $app['EM.opcode-cache-options'] )); $config->setResultCacheImpl($app['phraseanet.cache-service']->factory( - 'ORMresult', $cacheType, $cacheOptions + 'ORMresult', $app['EM.cache-type'], $app['EM.cache-options'] )); $config->setAutoGenerateProxyClasses($app['debug']); - $config->setMetadataDriverImpl($driverChain); + $config->setMetadataDriverImpl($app['EM.driver']); $config->setProxyDir($app['root.path'] . '/lib/Doctrine/Proxies'); $config->setProxyNamespace('Proxies'); - if ('test' === $app->getEnvironment()) { - $dbalConf = $app['phraseanet.configuration']['main']['database-test']; - } else { - $dbalConf = $app['phraseanet.configuration']['main']['database']; - } + return $config; + }); + $app['EM.opcode-cache-type'] = $app->share(function(Application $app) { + return $app['phraseanet.configuration']['main']['opcodecache']['type']; + }); + $app['EM.opcode-cache-options'] = $app->share(function(Application $app) { + return $app['phraseanet.configuration']['main']['opcodecache']['options']; + }); + + $app['EM.cache-type'] = $app->share(function(Application $app) { + return $app['phraseanet.configuration']['main']['cache']['type']; + }); + $app['EM.cache-options'] = $app->share(function(Application $app) { + return $app['phraseanet.configuration']['main']['cache']['options']; + }); + $app['EM.events-manager'] = $app->share(function(Application $app) { $evm = new EventManager(); $evm->addEventSubscriber(new TimestampableListener()); + return $evm; + }); + + $app['EM.dbal-conf'] = $app->share(function(Application $app) { + if ('test' === $app->getEnvironment()) { + return $app['phraseanet.configuration']['main']['database-test']; + } + + return $app['phraseanet.configuration']['main']['database']; + }); + + $app['EM'] = $app->share(function(Application $app) { try { - $em = EntityManager::create($dbalConf, $config, $evm); + $em = EntityManager::create($app['EM.dbal-conf'], $app['EM.config'], $app['EM.events-manager']); } catch (\Exception $e) { throw new RuntimeException("Unable to create database connection", $e->getCode(), $e); } diff --git a/lib/Alchemy/Phrasea/Core/Version.php b/lib/Alchemy/Phrasea/Core/Version.php index 5de67b440b..f7aaad1888 100644 --- a/lib/Alchemy/Phrasea/Core/Version.php +++ b/lib/Alchemy/Phrasea/Core/Version.php @@ -18,7 +18,7 @@ namespace Alchemy\Phrasea\Core; */ class Version { - protected static $number = '3.9.0.a0'; + protected static $number = '3.9.0.a1'; protected static $name = 'Diplodocus'; public static function getNumber() diff --git a/lib/Doctrine/Entities/FtpCredential.php b/lib/Doctrine/Entities/FtpCredential.php new file mode 100644 index 0000000000..58e7eb9568 --- /dev/null +++ b/lib/Doctrine/Entities/FtpCredential.php @@ -0,0 +1,270 @@ +id; + } + + /** + * @return \User_Adapter + */ + public function getUser(Application $app) + { + return \User_Adapter::getInstance($this->usrId, $app); + } + + /** + * @return \User_Adapter + */ + public function getUsrId() + { + return $this->usrId; + } + + /** + * @param integer $usrId + */ + public function setUsrId($usrId) + { + $this->usrId = $usrId; + } + + /** + * @return boolean + */ + public function isActive() + { + return $this->active; + } + + /** + * @param boolean $active + */ + public function setActive($active) + { + $this->active = (Boolean) $active; + } + + /** + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * @param string $address + */ + public function setAddress($address) + { + $this->address = $address; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->login; + } + + /** + * @param string $login + */ + public function setLogin($login) + { + $this->login = $login; + } + + /** + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $password + */ + public function setPassword($password) + { + $this->password = $password; + } + + /** + * @return string + */ + public function getReceptionFolder() + { + return $this->receptionFolder; + } + + /** + * @param string $receptionFolder + */ + public function setReceptionFolder($receptionFolder) + { + $this->receptionFolder = $receptionFolder; + } + + /** + * @return string + */ + public function getRepositoryPrefixName() + { + return $this->repositoryPrefixName; + } + + /** + * @param string $repositoryPrefixName + */ + public function setRepositoryPrefixName($repositoryPrefixName) + { + $this->repositoryPrefixName = $repositoryPrefixName; + } + + /** + * @return boolean + */ + public function isPassive() + { + return $this->passive; + } + + /** + * @param string $passive + */ + public function setPassive($passive) + { + $this->passive = (Boolean) $passive; + } + + /** + * @return boolean + */ + public function isSsl() + { + return $this->ssl; + } + + /** + * @param string $ssl + */ + public function setSsl($ssl) + { + $this->ssl = (Boolean) $ssl; + } + + /** + * @return integer + */ + public function getMaxRetry() + { + return $this->maxRetry; + } + + /** + * @param string $maxRetry + */ + public function setMaxRetry($maxRetry) + { + $this->maxRetry = $maxRetry; + } + + /** + * @return \Datetime + */ + public function getUpdated() + { + return $this->updated; + } +} diff --git a/lib/Doctrine/Repositories/FtpCredentialRepository.php b/lib/Doctrine/Repositories/FtpCredentialRepository.php new file mode 100644 index 0000000000..dc39ec840b --- /dev/null +++ b/lib/Doctrine/Repositories/FtpCredentialRepository.php @@ -0,0 +1,18 @@ +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 $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); diff --git a/lib/classes/User/Interface.php b/lib/classes/User/Interface.php index 3b23447c1d..649d288602 100644 --- a/lib/classes/User/Interface.php +++ b/lib/classes/User/Interface.php @@ -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); diff --git a/lib/classes/patch/390.php b/lib/classes/patch/390.php new file mode 100644 index 0000000000..4e7b62ef44 --- /dev/null +++ b/lib/classes/patch/390.php @@ -0,0 +1,89 @@ +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(); + } +} diff --git a/lib/classes/set/export.php b/lib/classes/set/export.php index 0208cb8fc2..271aacdb23 100644 --- a/lib/classes/set/export.php +++ b/lib/classes/set/export.php @@ -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() ); } diff --git a/lib/conf.d/bases_structure.xml b/lib/conf.d/bases_structure.xml index bafcefb40b..5c49ad3a1b 100644 --- a/lib/conf.d/bases_structure.xml +++ b/lib/conf.d/bases_structure.xml @@ -3729,107 +3729,6 @@ 0 - - activeFTP - tinyint(1) - - - - - 0 - - - - addrFTP - - varchar(128) - - - - - - - - sslFTP - - tinyint(1) unsigned - - - - 0 - - - - - loginFTP - varchar(128) - - - - - - - - - pwdFTP - varchar(128) - - - - - - - - - destFTP - varchar(128) - - - - - - - - - passifFTP - tinyint(1) unsigned - - - - - 0 - - - - retryFTP - tinyint(1) unsigned - - - - - 5 - - - - defaultftpdatasent - int(11) unsigned - - - - - 0 - - - - prefixFTPfolder - - varchar(100) - - - - - - lastModel varchar(50) @@ -4019,10 +3918,6 @@ 0000-00-00 00:00:00 0 0 - 0 - 0 - 5 - 5 0 0 @@ -4038,10 +3933,6 @@ 0000-00-00 00:00:00 0 0 - 0 - 0 - 5 - 5 0 0 diff --git a/templates/web/account/account.html.twig b/templates/web/account/account.html.twig index 9b579b6d83..e23ff26884 100644 --- a/templates/web/account/account.html.twig +++ b/templates/web/account/account.html.twig @@ -167,48 +167,49 @@ {% trans "FTP" %} + {% set ftpCredential = app["authentication"].getUser().getFtpCredential() %}

-
+
- +
- +

- +

- +

- +

- +

@@ -216,7 +217,7 @@

@@ -224,7 +225,7 @@
- +

diff --git a/templates/web/common/dialog_export.html.twig b/templates/web/common/dialog_export.html.twig index 9aa9f900ea..b2cfa38913 100644 --- a/templates/web/common/dialog_export.html.twig +++ b/templates/web/common/dialog_export.html.twig @@ -3,52 +3,52 @@ {% macro print_ftp_form(datas) %}
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- - + +
diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php index df3fd335e3..c4e2079055 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php @@ -107,10 +107,10 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testExportFtpNoDocs() { self::$DI['client']->request('POST', '/prod/export/ftp/', array( - 'addr' => 'test.ftp', + 'address' => 'test.ftp', 'login' => 'login', - 'destfolder' => 'documents', - 'NAMMKDFOLD' => 'documents', + 'dest_folder' => 'documents', + 'prefix_folder' => 'documents', 'obj' => array('preview') )); $response = self::$DI['client']->getResponse(); @@ -137,10 +137,10 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { return array( array(array()), - array(array('addr' => '')), - array(array('addr' => '', 'login' => '')), - array(array('addr' => '', 'login' => '', 'destfolder' => '')), - array(array('addr' => '', 'login' => '', 'destfolder' => '', 'NAMMKDFOLD' => '')), + array(array('address' => '')), + array(array('address' => '', 'login' => '')), + array(array('address' => '', 'login' => '', 'dest_folder' => '')), + array(array('address' => '', 'login' => '', 'dest_folder' => '', 'prefix_folder' => '')), ); } @@ -157,10 +157,10 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['client']->request('POST', '/prod/export/ftp/', array( 'lst' => self::$DI['record_1']->get_serialize_key(), 'user_dest' => self::$DI['user']->get_id(), - 'addr' => 'local.phrasea.test', + 'address' => 'local.phrasea.test', 'login' => self::$DI['user']->get_email(), - 'destfolder' => '/home/test/', - 'NAMMKDFOLD' => 'test2/', + 'dest_folder' => '/home/test/', + 'prefix_folder' => 'test2/', 'obj' => array('preview') )); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php index e4c800bd1f..2c0c52a5b6 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php @@ -305,7 +305,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'form_company' => 'NASA', 'form_activity' => 'Space', 'form_geonameid' => '', - 'form_addrFTP' => '', + 'form_addressFTP' => '', 'form_loginFTP' => '', 'form_pwdFTP' => '', 'form_destFTP' => '', diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index 0499a6aab8..c59520c680 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -60,6 +60,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase self::$time_start = microtime(true); self::$DI = new \Pimple(); + self::initializeSqliteDB(); $application = new Application('test'); @@ -68,10 +69,10 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase exit(1); } - self::createSetOfUserTests($application); - self::updateTablesSchema($application); + self::createSetOfUserTests($application); + self::setCollection($application); self::generateRecords($application); @@ -82,6 +83,14 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } } + public static function initializeSqliteDB($path = '/tmp/db.sqlite') + { + if (is_file($path)) { + unlink($path); + } + copy(__DIR__ . '/../db-ref.sqlite', $path); + } + public function createApplication() { @@ -129,9 +138,8 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $app['debug'] = true; - $app['EM'] = $app->share($app->extend('EM', function($em) { - @unlink('/tmp/db.sqlite'); - copy(__DIR__ . '/../db-ref.sqlite', '/tmp/db.sqlite'); + $app['EM'] = $app->share($app->extend('EM', function($em) use ($phpunit) { + $phpunit::initializeSqliteDB(); return $em; })); @@ -171,9 +179,8 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $app['debug'] = true; - $app['EM'] = $app->share($app->extend('EM', function($em) { - @unlink('/tmp/db.sqlite'); - copy(__DIR__ . '/../db-ref.sqlite', '/tmp/db.sqlite'); + $app['EM'] = $app->share($app->extend('EM', function ($em) use ($phpunit) { + $phpunit::initializeSqliteDb(); return $em; })); diff --git a/tests/db-ref.sqlite b/tests/db-ref.sqlite index ce013a619d..f31ad467c4 100644 Binary files a/tests/db-ref.sqlite and b/tests/db-ref.sqlite differ