Ejemplo n.º 1
0
 /**
  * Update account informations
  *
  * @param  PhraseaApplication $app     A Silex application where the controller is mounted on
  * @param  Request            $request The current request
  * @return Response
  */
 public function updateAccount(PhraseaApplication $app, Request $request)
 {
     $registrations = $request->request->get('registrations');
     if (false === is_array($registrations)) {
         $app->abort(400, '"registrations" parameter must be an array of base ids.');
     }
     if (0 !== count($registrations)) {
         foreach ($registrations as $baseId) {
             $app['manipulator.registration']->createRegistration($app['authentication']->getUser(), \collection::get_from_base_id($app, $baseId));
         }
         $app->addFlash('success', $app->trans('Your registration requests have been taken into account.'));
     }
     $accountFields = ['form_gender', 'form_firstname', 'form_lastname', 'form_address', 'form_zip', 'form_phone', 'form_fax', 'form_function', 'form_company', 'form_activity', 'form_geonameid', 'form_addressFTP', 'form_loginFTP', 'form_pwdFTP', 'form_destFTP', 'form_prefixFTPfolder', 'form_retryFTP'];
     if (0 === count(array_diff($accountFields, array_keys($request->request->all())))) {
         $app['authentication']->getUser()->setGender($request->request->get("form_gender"))->setFirstName($request->request->get("form_firstname"))->setLastName($request->request->get("form_lastname"))->setAddress($request->request->get("form_address"))->setZipCode($request->request->get("form_zip"))->setPhone($request->request->get("form_phone"))->setFax($request->request->get("form_fax"))->setJob($request->request->get("form_activity"))->setCompany($request->request->get("form_company"))->setActivity($request->request->get("form_function"))->setMailNotificationsActivated((bool) $request->request->get("mail_notifications"));
         $app['manipulator.user']->setGeonameId($app['authentication']->getUser(), $request->request->get("form_geonameid"));
         $ftpCredential = $app['authentication']->getUser()->getFtpCredential();
         if (null === $ftpCredential) {
             $ftpCredential = new FtpCredential();
             $ftpCredential->setUser($app['authentication']->getUser());
         }
         $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['EM']->persist($ftpCredential);
         $app['EM']->persist($app['authentication']->getUser());
         $app['EM']->flush();
         $app->addFlash('success', $app->trans('login::notification: Changements enregistres'));
     }
     $requestedNotifications = (array) $request->request->get('notifications', []);
     foreach ($app['events-manager']->list_notifications_available($app['authentication']->getUser()->getId()) as $notifications) {
         foreach ($notifications as $notification) {
             $app['manipulator.user']->setNotificationSetting($app['authentication']->getUser(), $notification['id'], isset($requestedNotifications[$notification['id']]));
         }
     }
     return $app->redirectPath('account');
 }
Ejemplo n.º 2
0
 private function updateFtpSettings(EntityManager $em)
 {
     $offset = 0;
     $perBatch = 100;
     do {
         $builder = $em->getConnection()->createQueryBuilder();
         $sql = $builder->select('u.usr_id', 'u.activeFTP', 'u.addrFTP', 'u.loginFTP', 'u.retryFTP', 'u.passifFTP', 'u.pwdFTP', 'u.destFTP', 'u.prefixFTPfolder')->from('usr', 'u')->where($builder->expr()->notLike('u.usr_login', $builder->expr()->literal('(#deleted_%')), $builder->expr()->eq('u.model_of', 0), $builder->expr()->neq('u.addrFTP', $builder->expr()->literal('')))->setFirstResult($offset)->setMaxResults($perBatch)->getSQL();
         $rs = $em->getConnection()->fetchAll($sql);
         foreach ($rs as $row) {
             try {
                 $user = $em->createQuery('SELECT PARTIAL u.{id} FROM Phraseanet:User u WHERE u.id = :id')->setParameters(['id' => $row['usr_id']])->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)->getSingleResult();
             } catch (NoResultException $e) {
                 continue;
             }
             $credential = new FtpCredential();
             $credential->setActive($row['activeFTP']);
             $credential->setAddress($row['addrFTP']);
             $credential->setLogin($row['loginFTP']);
             $credential->setMaxRetry((int) $row['retryFTP']);
             $credential->setPassive($row['passifFTP']);
             $credential->setPassword($row['pwdFTP']);
             $credential->setReceptionFolder($row['destFTP']);
             $credential->setRepositoryPrefixName($row['prefixFTPfolder']);
             $credential->setUser($user);
             $em->persist($credential);
         }
         $em->flush();
         $em->clear();
         $offset += $perBatch;
     } while (count($rs) > 0);
     return true;
 }
Ejemplo n.º 3
0
 private function updateFtpSettings(EntityManager $em)
 {
     $offset = 0;
     $perBatch = 100;
     do {
         $sql = 'SELECT usr_id, activeFTP, addrFTP, loginFTP,
                     retryFTP, passifFTP, pwdFTP, destFTP, prefixFTPfolder
                 FROM usr
                 WHERE
                     usr_login NOT LIKE "(#deleted_%"
                     AND model_of = 0
                     AND addrFTP != ""' . sprintf(' LIMIT %d, %d', $offset, $perBatch);
         $rs = $em->getConnection()->fetchAll($sql);
         foreach ($rs as $row) {
             try {
                 $user = $em->createQuery('SELECT PARTIAL u.{id} FROM Phraseanet:User u WHERE u.id = :id')->setParameters(['id' => $row['usr_id']])->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)->getSingleResult();
             } catch (NoResultException $e) {
                 continue;
             }
             $credential = new FtpCredential();
             $credential->setActive($row['activeFTP']);
             $credential->setAddress($row['addrFTP']);
             $credential->setLogin($row['loginFTP']);
             $credential->setMaxRetry((int) $row['retryFTP']);
             $credential->setPassive($row['passifFTP']);
             $credential->setPassword($row['pwdFTP']);
             $credential->setReceptionFolder($row['destFTP']);
             $credential->setRepositoryPrefixName($row['prefixFTPfolder']);
             $credential->setUser($user);
             $em->persist($credential);
         }
         $em->flush();
         $em->clear();
         $offset += $perBatch;
     } while (count($rs) > 0);
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function setLogin($login)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setLogin', array($login));
     return parent::setLogin($login);
 }