Remove User_Adapter

This commit is contained in:
Nicolas Le Goff
2013-11-05 17:38:27 +01:00
parent 171390f7c8
commit c156f842c7
231 changed files with 3918 additions and 2986 deletions

View File

@@ -14,6 +14,7 @@ require_once __DIR__ . '/../../vendor/autoload.php';
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Behat\Behat\Exception\PendingException; use Behat\Behat\Exception\PendingException;
use Behat\MinkExtension\Context\MinkContext; use Behat\MinkExtension\Context\MinkContext;
use Alchemy\Phrasea\Model\Entities\User;
class GuiContext extends MinkContext class GuiContext extends MinkContext
{ {
@@ -65,9 +66,7 @@ class GuiContext extends MinkContext
*/ */
public function aUserDoesNotExist($login) public function aUserDoesNotExist($login)
{ {
if (false !== $userId = \User_Adapter::get_usr_id_from_login($this->app, $login)) { if (null !== $user = $this->app['manipulator.user']->getRepository()->findByLogin($login)) {
$user = \User_Adapter::getInstance($userId, $this->app);
$user->ACL()->revoke_access_from_bases(array_keys( $user->ACL()->revoke_access_from_bases(array_keys(
$this->app['authentication']->getUser()->ACL()->get_granted_base(array('canadmin')) $this->app['authentication']->getUser()->ACL()->get_granted_base(array('canadmin'))
)); ));
@@ -81,14 +80,8 @@ class GuiContext extends MinkContext
*/ */
public function aUserExistsWithAsPassword($login, $password) public function aUserExistsWithAsPassword($login, $password)
{ {
if (false === \User_Adapter::get_usr_id_from_login($this->app, $login)) { if (null === $user = $this->app['manipulator.user']->getRepository()->findByLogin($login)) {
\User_Adapter::create( $this->app['manipulator.user']->create($login, $password, null, false);
$this->app,
$login,
$password,
$login,
false
);
} }
} }
@@ -168,17 +161,8 @@ class GuiContext extends MinkContext
*/ */
public function userGuestAccessIsEnable() public function userGuestAccessIsEnable()
{ {
if (false === $usrId = \User_Adapter::get_usr_id_from_login($this->app, 'invite')) { if (null === $user = $this->app['manipulator.user']->getRepository()->findByLogin(User::USER_GUEST)) {
$user = \User_Adapter::create( $user = $this->app['manipulator.user']->create(User::USER_GUEST, '');
$this->app,
'invite',
'',
null,
false,
true
);
} else {
$user = \User_Adapter::getInstance($usrId, $this->app);
} }
$user->ACL()->give_access_to_sbas(array_keys($this->app['phraseanet.appbox']->get_databoxes())); $user->ACL()->give_access_to_sbas(array_keys($this->app['phraseanet.appbox']->get_databoxes()));
@@ -195,9 +179,7 @@ class GuiContext extends MinkContext
*/ */
public function userGuestAccessIsDisable() public function userGuestAccessIsDisable()
{ {
if (false !== $usrId = \User_Adapter::get_usr_id_from_login($this->app, 'invite')) { if (null !== $user = $this->app['manipulator.user']->getRepository()->findByLogin(User::USER_GUEST)) {
$user = \User_Adapter::getInstance($usrId, $this->app);
foreach ($this->app['phraseanet.appbox']->get_databoxes() as $databox) { foreach ($this->app['phraseanet.appbox']->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $collection) { foreach ($databox->get_collections() as $collection) {
$user->ACL()->revoke_access_from_bases(array($collection->get_base_id())); $user->ACL()->revoke_access_from_bases(array($collection->get_base_id()));
@@ -227,12 +209,10 @@ class GuiContext extends MinkContext
*/ */
public function isAuthenticated($login) public function isAuthenticated($login)
{ {
if (false == $usrId = \User_Adapter::get_usr_id_from_login($this->app, $login)) { if (null === $user = $this->app['manipulator.user']->getRepository()->findByLogin($login)) {
throw new \Exception(sprintf('User %s does not exists, use the following definition to create it : a user "%s" exists', $login, $login)); throw new \Exception(sprintf('User %s does not exists, use the following definition to create it : a user "%s" exists', $login, $login));
} }
$user = \User_Adapter::getInstance($usrId, $this->app);
$this->app['authentication']->openAccount($user); $this->app['authentication']->openAccount($user);
throw new PendingException(); throw new PendingException();

View File

@@ -111,6 +111,7 @@ use Alchemy\Phrasea\Core\Provider\TokensServiceProvider;
use Alchemy\Phrasea\Core\Provider\TranslationServiceProvider; use Alchemy\Phrasea\Core\Provider\TranslationServiceProvider;
use Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider; use Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Form\Extension\HelpTypeExtension; use Alchemy\Phrasea\Form\Extension\HelpTypeExtension;
use Alchemy\Phrasea\Twig\JSUniqueID; use Alchemy\Phrasea\Twig\JSUniqueID;
use Alchemy\Phrasea\Twig\Camelize; use Alchemy\Phrasea\Twig\Camelize;
@@ -771,13 +772,11 @@ class Application extends SilexApplication
*/ */
public function isGuestAllowed() public function isGuestAllowed()
{ {
$usrId = \User_Adapter::get_usr_id_from_login($this, 'invite'); if (null === $user = $this['manipulator.user']->getRepository()->findByLogin(User::USER_GUEST)) {
if (!$usrId) {
return false; return false;
} }
return count($this['acl']->get(\User_Adapter::getInstance($usrId, $this))->get_granted_base()) > 0; return count($this['acl']->get($user)->get_granted_base()) > 0;
} }
/** /**

View File

@@ -37,7 +37,7 @@ class ACLProvider
* *
* @return \ACL * @return \ACL
*/ */
public function get(\User_Adapter $user) public function get(User $user)
{ {
if (null !== $acl = $this->fetchFromCache($user)) { if (null !== $acl = $this->fetchFromCache($user)) {
return $acl; return $acl;
@@ -61,9 +61,9 @@ class ACLProvider
* *
* @return null || \ACL * @return null || \ACL
*/ */
private function fetchFromCache(\User_Adapter $user) private function fetchFromCache(User $user)
{ {
return $this->hasCache($user) ? self::$cache[$user->get_id()] : null; return $this->hasCache($user) ? self::$cache[$user->getId()] : null;
} }
/** /**
@@ -73,9 +73,9 @@ class ACLProvider
* *
* @return boolean * @return boolean
*/ */
private function hasCache(\User_Adapter $user) private function hasCache(User $user)
{ {
return isset(self::$cache[$user->get_id()]); return isset(self::$cache[$user->getId()]);
} }
/** /**
@@ -85,8 +85,8 @@ class ACLProvider
* *
* @return \ACL * @return \ACL
*/ */
private function fetch(\User_Adapter $user) private function fetch(User $user)
{ {
return self::$cache[$user->get_id()] = new \ACL($user, $this->app); return self::$cache[$user->getId()] = new \ACL($user, $this->app);
} }
} }

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Authentication;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Model\Entities\User;
class AccountCreator class AccountCreator
{ {
@@ -56,7 +57,7 @@ class AccountCreator
* @param string $email The email * @param string $email The email
* @param array $templates Some extra templates to apply with the ones of this creator * @param array $templates Some extra templates to apply with the ones of this creator
* *
* @return \User_Adapter * @return User
* *
* @throws RuntimeException In case the AccountCreator is disabled * @throws RuntimeException In case the AccountCreator is disabled
* @throws InvalidArgumentException In case a user with the same email already exists * @throws InvalidArgumentException In case a user with the same email already exists
@@ -70,16 +71,16 @@ class AccountCreator
$login = $id; $login = $id;
$n = 1; $n = 1;
if (null !== $email && false !== \User_Adapter::get_usr_id_from_email($app, $email)) { if (null !== $email && null !== $app['manipulator.user']->getRepository()->findByEmail($email)) {
throw new InvalidArgumentException('Provided email already exist in account base.'); throw new InvalidArgumentException('Provided email already exist in account base.');
} }
while (false !== \User_Adapter::get_usr_id_from_login($app, $login)) { while (null !== $app['manipulator.user']->getRepository()->findByLogin($login)) {
$login = $id . '#' . $n; $login = $id . '#' . $n;
$n++; $n++;
} }
$user = \User_Adapter::create($app, $login, $this->random->generatePassword(), $email, false, false); $user = $app['manipulator.user']->createUser($login, $this->random->generatePassword(), $email);
$base_ids = []; $base_ids = [];
foreach ($this->appbox->get_databoxes() as $databox) { foreach ($this->appbox->get_databoxes() as $databox) {

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Authentication;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Model\Entities\User;
use Browser; use Browser;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Alchemy\Phrasea\Model\Entities\Session; use Alchemy\Phrasea\Model\Entities\Session;
@@ -43,7 +44,7 @@ class Authenticator
return $this->user; return $this->user;
} }
public function setUser(\User_Adapter $user = null) public function setUser(User $user = null)
{ {
$this->user = $user; $this->user = $user;
@@ -53,13 +54,13 @@ class Authenticator
/** /**
* Open user session * Open user session
* *
* @param \User_Adapter $user * @param User $user
* *
* @return Session * @return Session
* *
* @throws \Exception_InternalServerError * @throws \Exception_InternalServerError
*/ */
public function openAccount(\User_Adapter $user) public function openAccount(User $user)
{ {
$this->session->remove('usr_id'); $this->session->remove('usr_id');
$this->session->remove('session_id'); $this->session->remove('session_id');
@@ -69,7 +70,7 @@ class Authenticator
->setBrowserVersion($this->browser->getVersion()) ->setBrowserVersion($this->browser->getVersion())
->setPlatform($this->browser->getPlatform()) ->setPlatform($this->browser->getPlatform())
->setUserAgent($this->browser->getUserAgent()) ->setUserAgent($this->browser->getUserAgent())
->setUsrId($user->get_id()); ->setUsrId($user->getId());
$this->em->persist($session); $this->em->persist($session);
$this->em->flush(); $this->em->flush();
@@ -104,10 +105,8 @@ class Authenticator
throw new RuntimeException('Unable to refresh the session, it does not exist anymore'); throw new RuntimeException('Unable to refresh the session, it does not exist anymore');
} }
try { if (null === $user = $this->app['manipulator.user']->getRepository()->find($session->getUsrId())) {
$user = \User_Adapter::getInstance($session->getUsrId(), $this->app); throw new RuntimeException('Unable to refresh the session');
} catch (NotFoundHttpException $e) {
throw new RuntimeException('Unable to refresh the session', $e->getCode(), $e);
} }
$this->session->clear(); $this->session->clear();
@@ -145,7 +144,7 @@ class Authenticator
public function reinitUser() public function reinitUser()
{ {
if ($this->isAuthenticated()) { if ($this->isAuthenticated()) {
$this->user = \User_Adapter::getInstance($this->session->get('usr_id'), $this->app); $this->user = $this->app['manipulator.user']->getRepository()->find($this->session->get('usr_id'));
} else { } else {
$this->user = null; $this->user = null;
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Authentication; namespace Alchemy\Phrasea\Authentication;
use Alchemy\Phrasea\Model\Entities\Session; use Alchemy\Phrasea\Model\Entities\Session;
use Alchemy\Phrasea\Model\Entities\User;
class Manager class Manager
{ {
@@ -26,11 +27,11 @@ class Manager
/** /**
* *
* @param \User_Adapter $user * @param User $user
* *
* @return Session * @return Session
*/ */
public function openAccount(\User_Adapter $user) public function openAccount(User $user)
{ {
return $this->authenticator->openAccount($user); return $this->authenticator->openAccount($user);
} }

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\Exception\NotAuthenticatedException; use Alchemy\Phrasea\Authentication\Exception\NotAuthenticatedException;
use Alchemy\Phrasea\Authentication\Provider\Token\Token; use Alchemy\Phrasea\Authentication\Provider\Token\Token;
use Alchemy\Phrasea\Authentication\Provider\Token\Identity; use Alchemy\Phrasea\Authentication\Provider\Token\Identity;
use Alchemy\Phrasea\Model\Entities\User;
class SuggestionFinder class SuggestionFinder
{ {
@@ -30,7 +31,7 @@ class SuggestionFinder
* *
* @param Token $token * @param Token $token
* *
* @return null|\User_Adapter * @return null|User
* *
* @throws NotAuthenticatedException In case the token is not authenticated. * @throws NotAuthenticatedException In case the token is not authenticated.
*/ */
@@ -47,7 +48,7 @@ class SuggestionFinder
$stmt->closeCursor(); $stmt->closeCursor();
if ($row) { if ($row) {
return \User_Adapter::getInstance($row['usr_id'], $this->app); return $this->app['manipulator.user']->getRepository()->find($row['usr_id']);
} }
} }

View File

@@ -60,9 +60,7 @@ class CreateCollection extends Command
} }
$app = $this->container; $app = $this->container;
$this->container['manipulator.acl']->resetAdminRights(array_map(function ($id) use ($app) { $this->container['manipulator.acl']->resetAdminRights($this->container['manipulator.user']->getRepository()->findAdmins());
return \User_Adapter::getInstance($id, $app);
}, array_keys(\User_Adapter::get_sys_admins($this->container))));
$this->container['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($new_collection)); $this->container['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($new_collection));
} }

View File

@@ -200,8 +200,9 @@ class Collection implements ControllerProviderInterface
} }
foreach (array_filter($newAdmins) as $admin) { foreach (array_filter($newAdmins) as $admin) {
$user = \User_Adapter::getInstance($admin, $app); if (null !== $user = $app['manipulator.user']->getRepository()->find($admin)) {
$app['acl']->get($user)->update_rights_to_base($bas_id, ['order_master' => true]); $app['acl']->get($user)->update_rights_to_base($bas_id, array('order_master' => true));
}
} }
$conn->commit(); $conn->commit();

View File

@@ -69,7 +69,7 @@ class Dashboard implements ControllerProviderInterface
$parameters = [ $parameters = [
'cache_flushed' => $request->query->get('flush_cache') === 'ok', 'cache_flushed' => $request->query->get('flush_cache') === 'ok',
'admins' => \User_Adapter::get_sys_admins($app), 'admins' => $app['manipulator.user']->getRepository()->findAdmins(),
'email_status' => $emailStatus, 'email_status' => $emailStatus,
]; ];
@@ -132,9 +132,7 @@ class Dashboard implements ControllerProviderInterface
*/ */
public function resetAdminRights(Application $app, Request $request) public function resetAdminRights(Application $app, Request $request)
{ {
$app['manipulator.acl']->resetAdminRights(array_map(function ($id) use ($app) { $app['manipulator.acl']->resetAdminRights($app['manipulator.user']->getRepository()->findAdmins());
return \User_Adapter::getInstance($id, $app);
}, array_keys(\User_Adapter::get_sys_admins($app))));
return $app->redirectPath('admin_dashbord'); return $app->redirectPath('admin_dashbord');
} }
@@ -150,15 +148,13 @@ class Dashboard implements ControllerProviderInterface
{ {
if (count($admins = $request->request->get('admins', [])) > 0) { if (count($admins = $request->request->get('admins', [])) > 0) {
if (!in_array($app['authentication']->getUser()->get_id(), $admins)) { if (!in_array($app['authentication']->getUser()->getId(), $admins)) {
$admins[] = $app['authentication']->getUser()->get_id(); $admins[] = $app['authentication']->getUser()->getId();
} }
if ($admins > 0) { if ($admins > 0) {
\User_Adapter::set_sys_admins($app, array_filter($admins)); \User_Adapter::set_sys_admins($app, array_filter($admins));
$app['manipulator.acl']->resetAdminRights(array_map(function ($id) use ($app) { $app['manipulator.acl']->resetAdminRights($app['manipulator.user']->getRepository()->findAdmins());
return \User_Adapter::getInstance($id, $app);
}, array_keys(\User_Adapter::get_sys_admins($app))));
} }
} }

View File

@@ -52,7 +52,7 @@ class Publications implements ControllerProviderInterface
$feed = new Feed(); $feed = new Feed();
$publisher->setFeed($feed); $publisher->setFeed($feed);
$publisher->setUsrId($app['authentication']->getUser()->get_id()); $publisher->setUsrId($app['authentication']->getUser()->getId());
$publisher->setIsOwner(true); $publisher->setIsOwner(true);
$feed->addPublisher($publisher); $feed->addPublisher($publisher);
@@ -193,11 +193,11 @@ class Publications implements ControllerProviderInterface
$error = ''; $error = '';
try { try {
$request = $app['request']; $request = $app['request'];
$user = \User_Adapter::getInstance($request->request->get('usr_id'), $app); $user = $app['manipulator.user']->getRepository()->find($request->request->get('usr_id'));
$feed = $app["EM"]->find('Phraseanet:Feed', $id); $feed = $app["EM"]->find('Alchemy\Phrasea\Model\Entities\Feed', $id);
$publisher = new FeedPublisher(); $publisher = new FeedPublisher();
$publisher->setUsrId($user->get_id()); $publisher->setUsrId($user->getId());
$publisher->setFeed($feed); $publisher->setFeed($feed);
$feed->addPublisher($publisher); $feed->addPublisher($publisher);

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Helper\User as UserHelper; use Alchemy\Phrasea\Helper\User as UserHelper;
use Alchemy\Phrasea\Model\Entities\FtpCredential; use Alchemy\Phrasea\Model\Entities\FtpCredential;
use Alchemy\Phrasea\Model\Entities\User;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -173,24 +174,23 @@ class Users implements ControllerProviderInterface
]; ];
foreach ($users->export() as $user) { foreach ($users->export() as $user) {
/* @var $user \User_Adapter */
$userTable[] = [ $userTable[] = [
$user->get_id(), $user->getId(),
$user->get_login(), $user->getLogin(),
$user->get_lastname(), $user->getLastName(),
$user->get_firstname(), $user->getFirstName(),
$user->get_email(), $user->getEmail(),
$user->get_creation_date()->format(DATE_ATOM), $user->getCreated()->format(DATE_ATOM),
$user->get_modification_date()->format(DATE_ATOM), $user->getUpdated()->format(DATE_ATOM),
$user->get_address(), $user->getAddress(),
$user->get_city(), $user->getCity(),
$user->get_zipcode(), $user->getZipCode(),
$user->get_country(), $user->getCountry(),
$user->get_tel(), $user->getPhone(),
$user->get_fax(), $user->getFax(),
$user->get_job(), $user->getJob(),
$user->get_company(), $user->getCompany(),
$user->get_position() $user->getActivity()
]; ];
} }
@@ -241,10 +241,10 @@ class Users implements ControllerProviderInterface
foreach ($elligible_users as $user) { foreach ($elligible_users as $user) {
$datas[] = [ $datas[] = [
'email' => $user->get_email() ? : '' 'email' => $user->getEmail() ? : ''
, 'login' => $user->get_login() ? : '' , 'login' => $user->getLogin() ? : ''
, 'name' => $user->get_display_name() ? : '' , 'name' => $user->getDisplayName() ? : ''
, 'id' => $user->get_id() , 'id' => $user->getId()
]; ];
} }
@@ -252,7 +252,6 @@ class Users implements ControllerProviderInterface
}); });
$controllers->post('/create/', function (Application $app) { $controllers->post('/create/', function (Application $app) {
$datas = ['error' => false, 'message' => '', 'data' => null]; $datas = ['error' => false, 'message' => '', 'data' => null];
try { try {
$request = $app['request']; $request = $app['request'];
@@ -262,10 +261,10 @@ class Users implements ControllerProviderInterface
} else { } else {
$user = $module->create_newuser(); $user = $module->create_newuser();
} }
if (!($user instanceof \User_Adapter)) if (!($user instanceof User))
throw new \Exception('Unknown error'); throw new \Exception('Unknown error');
$datas['data'] = $user->get_id(); $datas['data'] = $user->getId();
} catch (\Exception $e) { } catch (\Exception $e) {
$datas['error'] = true; $datas['error'] = true;
if ($request->request->get('template') == '1') { if ($request->request->get('template') == '1') {
@@ -321,22 +320,22 @@ class Users implements ControllerProviderInterface
foreach ($results as $user) { foreach ($results as $user) {
$buffer[] = [ $buffer[] = [
$user->get_id() $user->getId()
, $user->get_login() , $user->getLogin()
, $user->get_lastname() , $user->getLastName()
, $user->get_firstname() , $user->getFirstName()
, $user->get_email() , $user->getEmail()
, $app['date-formatter']->format_mysql($user->get_creation_date()) , $app['date-formatter']->format_mysql($user->getCreated())
, $app['date-formatter']->format_mysql($user->get_modification_date()) , $app['date-formatter']->format_mysql($user->getUpdated())
, $user->get_address() , $user->getAddress()
, $user->get_city() , $user->getCity()
, $user->get_zipcode() , $user->getZipCode()
, $user->get_country() , $user->getCountry()
, $user->get_tel() , $user->getPhone()
, $user->get_fax() , $user->getFax()
, $user->get_job() , $user->getJob()
, $user->get_company() , $user->getCompany()
, $user->get_position() , $user->getActivity()
]; ];
} }
} while (count($results) > 0); } while (count($results) > 0);
@@ -366,7 +365,7 @@ class Users implements ControllerProviderInterface
$sql = 'SELECT usr_id, usr_login FROM usr WHERE model_of = :usr_id'; $sql = 'SELECT usr_id, usr_login FROM usr WHERE model_of = :usr_id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $app['authentication']->getUser()->get_id()]); $stmt->execute(array(':usr_id' => $app['authentication']->getUser()->getId()));
$models = $stmt->fetchAll(\PDO::FETCH_ASSOC); $models = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -458,10 +457,10 @@ class Users implements ControllerProviderInterface
$cache_to_update = []; $cache_to_update = [];
foreach ($templates as $usr => $template_id) { foreach ($templates as $usr => $template_id) {
$user = \User_Adapter::getInstance($usr, $app); $user = $app['manipulator.user']->getRepository()->find($usr);
$cache_to_update[$usr] = true; $cache_to_update[$usr] = true;
$user_template = \User_Adapter::getInstance($template_id, $app); $user_template = $app['manipulator.user']->getRepository()->find($template_id);
$base_ids = array_keys($app['acl']->get($user_template)->get_granted_base()); $base_ids = array_keys($app['acl']->get($user_template)->get_granted_base());
$app['acl']->get($user)->apply_model($user_template, $base_ids); $app['acl']->get($user)->apply_model($user_template, $base_ids);
@@ -507,7 +506,7 @@ class Users implements ControllerProviderInterface
$stmt->closeCursor(); $stmt->closeCursor();
foreach ($accept as $usr => $bases) { foreach ($accept as $usr => $bases) {
$user = \User_Adapter::getInstance($usr, $app); $user = $app['manipulator.user']->getRepository()->find($usr);
$cache_to_update[$usr] = true; $cache_to_update[$usr] = true;
foreach ($bases as $bas) { foreach ($bases as $bas) {
@@ -538,7 +537,7 @@ class Users implements ControllerProviderInterface
} }
foreach (array_keys($cache_to_update) as $usr_id) { foreach (array_keys($cache_to_update) as $usr_id) {
$user = \User_Adapter::getInstance($usr_id, $app); $user = $app['manipulator.user']->getRepository()->find($usr_id);
$app['acl']->get($user)->delete_data_from_cache(); $app['acl']->get($user)->delete_data_from_cache();
unset($user); unset($user);
} }
@@ -667,7 +666,7 @@ class Users implements ControllerProviderInterface
} elseif (in_array($loginToAdd, $loginNew)) { } elseif (in_array($loginToAdd, $loginNew)) {
$out['errors'][] = $app->trans("Login %login% is already defined in the file at line %line%", ['%login%' => $loginToAdd, '%line%' => $nbLine]); $out['errors'][] = $app->trans("Login %login% is already defined in the file at line %line%", ['%login%' => $loginToAdd, '%line%' => $nbLine]);
} else { } else {
if (\User_Adapter::get_usr_id_from_login($app, $loginToAdd)) { if (null !== $app['manipulator.user']->getRepository()->findByLogin($loginToAdd)) {
$out['errors'][] = $app->trans("Login %login% already exists in database", ['%login%' => $loginToAdd]); $out['errors'][] = $app->trans("Login %login% already exists in database", ['%login%' => $loginToAdd]);
} else { } else {
$loginValid = true; $loginValid = true;
@@ -680,7 +679,7 @@ class Users implements ControllerProviderInterface
if ($mailToAdd === "") { if ($mailToAdd === "") {
$out['errors'][] = $app->trans("Mail line %line% is empty", ['%line%' => $nbLine + 1]); $out['errors'][] = $app->trans("Mail line %line% is empty", ['%line%' => $nbLine + 1]);
} elseif (false !== \User_Adapter::get_usr_id_from_email($app, $mailToAdd)) { } elseif (null !== $app['manipulator.user']->getRepository()->findByEmail($mailToAdd)) {
$out['errors'][] = $app->trans("Email '%email%' for login '%login%' already exists in database", ['%email%' => $mailToAdd, '%login%' => $loginToAdd]); $out['errors'][] = $app->trans("Email '%email%' for login '%login%' already exists in database", ['%email%' => $mailToAdd, '%login%' => $loginToAdd]);
} else { } else {
$mailValid = true; $mailValid = true;
@@ -727,7 +726,7 @@ class Users implements ControllerProviderInterface
GROUP BY usr_id"; GROUP BY usr_id";
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $app['authentication']->getUser()->get_id()]); $stmt->execute(array(':usr_id' => $app['authentication']->getUser()->getId()));
$models = $stmt->fetchAll(\PDO::FETCH_ASSOC); $models = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -807,12 +806,13 @@ class Users implements ControllerProviderInterface
if (isset($curUser['usr_login']) && trim($curUser['usr_login']) !== '' if (isset($curUser['usr_login']) && trim($curUser['usr_login']) !== ''
&& isset($curUser['usr_password']) && trim($curUser['usr_password']) !== '' && isset($curUser['usr_password']) && trim($curUser['usr_password']) !== ''
&& isset($curUser['usr_mail']) && trim($curUser['usr_mail']) !== '') { && isset($curUser['usr_mail']) && trim($curUser['usr_mail']) !== '') {
if (false === \User_Adapter::get_usr_id_from_login($app, $curUser['usr_login']) if (null === $app['manipulator.user']->getRepository()->findByLogin($curUser['usr_login'])
&& false === \User_Adapter::get_usr_id_from_email($app, $curUser['usr_mail'])) { && false === $app['manipulator.user']->getRepository()->findByEmail($curUser['usr_mail'])) {
$NewUser = \User_Adapter::create($app, $curUser['usr_login'], $curUser['usr_password'], $curUser['usr_mail'], false);
$NewUser = $app['manipulator.user']->createUser($curUser['usr_login'], $curUser['usr_password'], $curUser['usr_mail']);
$ftpCredential = new FtpCredential(); $ftpCredential = new FtpCredential();
$ftpCredential->setUsrId($NewUser->get_id()); $ftpCredential->setUsrId($NewUser->getId());
if (isset($curUser['activeFTP'])) { if (isset($curUser['activeFTP'])) {
$ftpCredential->setActive((int) $curUser['activeFTP']); $ftpCredential->setActive((int) $curUser['activeFTP']);
@@ -830,38 +830,38 @@ class Users implements ControllerProviderInterface
$ftpCredential->setRepositoryPrefixName($curUser['prefixFTPfolder']); $ftpCredential->setRepositoryPrefixName($curUser['prefixFTPfolder']);
} }
if (isset($curUser['usr_prenom'])) { if (isset($curUser['usr_prenom'])) {
$NewUser->set_firstname($curUser['usr_prenom']); $NewUser->setFirstName($curUser['usr_prenom']);
} }
if (isset($curUser['usr_nom'])) { if (isset($curUser['usr_nom'])) {
$NewUser->set_lastname($curUser['usr_nom']); $NewUser->setLastName($curUser['usr_nom']);
} }
if (isset($curUser['adresse'])) { if (isset($curUser['adresse'])) {
$NewUser->set_address($curUser['adresse']); $NewUser->setAdress($curUser['adresse']);
} }
if (isset($curUser['cpostal'])) { if (isset($curUser['cpostal'])) {
$NewUser->set_zip($curUser['cpostal']); $NewUser->setZipCode($curUser['cpostal']);
} }
if (isset($curUser['usr_sexe'])) { if (isset($curUser['usr_sexe'])) {
$NewUser->set_gender((int) ($curUser['usr_sexe'])); $NewUser->setGender((int) ($curUser['usr_sexe']));
} }
if (isset($curUser['tel'])) { if (isset($curUser['tel'])) {
$NewUser->set_tel($curUser['tel']); $NewUser->setPhone($curUser['tel']);
} }
if (isset($curUser['fax'])) { if (isset($curUser['fax'])) {
$NewUser->set_fax($curUser['fax']); $NewUser->setFax($curUser['fax']);
} }
if (isset($curUser['activite'])) { if (isset($curUser['activite'])) {
$NewUser->set_job($curUser['activite']); $NewUser->setJob($curUser['activite']);
} }
if (isset($curUser['fonction'])) { if (isset($curUser['fonction'])) {
$NewUser->set_position($curUser['fonction']); $NewUser->setPosition($curUser['fonction']);
} }
if (isset($curUser['societe'])) { if (isset($curUser['societe'])) {
$NewUser->set_company($curUser['societe']); $NewUser->setCompany($curUser['societe']);
} }
$app['acl']->get($NewUser)->apply_model( $app['acl']->get($NewUser)->apply_model(
\User_Adapter::getInstance($model, $app), array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_base(['manage'])) $app['manipulator.user']->getRepository()->find($model), array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_base(array('manage')))
); );
$nbCreation++; $nbCreation++;

View File

@@ -91,7 +91,7 @@ class Oauth2 implements ControllerProviderInterface
return $app->redirectPath('oauth2_authorize', ['error' => 'account-locked']); return $app->redirectPath('oauth2_authorize', ['error' => 'account-locked']);
} }
$app['authentication']->openAccount(\User_Adapter::getInstance($usr_id, $app)); $app['authentication']->openAccount($app['manipulator.user']->getRepository()->find($usr_id));
} }
return new Response($app['twig']->render($template, ["auth" => $oauth2_adapter])); return new Response($app['twig']->render($template, ["auth" => $oauth2_adapter]));
@@ -109,7 +109,7 @@ class Oauth2 implements ControllerProviderInterface
} }
} }
$account = $oauth2_adapter->updateAccount($app['authentication']->getUser()->get_id()); $account = $oauth2_adapter->updateAccount($app['authentication']->getUser()->getId());
$params['account_id'] = $account->get_id(); $params['account_id'] = $account->get_id();

View File

@@ -82,7 +82,7 @@ class V1 implements ControllerProviderInterface
return; return;
} }
$user = \User_Adapter::getInstance($oauth2_adapter->get_usr_id(), $app); $user = $app['manipulator.user']->getRepository()->find($oauth2_adapter->get_usr_id());
$app['authentication']->openAccount($user); $app['authentication']->openAccount($user);
$oauth2_adapter->remember_this_ses_id($app['session']->get('session_id')); $oauth2_adapter->remember_this_ses_id($app['session']->get('session_id'));

View File

@@ -91,7 +91,7 @@ class Root implements ControllerProviderInterface
$result = $app['phraseanet.SE']->query($query, ($currentPage - 1) * $perPage, $perPage, $options); $result = $app['phraseanet.SE']->query($query, ($currentPage - 1) * $perPage, $perPage, $options);
$userQuery = new UserQuery(); $userQuery = new UserQuery();
$userQuery->setUsrId($app['authentication']->getUser()->get_id()); $userQuery->setUsrId($app['authentication']->getUser()->getId());
$userQuery->setQuery($query); $userQuery->setQuery($query);
$app['EM']->persist($userQuery); $app['EM']->persist($userQuery);
@@ -171,7 +171,7 @@ class Root implements ControllerProviderInterface
'per_page' => $perPage, 'per_page' => $perPage,
'search_engine' => $app['phraseanet.SE'], 'search_engine' => $app['phraseanet.SE'],
'search_engine_option' => $options->serialize(), 'search_engine_option' => $options->serialize(),
'history' => \queries::history($app, $app['authentication']->getUser()->get_id()), 'history' => \queries::history($app, $app['authentication']->getUser()->getId()),
'result' => $result, 'result' => $result,
'proposals' => $currentPage === 1 ? $result->getProposals() : null, 'proposals' => $currentPage === 1 ? $result->getProposals() : null,
'help' => count($resultData) === 0 ? $this->getHelpStartPage($app) : '', 'help' => count($resultData) === 0 ? $this->getHelpStartPage($app) : '',

View File

@@ -44,7 +44,7 @@ class Lightbox implements ControllerProviderInterface
return $app->redirectPath('homepage'); return $app->redirectPath('homepage');
} }
$app['authentication']->openAccount(\User_Adapter::getInstance($usr_id, $app)); $app['authentication']->openAccount($app['manipulator.user']->getRepository()->find($usr_id));
try { try {
$datas = $app['tokens']->helloToken($request->query->get('LOG')); $datas = $app['tokens']->helloToken($request->query->get('LOG'));
@@ -468,15 +468,15 @@ class Lightbox implements ControllerProviderInterface
$expires = new \DateTime('+10 days'); $expires = new \DateTime('+10 days');
$url = $app->url('lightbox', ['LOG' => $app['tokens']->getUrlToken( $url = $app->url('lightbox', ['LOG' => $app['tokens']->getUrlToken(
\random::TYPE_VALIDATE \random::TYPE_VALIDATE
, $basket->getValidation()->getInitiator($app)->get_id() , $basket->getValidation()->getInitiator($app)->getId()
, $expires , $expires
, $basket->getId() , $basket->getId()
)]); )]);
$to = $basket->getValidation()->getInitiator($app)->get_id(); $to = $basket->getValidation()->getInitiator($app)->getId();
$params = [ $params = [
'ssel_id' => $basket->getId(), 'ssel_id' => $basket->getId(),
'from' => $app['authentication']->getUser()->get_id(), 'from' => $app['authentication']->getUser()->getId(),
'url' => $url, 'url' => $url,
'to' => $to 'to' => $to
]; ];

View File

@@ -154,16 +154,14 @@ class Permalink extends AbstractDelivery
$watermark = $stamp = false; $watermark = $stamp = false;
if ($app['authentication']->isAuthenticated()) { if ($app['authentication']->isAuthenticated()) {
$user = \User_Adapter::getInstance($app['authentication']->getUser()->get_id(), $app); $watermark = !$app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'nowatermark');
$watermark = !$app['acl']->get($user)->has_right_on_base($record->get_base_id(), 'nowatermark');
if ($watermark) { if ($watermark) {
$repository = $app['EM']->getRepository('Phraseanet:BasketElement'); $repository = $app['EM']->getRepository('Phraseanet:BasketElement');
if (count($repository->findReceivedValidationElementsByRecord($record, $user)) > 0) { if (count($repository->findReceivedValidationElementsByRecord($record, $app['authentication']->getUser())) > 0) {
$watermark = false; $watermark = false;
} elseif (count($repository->findReceivedElementsByRecord($record, $user)) > 0) { } elseif (count($repository->findReceivedElementsByRecord($record, $app['authentication']->getUser())) > 0) {
$watermark = false; $watermark = false;
} }
} }

View File

@@ -173,7 +173,7 @@ class Bridge implements ControllerProviderInterface
try { try {
$account = \Bridge_Account::load_account($app, $account_id); $account = \Bridge_Account::load_account($app, $account_id);
if ($account->get_user()->get_id() !== $app['authentication']->getUser()->get_id()) { if ($account->get_user()->getId() !== $app['authentication']->getUser()->getId()) {
throw new HttpException(403, 'Access forbiden'); throw new HttpException(403, 'Access forbiden');
} }

View File

@@ -66,7 +66,7 @@ class Download implements ControllerProviderInterface
$token = $app['tokens']->getUrlToken( $token = $app['tokens']->getUrlToken(
\random::TYPE_DOWNLOAD, \random::TYPE_DOWNLOAD,
$app['authentication']->getUser()->get_id(), $app['authentication']->getUser()->getId(),
new \DateTime('+3 hours'), // Token lifetime new \DateTime('+3 hours'), // Token lifetime
serialize($list) serialize($list)
); );
@@ -77,7 +77,7 @@ class Download implements ControllerProviderInterface
$app['events-manager']->trigger('__DOWNLOAD__', [ $app['events-manager']->trigger('__DOWNLOAD__', [
'lst' => $lst, 'lst' => $lst,
'downloader' => $app['authentication']->getUser()->get_id(), 'downloader' => $app['authentication']->getUser()->getId(),
'subdefs' => $subdefs, 'subdefs' => $subdefs,
'from_basket' => $ssttid, 'from_basket' => $ssttid,
'export_file' => $download->getExportName() 'export_file' => $download->getExportName()

View File

@@ -206,7 +206,7 @@ class Export implements ControllerProviderInterface
$destMails[] = $mail; $destMails[] = $mail;
} else { } else {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', [ $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', [
'usr_id' => $app['authentication']->getUser()->get_id(), 'usr_id' => $app['authentication']->getUser()->getId(),
'lst' => $lst, 'lst' => $lst,
'ssttid' => $ssttid, 'ssttid' => $ssttid,
'dest' => $mail, 'dest' => $mail,
@@ -232,7 +232,7 @@ class Export implements ControllerProviderInterface
$url = $app->url('prepare_download', ['token' => $token, 'anonymous']); $url = $app->url('prepare_download', ['token' => $token, 'anonymous']);
$emitter = new Emitter($app['authentication']->getUser()->get_display_name(), $app['authentication']->getUser()->get_email()); $emitter = new Emitter($app['authentication']->getUser()->getDisplayName(), $app['authentication']->getUser()->getEmail());
foreach ($destMails as $key => $mail) { foreach ($destMails as $key => $mail) {
try { try {
@@ -253,7 +253,7 @@ class Export implements ControllerProviderInterface
if (count($remaingEmails) > 0) { if (count($remaingEmails) > 0) {
foreach ($remaingEmails as $mail) { foreach ($remaingEmails as $mail) {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', [ $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', [
'usr_id' => $app['authentication']->getUser()->get_id(), 'usr_id' => $app['authentication']->getUser()->getId(),
'lst' => $lst, 'lst' => $lst,
'ssttid' => $ssttid, 'ssttid' => $ssttid,
'dest' => $mail, 'dest' => $mail,
@@ -264,7 +264,7 @@ class Export implements ControllerProviderInterface
} elseif (!$token && count($destMails) > 0) { //couldn't generate token } elseif (!$token && count($destMails) > 0) { //couldn't generate token
foreach ($destMails as $mail) { foreach ($destMails as $mail) {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', [ $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', [
'usr_id' => $app['authentication']->getUser()->get_id(), 'usr_id' => $app['authentication']->getUser()->getId(),
'lst' => $lst, 'lst' => $lst,
'ssttid' => $ssttid, 'ssttid' => $ssttid,
'dest' => $mail, 'dest' => $mail,

View File

@@ -49,7 +49,7 @@ class Feed implements ControllerProviderInterface
$app->abort(404, "Feed not found"); $app->abort(404, "Feed not found");
} }
$publisher = $app['EM']->getRepository('Phraseanet:FeedPublisher')->findOneBy(['feed' => $feed, 'usrId' => $app['authentication']->getUser()->get_id()]); $publisher = $app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\FeedPublisher')->findOneBy(array('feed' => $feed, 'usrId' => $app['authentication']->getUser()->getId()));
if ('' === $title = trim($request->request->get('title', ''))) { if ('' === $title = trim($request->request->get('title', ''))) {
$app->abort(400, "Bad request"); $app->abort(400, "Bad request");

View File

@@ -94,7 +94,7 @@ class Order implements ControllerProviderInterface
if (!$records->isEmpty()) { if (!$records->isEmpty()) {
$order = new OrderEntity(); $order = new OrderEntity();
$order->setUsrId($app['authentication']->getUser()->get_id()); $order->setUsrId($app['authentication']->getUser()->getId());
$order->setDeadline((null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine); $order->setDeadline((null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine);
$order->setOrderUsage($request->request->get('use', '')); $order->setOrderUsage($request->request->get('use', ''));
foreach ($records as $key => $record) { foreach ($records as $key => $record) {
@@ -242,7 +242,7 @@ class Order implements ControllerProviderInterface
throw new NotFoundHttpException('Order not found'); throw new NotFoundHttpException('Order not found');
} }
$dest_user = \User_Adapter::getInstance($order->getUsrId(), $app); $dest_user = $app['manipulator.user']->getRepository()->find($order->getUsrId());
$basket = $order->getBasket(); $basket = $order->getBasket();
@@ -267,7 +267,7 @@ class Order implements ControllerProviderInterface
$basketElement->setRecord($record); $basketElement->setRecord($record);
$basketElement->setBasket($basket); $basketElement->setBasket($basket);
$orderElement->setOrderMasterId($app['authentication']->getUser()->get_id()); $orderElement->setOrderMasterId($app['authentication']->getUser()->getId());
$orderElement->setDeny(false); $orderElement->setDeny(false);
$orderElement->getOrder()->setBasket($basket); $orderElement->getOrder()->setBasket($basket);
@@ -284,8 +284,8 @@ class Order implements ControllerProviderInterface
$app['events-manager']->trigger('__ORDER_DELIVER__', [ $app['events-manager']->trigger('__ORDER_DELIVER__', [
'ssel_id' => $order->getBasket()->getId(), 'ssel_id' => $order->getBasket()->getId(),
'from' => $app['authentication']->getUser()->get_id(), 'from' => $app['authentication']->getUser()->getId(),
'to' => $dest_user->get_id(), 'to' => $dest_user->getId(),
'n' => $n 'n' => $n
]); ]);
} }
@@ -333,7 +333,7 @@ class Order implements ControllerProviderInterface
$elements = $request->request->get('elements', []); $elements = $request->request->get('elements', []);
foreach ($order->getElements() as $orderElement) { foreach ($order->getElements() as $orderElement) {
if (in_array($orderElement->getId(),$elements)) { if (in_array($orderElement->getId(),$elements)) {
$orderElement->setOrderMasterId($app['authentication']->getUser()->get_id()); $orderElement->setOrderMasterId($app['authentication']->getUser()->getId());
$orderElement->setDeny(true); $orderElement->setDeny(true);
$app['EM']->persist($orderElement); $app['EM']->persist($orderElement);
@@ -346,7 +346,7 @@ class Order implements ControllerProviderInterface
$order->setTodo($order->getTodo() - $n); $order->setTodo($order->getTodo() - $n);
$app['events-manager']->trigger('__ORDER_NOT_DELIVERED__', [ $app['events-manager']->trigger('__ORDER_NOT_DELIVERED__', [
'from' => $app['authentication']->getUser()->get_id(), 'from' => $app['authentication']->getUser()->getId(),
'to' => $order->getUsrId(), 'to' => $order->getUsrId(),
'n' => $n 'n' => $n
]); ]);

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\Basket;
use Alchemy\Phrasea\Model\Entities\BasketElement; use Alchemy\Phrasea\Model\Entities\BasketElement;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Entities\UsrList; use Alchemy\Phrasea\Model\Entities\UsrList;
use Alchemy\Phrasea\Model\Entities\UsrListEntry; use Alchemy\Phrasea\Model\Entities\UsrListEntry;
use Alchemy\Phrasea\Model\Entities\ValidationSession; use Alchemy\Phrasea\Model\Entities\ValidationSession;
@@ -30,16 +31,16 @@ class Push implements ControllerProviderInterface
{ {
protected function getUserFormatter() protected function getUserFormatter()
{ {
return function (\User_Adapter $user) { return function (User $user) {
$subtitle = array_filter([$user->get_job(), $user->get_company()]); $subtitle = array_filter(array($user->getJob(), $user->getCompany()));
return [ return [
'type' => 'USER' 'type' => 'USER'
, 'usr_id' => $user->get_id() , 'usr_id' => $user->getId()
, 'firstname' => $user->get_firstname() , 'firstname' => $user->getFirstName()
, 'lastname' => $user->get_lastname() , 'lastname' => $user->getLastName()
, 'email' => $user->get_email() , 'email' => $user->getEmail()
, 'display_name' => $user->get_display_name() , 'display_name' => $user->getDisplayName()
, 'subtitle' => implode(', ', $subtitle) , 'subtitle' => implode(', ', $subtitle)
]; ];
}; };
@@ -87,7 +88,7 @@ class Push implements ControllerProviderInterface
$user = $value->getRessource(); $user = $value->getRessource();
$Users->set($user->get_id(), $user); $Users->set($user->getId(), $user);
} }
} }
} }
@@ -161,7 +162,7 @@ class Push implements ControllerProviderInterface
try { try {
$pusher = new RecordHelper\Push($app, $app['request']); $pusher = new RecordHelper\Push($app, $app['request']);
$push_name = $request->request->get('name', $app->trans('Push from %user%', ['%user%' => $app['authentication']->getUser()->get_display_name()])); $push_name = $request->request->get('name', $app->trans('Push from %user%', ['%user%' => $app['authentication']->getUser()->getDisplayName()]));
$push_description = $request->request->get('push_description'); $push_description = $request->request->get('push_description');
$receivers = $request->request->get('participants'); $receivers = $request->request->get('participants');
@@ -176,7 +177,7 @@ class Push implements ControllerProviderInterface
foreach ($receivers as $receiver) { foreach ($receivers as $receiver) {
try { try {
$user_receiver = \User_Adapter::getInstance($receiver['usr_id'], $app); $user_receiver = $app['manipulator.user']->getRepository()->find($receiver['usr_id']);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new ControllerException($app->trans('Unknown user %user_id%', ['%user_id%' => $receiver['usr_id']])); throw new ControllerException($app->trans('Unknown user %user_id%', ['%user_id%' => $receiver['usr_id']]));
} }
@@ -220,15 +221,15 @@ class Push implements ControllerProviderInterface
'basket' => $Basket->getId(), 'basket' => $Basket->getId(),
'LOG' => $app['tokens']->getUrlToken( 'LOG' => $app['tokens']->getUrlToken(
\random::TYPE_VIEW, \random::TYPE_VIEW,
$user_receiver->get_id(), $user_receiver->getId(),
null, null,
$Basket->getId() $Basket->getId()
) )
]); ]);
$receipt = $request->get('recept') ? $app['authentication']->getUser()->get_email() : ''; $receipt = $request->get('recept') ? $app['authentication']->getUser()->getEmail() : '';
$params = [ $params = array(
'from' => $app['authentication']->getUser()->get_id() 'from' => $app['authentication']->getUser()->get_id()
, 'from_email' => $app['authentication']->getUser()->get_email() , 'from_email' => $app['authentication']->getUser()->get_email()
, 'to' => $user_receiver->get_id() , 'to' => $user_receiver->get_id()
@@ -244,7 +245,7 @@ class Push implements ControllerProviderInterface
} }
$app['phraseanet.logger']($BasketElement->getRecord($app)->get_databox()) $app['phraseanet.logger']($BasketElement->getRecord($app)->get_databox())
->log($BasketElement->getRecord($app), \Session_Logger::EVENT_VALIDATE, $user_receiver->get_id(), ''); ->log($BasketElement->getRecord($app), \Session_Logger::EVENT_VALIDATE, $user_receiver->getId(), '');
$app['EM']->flush(); $app['EM']->flush();
@@ -279,7 +280,7 @@ class Push implements ControllerProviderInterface
$repository = $app['EM']->getRepository('Phraseanet:Basket'); $repository = $app['EM']->getRepository('Phraseanet:Basket');
$validation_name = $request->request->get('name', $app->trans('Validation from %user%', ['%user%' => $app['authentication']->getUser()->get_display_name()])); $validation_name = $request->request->get('name', $app->trans('Validation from %user%', ['%user%' => $app['authentication']->getUser()->getDisplayName()]));
$validation_description = $request->request->get('validation_description'); $validation_description = $request->request->get('validation_description');
$participants = $request->request->get('participants'); $participants = $request->request->get('participants');
@@ -337,16 +338,16 @@ class Push implements ControllerProviderInterface
$found = false; $found = false;
foreach ($participants as $key => $participant) { foreach ($participants as $key => $participant) {
if ($participant['usr_id'] == $app['authentication']->getUser()->get_id()) { if ($participant['usr_id'] == $app['authentication']->getUser()->getId()) {
$found = true; $found = true;
break; break;
} }
} }
if (!$found) { if (!$found) {
$participants[$app['authentication']->getUser()->get_id()] = [ $participants[$app['authentication']->getUser()->get_id()] = array(
'see_others' => 1, 'see_others' => 1,
'usr_id' => $app['authentication']->getUser()->get_id(), 'usr_id' => $app['authentication']->getUser()->getId(),
'agree' => 0, 'agree' => 0,
'HD' => 0 'HD' => 0
]; ];
@@ -359,7 +360,7 @@ class Push implements ControllerProviderInterface
} }
try { try {
$participant_user = \User_Adapter::getInstance($participant['usr_id'], $app); $participant_user = $app['manipulator.user']->getRepository()->find($participant['usr_id']);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new ControllerException($app->trans('Unknown user %usr_id%', ['%usr_id%' => $participant['usr_id']])); throw new ControllerException($app->trans('Unknown user %usr_id%', ['%usr_id%' => $participant['usr_id']]));
} }
@@ -404,7 +405,7 @@ class Push implements ControllerProviderInterface
$app['EM']->persist($ValidationData); $app['EM']->persist($ValidationData);
$app['phraseanet.logger']($BasketElement->getRecord($app)->get_databox()) $app['phraseanet.logger']($BasketElement->getRecord($app)->get_databox())
->log($BasketElement->getRecord($app), \Session_Logger::EVENT_PUSH, $participant_user->get_id(), ''); ->log($BasketElement->getRecord($app), \Session_Logger::EVENT_PUSH, $participant_user->getId(), '');
$Participant->addData($ValidationData); $Participant->addData($ValidationData);
} }
@@ -417,15 +418,15 @@ class Push implements ControllerProviderInterface
'basket' => $Basket->getId(), 'basket' => $Basket->getId(),
'LOG' => $app['tokens']->getUrlToken( 'LOG' => $app['tokens']->getUrlToken(
\random::TYPE_VALIDATE, \random::TYPE_VALIDATE,
$participant_user->get_id(), $participant_user->getId(),
null, null,
$Basket->getId() $Basket->getId()
) )
]); ]);
$receipt = $request->get('recept') ? $app['authentication']->getUser()->get_email() : ''; $receipt = $request->get('recept') ? $app['authentication']->getUser()->getEmail() : '';
$params = [ $params = array(
'from' => $app['authentication']->getUser()->get_id(), 'from' => $app['authentication']->getUser()->get_id(),
'from_email' => $app['authentication']->getUser()->get_email(), 'from_email' => $app['authentication']->getUser()->get_email(),
'to' => $participant_user->get_id(), 'to' => $participant_user->get_id(),
@@ -533,8 +534,7 @@ class Push implements ControllerProviderInterface
$email = $request->request->get('email'); $email = $request->request->get('email');
try { try {
$usr_id = \User_Adapter::get_usr_id_from_email($app, $email); $user = $app['manipulator.user']->getRepository()->findByEmail($email);
$user = \User_Adapter::getInstance($usr_id, $app);
$result['message'] = $app->trans('User already exists'); $result['message'] = $app->trans('User already exists');
$result['success'] = true; $result['success'] = true;
@@ -543,11 +543,11 @@ class Push implements ControllerProviderInterface
} }
if (!$user instanceof \User_Adapter) { if (!$user instanceof User) {
try { try {
$password = \random::generatePassword(); $password = \random::generatePassword();
$user = \User_Adapter::create($app, $email, $password, $email, false); $user = $app['manipulator.user']->getRepository()->createUser($email, $password, $email);
$user->set_firstname($request->request->get('firstname')) $user->set_firstname($request->request->get('firstname'))
->set_lastname($request->request->get('lastname')); ->set_lastname($request->request->get('lastname'));

View File

@@ -73,7 +73,7 @@ class Query implements ControllerProviderInterface
$result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage, $options); $result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage, $options);
$userQuery = new UserQuery(); $userQuery = new UserQuery();
$userQuery->setUsrId($app['authentication']->getUser()->get_id()); $userQuery->setUsrId($app['authentication']->getUser()->getId());
$userQuery->setQuery($result->getQuery()); $userQuery->setQuery($result->getQuery());
$app['EM']->persist($userQuery); $app['EM']->persist($userQuery);

View File

@@ -119,7 +119,7 @@ class Root implements ControllerProviderInterface
'GV_google_api' => $app['conf']->get(['registry', 'webservices', 'google-charts-enabled']), 'GV_google_api' => $app['conf']->get(['registry', 'webservices', 'google-charts-enabled']),
'queries_topics' => $queries_topics, 'queries_topics' => $queries_topics,
'search_status' => \databox_status::getSearchStatus($app), 'search_status' => \databox_status::getSearchStatus($app),
'queries_history' => \queries::history($app, $app['authentication']->getUser()->get_id()), 'queries_history' => \queries::history($app, $app['authentication']->getUser()->getId()),
'thesau_js_list' => $thjslist, 'thesau_js_list' => $thjslist,
'thesau_json_sbas' => json_encode($sbas), 'thesau_json_sbas' => json_encode($sbas),
'thesau_json_bas2sbas' => json_encode($bas2sbas), 'thesau_json_bas2sbas' => json_encode($bas2sbas),

View File

@@ -89,7 +89,7 @@ class Tooltip implements ControllerProviderInterface
public function displayUserBadge(Application $app, $usr_id) public function displayUserBadge(Application $app, $usr_id)
{ {
$user = \User_Adapter::getInstance($usr_id, $app); $user = $app['manipulator.user']->getRepository()->find($usr_id);
return $app['twig']->render( return $app['twig']->render(
'prod/Tooltip/User.html.twig' 'prod/Tooltip/User.html.twig'

View File

@@ -158,7 +158,7 @@ class Upload implements ControllerProviderInterface
$collection = \collection::get_from_base_id($app, $base_id); $collection = \collection::get_from_base_id($app, $base_id);
$lazaretSession = new LazaretSession(); $lazaretSession = new LazaretSession();
$lazaretSession->setUsrId($app['authentication']->getUser()->get_id()); $lazaretSession->setUsrId($app['authentication']->getUser()->getId());
$app['EM']->persist($lazaretSession); $app['EM']->persist($lazaretSession);

View File

@@ -90,26 +90,26 @@ class UsrLists implements ControllerProviderInterface
$owners = $entries = []; $owners = $entries = [];
foreach ($list->getOwners() as $owner) { foreach ($list->getOwners() as $owner) {
$owners[] = [ $owners[] = array(
'usr_id' => $owner->getUser($app)->get_id(), 'usr_id' => $owner->getUser($app)->getId(),
'display_name' => $owner->getUser($app)->get_display_name(), 'display_name' => $owner->getUser($app)->getDisplayName(),
'position' => $owner->getUser($app)->get_position(), 'position' => $owner->getUser($app)->getActivity(),
'job' => $owner->getUser($app)->get_job(), 'job' => $owner->getUser($app)->getJob(),
'company' => $owner->getUser($app)->get_company(), 'company' => $owner->getUser($app)->getCompany(),
'email' => $owner->getUser($app)->get_email(), 'email' => $owner->getUser($app)->getEmail(),
'role' => $owner->getRole() 'role' => $owner->getRole()
]; );
} }
foreach ($list->getEntries() as $entry) { foreach ($list->getEntries() as $entry) {
$entries[] = [ $entries[] = array(
'usr_id' => $owner->getUser($app)->get_id(), 'usr_id' => $owner->getUser($app)->getId(),
'display_name' => $owner->getUser($app)->get_display_name(), 'display_name' => $owner->getUser($app)->getDisplayName(),
'position' => $owner->getUser($app)->get_position(), 'position' => $owner->getUser($app)->getActivity(),
'job' => $owner->getUser($app)->get_job(), 'job' => $owner->getUser($app)->getJob(),
'company' => $owner->getUser($app)->get_company(), 'company' => $owner->getUser($app)->getCompany(),
'email' => $owner->getUser($app)->get_email(), 'email' => $owner->getUser($app)->getEmail(),
]; );
} }
/* @var $list UsrList */ /* @var $list UsrList */
@@ -201,26 +201,26 @@ class UsrLists implements ControllerProviderInterface
$owners = new ArrayCollection(); $owners = new ArrayCollection();
foreach ($list->getOwners() as $owner) { foreach ($list->getOwners() as $owner) {
$owners[] = [ $owners[] = array(
'usr_id' => $owner->getUser($app)->get_id(), 'usr_id' => $owner->getUser($app)->getId(),
'display_name' => $owner->getUser($app)->get_display_name(), 'display_name' => $owner->getUser($app)->getDisplayName(),
'position' => $owner->getUser($app)->get_position(), 'position' => $owner->getUser($app)->getActivity(),
'job' => $owner->getUser($app)->get_job(), 'job' => $owner->getUser($app)->getJob(),
'company' => $owner->getUser($app)->get_company(), 'company' => $owner->getUser($app)->getCompany(),
'email' => $owner->getUser($app)->get_email(), 'email' => $owner->getUser($app)->getEmail(),
'role' => $owner->getRole($app) 'role' => $owner->getRole($app)
]; );
} }
foreach ($list->getEntries() as $entry) { foreach ($list->getEntries() as $entry) {
$entries[] = [ $entries[] = array(
'usr_id' => $entry->getUser($app)->get_id(), 'usr_id' => $entry->getUser($app)->getId(),
'display_name' => $entry->getUser($app)->get_display_name(), 'display_name' => $entry->getUser($app)->getDisplayName(),
'position' => $entry->getUser($app)->get_position(), 'position' => $entry->getUser($app)->getActivity(),
'job' => $entry->getUser($app)->get_job(), 'job' => $entry->getUser($app)->getJob(),
'company' => $entry->getUser($app)->get_company(), 'company' => $entry->getUser($app)->getCompany(),
'email' => $entry->getUser($app)->get_email(), 'email' => $entry->getUser($app)->getEmail(),
]; );
} }
return $app->json([ return $app->json([
@@ -370,7 +370,7 @@ class UsrLists implements ControllerProviderInterface
$inserted_usr_ids = []; $inserted_usr_ids = [];
foreach ($request->request->get('usr_ids') as $usr_id) { foreach ($request->request->get('usr_ids') as $usr_id) {
$user_entry = \User_Adapter::getInstance($usr_id, $app); $user_entry = $app['manipulator.user']->getRepository()->find($usr_id);
if ($list->has($user_entry, $app)) if ($list->has($user_entry, $app))
continue; continue;
@@ -383,7 +383,7 @@ class UsrLists implements ControllerProviderInterface
$app['EM']->persist($entry); $app['EM']->persist($entry);
$inserted_usr_ids[] = $user_entry->get_id(); $inserted_usr_ids[] = $user_entry->getId();
} }
$app['EM']->flush(); $app['EM']->flush();
@@ -461,10 +461,10 @@ class UsrLists implements ControllerProviderInterface
throw new ControllerException($app->trans('You are not authorized to do this')); throw new ControllerException($app->trans('You are not authorized to do this'));
} }
$new_owner = \User_Adapter::getInstance($usr_id, $app); $new_owner = $app['manipulator.user']->getRepository()->find($usr_id);
if ($list->hasAccess($new_owner, $app)) { if ($list->hasAccess($new_owner, $app)) {
if ($new_owner->get_id() == $app['authentication']->getUser()->get_id()) { if ($new_owner->getId() == $app['authentication']->getUser()->getId()) {
throw new ControllerException('You can not downgrade your Admin right'); throw new ControllerException('You can not downgrade your Admin right');
} }

View File

@@ -93,7 +93,7 @@ class Account implements ControllerProviderInterface
$data = $form->getData(); $data = $form->getData();
$user = $app['authentication']->getUser(); $user = $app['authentication']->getUser();
if ($app['auth.password-encoder']->isPasswordValid($user->get_password(), $data['oldPassword'], $user->get_nonce())) { if ($app['auth.password-encoder']->isPasswordValid($user->getPassword(), $data['oldPassword'], $user->getNonce())) {
$user->set_password($data['password']); $user->set_password($data['password']);
$app->addFlash('success', $app->trans('login::notification: Mise a jour du mot de passe avec succes')); $app->addFlash('success', $app->trans('login::notification: Mise a jour du mot de passe avec succes'));
@@ -126,7 +126,7 @@ class Account implements ControllerProviderInterface
$user = $app['authentication']->getUser(); $user = $app['authentication']->getUser();
if (!$app['auth.password-encoder']->isPasswordValid($user->get_password(), $password, $user->get_nonce())) { if (!$app['auth.password-encoder']->isPasswordValid($user->getPassword(), $password, $user->getNonce())) {
$app->addFlash('error', $app->trans('admin::compte-utilisateur:ftp: Le mot de passe est errone')); $app->addFlash('error', $app->trans('admin::compte-utilisateur:ftp: Le mot de passe est errone'));
return $app->redirectPath('account_reset_email'); return $app->redirectPath('account_reset_email');
@@ -145,8 +145,8 @@ class Account implements ControllerProviderInterface
} }
$date = new \DateTime('1 day'); $date = new \DateTime('1 day');
$token = $app['tokens']->getUrlToken(\random::TYPE_EMAIL, $app['authentication']->getUser()->get_id(), $date, $app['authentication']->getUser()->get_email()); $token = $app['tokens']->getUrlToken(\random::TYPE_EMAIL, $app['authentication']->getUser()->getId(), $date, $app['authentication']->getUser()->getEmail());
$url = $app->url('account_reset_email', ['token' => $token]); $url = $app->url('account_reset_email', array('token' => $token));
try { try {
$receiver = Receiver::fromUser($app['authentication']->getUser()); $receiver = Receiver::fromUser($app['authentication']->getUser());
@@ -179,7 +179,7 @@ class Account implements ControllerProviderInterface
if (null !== $token = $request->query->get('token')) { if (null !== $token = $request->query->get('token')) {
try { try {
$datas = $app['tokens']->helloToken($token); $datas = $app['tokens']->helloToken($token);
$user = \User_Adapter::getInstance((int) $datas['usr_id'], $app); $user = $app['manipulator.user']->getRepository()->find((int) $datas['usr_id']);
$user->set_email($datas['datas']); $user->set_email($datas['datas']);
$app['tokens']->removeToken($token); $app['tokens']->removeToken($token);
@@ -239,9 +239,9 @@ class Account implements ControllerProviderInterface
{ {
require_once $app['root.path'] . '/lib/classes/deprecated/inscript.api.php'; require_once $app['root.path'] . '/lib/classes/deprecated/inscript.api.php';
return $app['twig']->render('account/access.html.twig', [ return $app['twig']->render('account/access.html.twig', array(
'inscriptions' => giveMeBases($app, $app['authentication']->getUser()->get_id()) 'inscriptions' => giveMeBases($app, $app['authentication']->getUser()->getId())
]); ));
} }
/** /**
@@ -318,11 +318,11 @@ class Account implements ControllerProviderInterface
*/ */
public function displayAccount(Application $app, Request $request) public function displayAccount(Application $app, Request $request)
{ {
return $app['twig']->render('account/account.html.twig', [ return $app['twig']->render('account/account.html.twig', array(
'user' => $app['authentication']->getUser(), 'user' => $app['authentication']->getUser(),
'evt_mngr' => $app['events-manager'], 'evt_mngr' => $app['events-manager'],
'notifications' => $app['events-manager']->list_notifications_available($app['authentication']->getUser()->get_id()), 'notifications' => $app['events-manager']->list_notifications_available($app['authentication']->getUser()->getId()),
]); ));
} }
/** /**
@@ -410,7 +410,7 @@ class Account implements ControllerProviderInterface
$requestedNotifications = (array) $request->request->get('notifications', []); $requestedNotifications = (array) $request->request->get('notifications', []);
foreach ($app['events-manager']->list_notifications_available($app['authentication']->getUser()->get_id()) as $notifications) { foreach ($app['events-manager']->list_notifications_available($app['authentication']->getUser()->getId()) as $notifications) {
foreach ($notifications as $notification) { foreach ($notifications as $notification) {
if (isset($requestedNotifications[$notification['id']])) { if (isset($requestedNotifications[$notification['id']])) {
$app['authentication']->getUser()->set_notification_preference($app, $notification['id'], '1'); $app['authentication']->getUser()->set_notification_preference($app, $notification['id'], '1');

View File

@@ -23,6 +23,7 @@ use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\FormProcessingException; use Alchemy\Phrasea\Exception\FormProcessingException;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Entities\ValidationParticipant; use Alchemy\Phrasea\Model\Entities\ValidationParticipant;
use Alchemy\Phrasea\Model\Entities\UsrAuthProvider; use Alchemy\Phrasea\Model\Entities\UsrAuthProvider;
use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Receiver;
@@ -362,7 +363,7 @@ class Login implements ControllerProviderInterface
$data['login'] = $data['email']; $data['login'] = $data['email'];
} }
$user = \User_Adapter::create($app, $data['login'], $data['password'], $data['email'], false); $user = $app['manipulator.user']->createUser($data['login'], $data['password'], $data['email'], false);
foreach ([ foreach ([
'gender' => 'set_gender', 'gender' => 'set_gender',
@@ -391,11 +392,9 @@ class Login implements ControllerProviderInterface
if ($app['conf']->get(['registry', 'registration', 'auto-register-enabled'])) { if ($app['conf']->get(['registry', 'registration', 'auto-register-enabled'])) {
$template_user_id = \User_Adapter::get_usr_id_from_login($app, 'autoregister'); $template_user = $app['manipulator.user']->getRepository()->findbyLogin('autoregister');
$template_user = \User_Adapter::getInstance($template_user_id, $app); $base_ids = array();
$base_ids = [];
foreach (array_keys($inscOK) as $base_id) { foreach (array_keys($inscOK) as $base_id) {
$base_ids[] = $base_id; $base_ids[] = $base_id;
@@ -417,11 +416,11 @@ class Login implements ControllerProviderInterface
$demandOK[$base_id] = true; $demandOK[$base_id] = true;
} }
$params = [ $params = array(
'demand' => $demandOK, 'demand' => $demandOK,
'autoregister' => $autoReg, 'autoregister' => $autoReg,
'usr_id' => $user->get_id() 'usr_id' => $user->getId()
]; );
$app['events-manager']->trigger('__REGISTER_AUTOREGISTER__', $params); $app['events-manager']->trigger('__REGISTER_AUTOREGISTER__', $params);
$app['events-manager']->trigger('__REGISTER_APPROVAL__', $params); $app['events-manager']->trigger('__REGISTER_APPROVAL__', $params);
@@ -462,12 +461,12 @@ class Login implements ControllerProviderInterface
])); ]));
} }
private function attachProviderToUser(EntityManager $em, ProviderInterface $provider, \User_Adapter $user) private function attachProviderToUser(EntityManager $em, ProviderInterface $provider, User $user)
{ {
$usrAuthProvider = new UsrAuthProvider(); $usrAuthProvider = new UsrAuthProvider();
$usrAuthProvider->setDistantId($provider->getToken()->getId()); $usrAuthProvider->setDistantId($provider->getToken()->getId());
$usrAuthProvider->setProvider($provider->getId()); $usrAuthProvider->setProvider($provider->getId());
$usrAuthProvider->setUsrId($user->get_id()); $usrAuthProvider->setUsrId($user->getId());
try { try {
$provider->logout(); $provider->logout();
@@ -492,7 +491,7 @@ class Login implements ControllerProviderInterface
} }
try { try {
$user = \User_Adapter::getInstance((int) $usrId, $app); $user = $app['manipulator.user']->getRepository()->find((int) $usrId);
} catch (\Exception $e) { } catch (\Exception $e) {
$app->addFlash('error', $app->trans('Invalid link.')); $app->addFlash('error', $app->trans('Invalid link.'));
@@ -514,17 +513,17 @@ class Login implements ControllerProviderInterface
* Sends an account unlock email. * Sends an account unlock email.
* *
* @param PhraseaApplication $app * @param PhraseaApplication $app
* @param \User_Adapter $user * @param User $user
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @throws RuntimeException * @throws RuntimeException
*/ */
private function sendAccountUnlockEmail(PhraseaApplication $app, \User_Adapter $user) private function sendAccountUnlockEmail(PhraseaApplication $app, User $user)
{ {
$receiver = Receiver::fromUser($user); $receiver = Receiver::fromUser($user);
$expire = new \DateTime('+3 days'); $expire = new \DateTime('+3 days');
$token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->get_id(), $expire, $user->get_email()); $token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->getId(), $expire, $user->getEmail());
$mail = MailRequestEmailConfirmation::create($app, $receiver); $mail = MailRequestEmailConfirmation::create($app, $receiver);
$mail->setButtonUrl($app->url('login_register_confirm', ['code' => $token])); $mail->setButtonUrl($app->url('login_register_confirm', ['code' => $token]));
@@ -557,14 +556,14 @@ class Login implements ControllerProviderInterface
} }
try { try {
$user = \User_Adapter::getInstance((int) $datas['usr_id'], $app); $user = $app['manipulator.user']->getRepository()->find((int) $datas['usr_id']);
} catch (\Exception $e) { } catch (\Exception $e) {
$app->addFlash('error', $app->trans('Invalid unlock link.')); $app->addFlash('error', $app->trans('Invalid unlock link.'));
return $app->redirectPath('homepage'); return $app->redirectPath('homepage');
} }
if (!$user->get_mail_locked()) { if (!$user->isMailLocked()) {
$app->addFlash('info', $app->trans('Account is already unlocked, you can login.')); $app->addFlash('info', $app->trans('Account is already unlocked, you can login.'));
return $app->redirectPath('homepage'); return $app->redirectPath('homepage');
@@ -621,7 +620,7 @@ class Login implements ControllerProviderInterface
$datas = $app['tokens']->helloToken($token); $datas = $app['tokens']->helloToken($token);
$user = \User_Adapter::getInstance($datas['usr_id'], $app); $user = $app['manipulator.user']->getRepository()->find($datas['usr_id']);
$user->set_password($data['password']); $user->set_password($data['password']);
$app['tokens']->removeToken($token); $app['tokens']->removeToken($token);
@@ -660,7 +659,7 @@ class Login implements ControllerProviderInterface
$data = $form->getData(); $data = $form->getData();
try { try {
$user = \User_Adapter::getInstance(\User_Adapter::get_usr_id_from_email($app, $data['email']), $app); $user = $app['manipulator.user']->getRepository()->findByEmail($data['email']);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new FormProcessingException($app->trans('phraseanet::erreur: Le compte n\'a pas ete trouve')); throw new FormProcessingException($app->trans('phraseanet::erreur: Le compte n\'a pas ete trouve'));
} }
@@ -671,7 +670,7 @@ class Login implements ControllerProviderInterface
throw new FormProcessingException($app->trans('Invalid email address')); throw new FormProcessingException($app->trans('Invalid email address'));
} }
$token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->get_id(), new \DateTime('+1 day')); $token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->getId(), new \DateTime('+1 day'));
if (!$token) { if (!$token) {
return $app->abort(500, 'Unable to generate a token'); return $app->abort(500, 'Unable to generate a token');
@@ -680,7 +679,7 @@ class Login implements ControllerProviderInterface
$url = $app->url('login_renew_password', ['token' => $token], true); $url = $app->url('login_renew_password', ['token' => $token], true);
$mail = MailRequestPasswordUpdate::create($app, $receiver); $mail = MailRequestPasswordUpdate::create($app, $receiver);
$mail->setLogin($user->get_login()); $mail->setLogin($user->getLogin());
$mail->setButtonUrl($url); $mail->setButtonUrl($url);
$app['notification.deliverer']->deliver($mail); $app['notification.deliverer']->deliver($mail);
@@ -808,10 +807,7 @@ class Login implements ControllerProviderInterface
$app['dispatcher']->dispatch(PhraseaEvents::PRE_AUTHENTICATE, new PreAuthenticate($request, $context)); $app['dispatcher']->dispatch(PhraseaEvents::PRE_AUTHENTICATE, new PreAuthenticate($request, $context));
$password = \random::generatePassword(24); $password = \random::generatePassword(24);
$user = \User_Adapter::create($app, 'invite', $password, null, false, true); $invite_user = $app['manipulator.user']->createUser('invite', $password);
$inviteUsrid = \User_Adapter::get_usr_id_from_login($app, 'invite');
$invite_user = \User_Adapter::getInstance($inviteUsrid, $app);
$usr_base_ids = array_keys($app['acl']->get($user)->get_granted_base()); $usr_base_ids = array_keys($app['acl']->get($user)->get_granted_base());
$app['acl']->get($user)->revoke_access_from_bases($usr_base_ids); $app['acl']->get($user)->revoke_access_from_bases($usr_base_ids);
@@ -822,7 +818,7 @@ class Login implements ControllerProviderInterface
$this->postAuthProcess($app, $user); $this->postAuthProcess($app, $user);
$response = $this->generateAuthResponse($app, $app['browser'], $request->request->get('redirect')); $response = $this->generateAuthResponse($app, $app['browser'], $request->request->get('redirect'));
$response->headers->setCookie(new Cookie('invite-usr-id', $user->get_id())); $response->headers->setCookie(new Cookie('invite-usr-id', $user->getId()));
$event = new PostAuthenticate($request, $response, $user, $context); $event = new PostAuthenticate($request, $response, $user, $context);
$app['dispatcher']->dispatch(PhraseaEvents::POST_AUTHENTICATE, $event); $app['dispatcher']->dispatch(PhraseaEvents::POST_AUTHENTICATE, $event);
@@ -849,7 +845,7 @@ class Login implements ControllerProviderInterface
} }
// move this in an event // move this in an event
public function postAuthProcess(PhraseaApplication $app, \User_Adapter $user) public function postAuthProcess(PhraseaApplication $app, User $user)
{ {
$date = new \DateTime('+' . (int) $app['conf']->get(['registry', 'actions', 'validation-reminder-days']) . ' days'); $date = new \DateTime('+' . (int) $app['conf']->get(['registry', 'actions', 'validation-reminder-days']) . ' days');
@@ -885,7 +881,7 @@ class Login implements ControllerProviderInterface
$session = $app['authentication']->openAccount($user); $session = $app['authentication']->openAccount($user);
if ($user->get_locale() != $app['locale']) { if ($user->getLocale() != $app['locale']) {
$user->set_locale($app['locale']); $user->set_locale($app['locale']);
} }
@@ -1047,7 +1043,7 @@ class Login implements ControllerProviderInterface
throw new AuthenticationException(call_user_func($redirector, $params)); throw new AuthenticationException(call_user_func($redirector, $params));
} }
$user = \User_Adapter::getInstance($usr_id, $app); $user = $app['manipulator.user']->getRepository()->find($usr_id);
$session = $this->postAuthProcess($app, $user); $session = $this->postAuthProcess($app, $user);
@@ -1056,13 +1052,13 @@ class Login implements ControllerProviderInterface
if ($request->cookies->has('postlog') && $request->cookies->get('postlog') == '1') { if ($request->cookies->has('postlog') && $request->cookies->get('postlog') == '1') {
if (!$user->is_guest() && $request->cookies->has('invite-usr_id')) { if (!$user->is_guest() && $request->cookies->has('invite-usr_id')) {
if ($user->get_id() != $inviteUsrId = $request->cookies->get('invite-usr_id')) { if ($user->getId() != $inviteUsrId = $request->cookies->get('invite-usr_id')) {
$repo = $app['EM']->getRepository('Phraseanet:Basket'); $repo = $app['EM']->getRepository('Phraseanet:Basket');
$baskets = $repo->findBy(['usr_id' => $inviteUsrId]); $baskets = $repo->findBy(['usr_id' => $inviteUsrId]);
foreach ($baskets as $basket) { foreach ($baskets as $basket) {
$basket->setUsrId($user->get_id()); $basket->setUsrId($user->getId());
$app['EM']->persist($basket); $app['EM']->persist($basket);
} }
} }

View File

@@ -55,15 +55,16 @@ class RSSFeeds implements ControllerProviderInterface
$page = $page < 1 ? 1 : $page; $page = $page < 1 ? 1 : $page;
return $app['feed.formatter-strategy']($format) return $app['feed.formatter-strategy']($format)
->createResponse($app, $token->getFeed(), $page, \User_Adapter::getInstance($token->getUsrId(), $app)); ->createResponse($app, $token->getFeed(), $page, $app['manipulator.user']->getRepository()->find($token->getUsrId()));
}) })
->bind('feed_user') ->bind('feed_user')
->assert('id', '\d+') ->assert('id', '\d+')
->assert('format', '(rss|atom)'); ->assert('format', '(rss|atom)');
$controllers->get('/userfeed/aggregated/{token}/{format}/', function (Application $app, $token, $format) { $controllers->get('/userfeed/aggregated/{token}/{format}/', function (Application $app, $token, $format) {
$token = $app['EM']->getRepository('Phraseanet:AggregateToken')->findOneBy(["value" => $token]); $token = $app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\AggregateToken')->findOneBy(["value" => $token]);
$user = \User_Adapter::getInstance($token->getUsrId(), $app);
$user = $app['manipulator.user']->getRepository()->find($token->getUsrId());
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($user)); $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($user));

View File

@@ -57,7 +57,7 @@ class Session implements ControllerProviderInterface
]; ];
if ($app['authentication']->isAuthenticated()) { if ($app['authentication']->isAuthenticated()) {
$usr_id = $app['authentication']->getUser()->get_id(); $usr_id = $app['authentication']->getUser()->getId();
if ($usr_id != $request->request->get('usr')) { // I logged with another user if ($usr_id != $request->request->get('usr')) { // I logged with another user
$ret['status'] = 'disconnected'; $ret['status'] = 'disconnected';
@@ -138,7 +138,7 @@ class Session implements ControllerProviderInterface
$app->abort(404, 'Unknown session'); $app->abort(404, 'Unknown session');
} }
if ($session->getUsrId() !== $app['authentication']->getUser()->get_id()) { if ($session->getUsrId() !== $app['authentication']->getUser()->getId()) {
$app->abort(403, 'Unauthorized'); $app->abort(403, 'Unauthorized');
} }

View File

@@ -777,7 +777,7 @@ class Thesaurus implements ControllerProviderInterface
$bases = $languages = []; $bases = $languages = [];
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $app['authentication']->getUser()->get_id()]); $stmt->execute(array(':usr_id' => $app['authentication']->getUser()->getId()));
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();

View File

@@ -358,7 +358,7 @@ class Xmlhttp implements ControllerProviderInterface
public function EditingPresetsJson(Application $app, Request $request) public function EditingPresetsJson(Application $app, Request $request)
{ {
$usr_id = $app['authentication']->getUser()->get_id(); $usr_id = $app['authentication']->getUser()->getId();
$ret = ['parm' => [ $ret = ['parm' => [
'act' => $request->get('act'), 'act' => $request->get('act'),

View File

@@ -59,7 +59,7 @@ class Notifications implements ControllerProviderInterface
try { try {
$app['events-manager']->read( $app['events-manager']->read(
explode('_', (string) $request->request->get('notifications')), explode('_', (string) $request->request->get('notifications')),
$app['authentication']->getUser()->get_id() $app['authentication']->getUser()->getId()
); );
return $app->json(['success' => true, 'message' => '']); return $app->json(['success' => true, 'message' => '']);

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Core\Event; namespace Alchemy\Phrasea\Core\Event;
use Alchemy\Phrasea\Authentication\Context; use Alchemy\Phrasea\Authentication\Context;
use Alchemy\Phrasea\Model\Entities\User;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\Event as SfEvent; use Symfony\Component\EventDispatcher\Event as SfEvent;
@@ -23,7 +24,7 @@ class PostAuthenticate extends SfEvent
private $request; private $request;
private $response; private $response;
public function __construct(Request $request, Response $response, \User_Adapter $user, Context $context) public function __construct(Request $request, Response $response, User $user, Context $context)
{ {
$this->request = $request; $this->request = $request;
$this->response = $response; $this->response = $response;

View File

@@ -57,12 +57,11 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
$templates = array_filter(array_map(function ($templateId) use ($app) { $templates = array_filter(array_map(function ($templateId) use ($app) {
try { try {
if (is_int($templateId) || ctype_digit($templateId)) { if (is_int($templateId) || ctype_digit($templateId)) {
return \User_Adapter::getInstance($templateId, $app); return $app['manipulator.user']->getRepository()->find($templateId);
} else { }
$template = \User_Adapter::get_usr_id_from_login($app, $templateId);
if (false !== $template) { if (false !== $templateId) {
return \User_Adapter::getInstance($template, $app); return $app['manipulator.user']->getRepository()->find($templateId);
}
} }
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -12,7 +12,9 @@
namespace Alchemy\Phrasea\Feed; namespace Alchemy\Phrasea\Feed;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Alchemy\Phrasea\Model\Entities\AggregateToken; use Alchemy\Phrasea\Model\Entities\AggregateToken;
@@ -55,7 +57,7 @@ class Aggregate implements FeedInterface
$this->updatedOn = new \DateTime(); $this->updatedOn = new \DateTime();
$this->em = $em; $this->em = $em;
$tmp_feeds = []; $tmp_feeds = array();
foreach ($feeds as $feed) { foreach ($feeds as $feed) {
$tmp_feeds[$feed->getId()] = $feed; $tmp_feeds[$feed->getId()] = $feed;
@@ -71,14 +73,14 @@ class Aggregate implements FeedInterface
* Creates an aggregate from all the feeds available to a given user. * Creates an aggregate from all the feeds available to a given user.
* *
* @param EntityManager $em * @param EntityManager $em
* @param \User_Adapter $user * @param User $user
* *
* @return Aggregate * @return Aggregate
*/ */
public static function createFromUser(Application $app, \User_Adapter $user) public static function createFromUser(Application $app, User $user)
{ {
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($user)); $feeds = $app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser($app['acl']->get($user));
$token = $app['EM']->getRepository('Phraseanet:AggregateToken')->findOneBy(['usrId' => $user->get_id()]); $token = $app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\AggregateToken')->findOneBy(array('usrId' => $user->getId()));
return new static($app['EM'], $feeds, $token); return new static($app['EM'], $feeds, $token);
} }
@@ -115,7 +117,7 @@ class Aggregate implements FeedInterface
return new ArrayCollection(); return new ArrayCollection();
} }
$feedIds = []; $feedIds = array();
foreach ($this->feeds as $feed) { foreach ($this->feeds as $feed) {
$feedIds[] = $feed->getId(); $feedIds[] = $feed->getId();
} }
@@ -201,7 +203,7 @@ class Aggregate implements FeedInterface
public function getCountTotalEntries() public function getCountTotalEntries()
{ {
if (count($this->feeds) > 0) { if (count($this->feeds) > 0) {
$feedIds = []; $feedIds = array();
foreach ($this->feeds as $feed) { foreach ($this->feeds as $feed) {
$feedIds[] = $feed->getId(); $feedIds[] = $feed->getId();
} }
@@ -238,6 +240,6 @@ class Aggregate implements FeedInterface
*/ */
public static function getPublic(Application $app) public static function getPublic(Application $app)
{ {
return new static($app['EM'], $app['EM']->getRepository('Phraseanet:Feed')->findBy(['public' => true], ['updatedOn' => 'DESC'])); return new static($app['EM'], $app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->findBy(array('public' => true), array('updatedOn' => 'DESC')));
} }
} }

View File

@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Model\Entities\FeedEntry;
use Alchemy\Phrasea\Feed\FeedInterface; use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Feed\Link\FeedLink; use Alchemy\Phrasea\Feed\Link\FeedLink;
use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection; use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection;
use Alchemy\Phrasea\Model\Entities\User;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterface class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterface
@@ -34,7 +35,7 @@ class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterf
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createResponse(Application $app, FeedInterface $feed, $page, \User_Adapter $user = null, $generator = 'Phraseanet') public function createResponse(Application $app, FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet')
{ {
$content = $this->format($feed, $page, $user, $generator, $app); $content = $this->format($feed, $page, $user, $generator, $app);
$response = new Response($content, 200, ['Content-Type' => 'application/atom+xml']); $response = new Response($content, 200, ['Content-Type' => 'application/atom+xml']);
@@ -45,7 +46,7 @@ class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterf
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function format(FeedInterface $feed, $page, \User_Adapter $user = null, $generator = 'Phraseanet', Application $app = null) public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null)
{ {
$updated_on = $feed->getUpdatedOn(); $updated_on = $feed->getUpdatedOn();

View File

@@ -17,6 +17,7 @@ use Alchemy\Phrasea\Model\Entities\FeedEntry;
use Alchemy\Phrasea\Model\Entities\FeedItem; use Alchemy\Phrasea\Model\Entities\FeedItem;
use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection; use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection;
use Alchemy\Phrasea\Feed\RSS\FeedRSSImage; use Alchemy\Phrasea\Feed\RSS\FeedRSSImage;
use Alchemy\Phrasea\Model\Entities\User;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterInterface class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterInterface
@@ -36,7 +37,7 @@ class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterIn
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createResponse(Application $app, FeedInterface $feed, $page, \User_Adapter $user = null, $generator = 'Phraseanet') public function createResponse(Application $app, FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet')
{ {
$content = $this->format($feed, $page, $user, $generator, $app); $content = $this->format($feed, $page, $user, $generator, $app);
$response = new Response($content, 200, ['Content-Type' => 'application/rss+xml']); $response = new Response($content, 200, ['Content-Type' => 'application/rss+xml']);
@@ -47,7 +48,7 @@ class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterIn
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function format(FeedInterface $feed, $page, \User_Adapter $user = null, $generator = 'Phraseanet', Application $app = null) public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null)
{ {
$updated_on = $feed->getUpdatedOn(); $updated_on = $feed->getUpdatedOn();

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Feed\Formatter;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Feed\FeedInterface; use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Model\Entities\User;
interface FeedFormatterInterface interface FeedFormatterInterface
{ {
@@ -21,24 +22,24 @@ interface FeedFormatterInterface
* *
* @param FeedInterface $feed * @param FeedInterface $feed
* @param type $page * @param type $page
* @param \User_Adapter $user * @param User $user
* @param type $generator * @param type $generator
* @param Application $app * @param Application $app
* *
* @return string * @return string
*/ */
public function format(FeedInterface $feed, $page, \User_Adapter $user = null, $generator = 'Phraseanet', Application $app); public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app);
/** /**
* Returns an HTTP Response containing a string representation of the feed. * Returns an HTTP Response containing a string representation of the feed.
* *
* @param FeedInterface $feed * @param FeedInterface $feed
* @param type $page * @param type $page
* @param \User_Adapter $user * @param User $user
* @param type $generator * @param type $generator
* @param Application $app * @param Application $app
* *
* @return string * @return string
*/ */
public function createResponse(Application $app, FeedInterface $feed, $page, \User_Adapter $user = null, $generator = 'Phraseanet'); public function createResponse(Application $app, FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet');
} }

View File

@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Feed\Link\FeedLink; use Alchemy\Phrasea\Feed\Link\FeedLink;
use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection; use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection;
use Alchemy\Phrasea\Feed\RSS\FeedRSSImage; use Alchemy\Phrasea\Feed\RSS\FeedRSSImage;
use Alchemy\Phrasea\Model\Entities\User;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Model\Entities\FeedEntry;
use Alchemy\Phrasea\Feed\Link\FeedLinkGenerator; use Alchemy\Phrasea\Feed\Link\FeedLinkGenerator;
@@ -37,7 +38,7 @@ class RssFormatter extends FeedFormatterAbstract implements FeedFormatterInterfa
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createResponse(Application $app, FeedInterface $feed, $page, \User_Adapter $user = null, $generator = 'Phraseanet') public function createResponse(Application $app, FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet')
{ {
$content = $this->format($feed, $page, $user, $generator, $app); $content = $this->format($feed, $page, $user, $generator, $app);
$response = new Response($content, 200, ['Content-Type' => 'application/rss+xml']); $response = new Response($content, 200, ['Content-Type' => 'application/rss+xml']);
@@ -48,7 +49,7 @@ class RssFormatter extends FeedFormatterAbstract implements FeedFormatterInterfa
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function format(FeedInterface $feed, $page, \User_Adapter $user = null, $generator = 'Phraseanet', Application $app = null) public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null)
{ {
$updated_on = $feed->getUpdatedOn(); $updated_on = $feed->getUpdatedOn();

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Feed\Aggregate; use Alchemy\Phrasea\Feed\Aggregate;
use Alchemy\Phrasea\Feed\FeedInterface; use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Model\Entities\AggregateToken; use Alchemy\Phrasea\Model\Entities\AggregateToken;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\Generator\UrlGenerator;
@@ -42,7 +43,7 @@ class AggregateLinkGenerator implements LinkGeneratorInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function generate(FeedInterface $aggregate, \User_Adapter $user, $format, $page = null, $renew = false) public function generate(FeedInterface $aggregate, User $user, $format, $page = null, $renew = false)
{ {
if (!$this->supports($aggregate)) { if (!$this->supports($aggregate)) {
throw new InvalidArgumentException('AggregateLinkGenerator only support aggregate feeds.'); throw new InvalidArgumentException('AggregateLinkGenerator only support aggregate feeds.');
@@ -50,10 +51,10 @@ class AggregateLinkGenerator implements LinkGeneratorInterface
switch ($format) { switch ($format) {
case self::FORMAT_ATOM: case self::FORMAT_ATOM:
$params = [ $params = array(
'token' => $this->getAggregateToken($user, $renew)->getValue(), 'token' => $this->getAggregateToken($user, $renew)->getValue(),
'format' => 'atom' 'format' => 'atom'
]; );
if (null !== $page) { if (null !== $page) {
$params['page'] = $page; $params['page'] = $page;
} }
@@ -64,10 +65,10 @@ class AggregateLinkGenerator implements LinkGeneratorInterface
'application/atom+xml' 'application/atom+xml'
); );
case self::FORMAT_RSS: case self::FORMAT_RSS:
$params = [ $params = array(
'token' => $this->getAggregateToken($user, $renew)->getValue(), 'token' => $this->getAggregateToken($user, $renew)->getValue(),
'format' => 'rss' 'format' => 'rss'
]; );
if (null !== $page) { if (null !== $page) {
$params['page'] = $page; $params['page'] = $page;
} }
@@ -101,7 +102,7 @@ class AggregateLinkGenerator implements LinkGeneratorInterface
switch ($format) { switch ($format) {
case self::FORMAT_ATOM: case self::FORMAT_ATOM:
$params = ['format' => 'atom']; $params = array('format' => 'atom');
if (null !== $page) { if (null !== $page) {
$params['page'] = $page; $params['page'] = $page;
} }
@@ -112,7 +113,7 @@ class AggregateLinkGenerator implements LinkGeneratorInterface
'application/atom+xml' 'application/atom+xml'
); );
case self::FORMAT_RSS: case self::FORMAT_RSS:
$params = ['format' => 'rss']; $params = array('format' => 'rss');
if (null !== $page) { if (null !== $page) {
$params['page'] = $page; $params['page'] = $page;
} }
@@ -127,16 +128,16 @@ class AggregateLinkGenerator implements LinkGeneratorInterface
} }
} }
private function getAggregateToken(\User_Adapter $user, $renew = false) private function getAggregateToken(User $user, $renew = false)
{ {
$token = $this->em $token = $this->em
->getRepository('Phraseanet:AggregateToken') ->getRepository('Alchemy\Phrasea\Model\Entities\AggregateToken')
->findOneBy(['usrId' => $user->get_id()]); ->findOneBy(array('usrId' => $user->getId()));
if (null === $token || true === $renew) { if (null === $token || true === $renew) {
if (null === $token) { if (null === $token) {
$token = new AggregateToken(); $token = new AggregateToken();
$token->setUsrId($user->get_id()); $token->setUsrId($user->getId());
} }
$token->setValue($this->random->generatePassword(12, \random::LETTERS_AND_NUMBERS)); $token->setValue($this->random->generatePassword(12, \random::LETTERS_AND_NUMBERS));

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Feed\Link;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Feed\FeedInterface; use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Alchemy\Phrasea\Model\Entities\Feed; use Alchemy\Phrasea\Model\Entities\Feed;
use Alchemy\Phrasea\Model\Entities\FeedToken; use Alchemy\Phrasea\Model\Entities\FeedToken;
@@ -42,7 +43,7 @@ class FeedLinkGenerator implements LinkGeneratorInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function generate(FeedInterface $feed, \User_Adapter $user, $format, $page = null, $renew = false) public function generate(FeedInterface $feed, User $user, $format, $page = null, $renew = false)
{ {
if (!$this->supports($feed)) { if (!$this->supports($feed)) {
throw new InvalidArgumentException('FeedLinkGenerator only support aggregate feeds.'); throw new InvalidArgumentException('FeedLinkGenerator only support aggregate feeds.');
@@ -50,11 +51,11 @@ class FeedLinkGenerator implements LinkGeneratorInterface
switch ($format) { switch ($format) {
case self::FORMAT_ATOM: case self::FORMAT_ATOM:
$params = [ $params = array(
'token' => $this->getFeedToken($feed, $user, $renew)->getValue(), 'token' => $this->getFeedToken($feed, $user, $renew)->getValue(),
'id' => $feed->getId(), 'id' => $feed->getId(),
'format' => 'atom' 'format' => 'atom'
]; );
if (null !== $page) { if (null !== $page) {
$params['page'] = $page; $params['page'] = $page;
} }
@@ -65,11 +66,11 @@ class FeedLinkGenerator implements LinkGeneratorInterface
'application/atom+xml' 'application/atom+xml'
); );
case self::FORMAT_RSS: case self::FORMAT_RSS:
$params = [ $params = array(
'token' => $this->getFeedToken($feed, $user, $renew)->getValue(), 'token' => $this->getFeedToken($feed, $user, $renew)->getValue(),
'id' => $feed->getId(), 'id' => $feed->getId(),
'format' => 'rss' 'format' => 'rss'
]; );
if (null !== $page) { if (null !== $page) {
$params['page'] = $page; $params['page'] = $page;
} }
@@ -103,10 +104,10 @@ class FeedLinkGenerator implements LinkGeneratorInterface
switch ($format) { switch ($format) {
case self::FORMAT_ATOM: case self::FORMAT_ATOM:
$params = [ $params = array(
'id' => $feed->getId(), 'id' => $feed->getId(),
'format' => 'atom' 'format' => 'atom'
]; );
if (null !== $page) { if (null !== $page) {
$params['page'] = $page; $params['page'] = $page;
} }
@@ -117,10 +118,10 @@ class FeedLinkGenerator implements LinkGeneratorInterface
'application/atom+xml' 'application/atom+xml'
); );
case self::FORMAT_RSS: case self::FORMAT_RSS:
$params = [ $params = array(
'id' => $feed->getId(), 'id' => $feed->getId(),
'format' => 'rss' 'format' => 'rss'
]; );
if (null !== $page) { if (null !== $page) {
$params['page'] = $page; $params['page'] = $page;
} }
@@ -135,17 +136,17 @@ class FeedLinkGenerator implements LinkGeneratorInterface
} }
} }
private function getFeedToken(Feed $feed, \User_Adapter $user, $renew = false) private function getFeedToken(Feed $feed, User $user, $renew = false)
{ {
$token = $this->em $token = $this->em
->getRepository('Phraseanet:FeedToken') ->getRepository('Alchemy\Phrasea\Model\Entities\FeedToken')
->findOneBy(['usrId' => $user->get_id(), 'feed' => $feed->getId()]); ->findOneBy(array('usrId' => $user->getId(), 'feed' => $feed->getId()));
if (null === $token || true === $renew) { if (null === $token || true === $renew) {
if (null === $token) { if (null === $token) {
$token = new FeedToken(); $token = new FeedToken();
$token->setFeed($feed); $token->setFeed($feed);
$token->setUsrId($user->get_id()); $token->setUsrId($user->getId());
$feed->addToken($token); $feed->addToken($token);
$this->em->persist($feed); $this->em->persist($feed);

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Feed\Link;
use Alchemy\Phrasea\Feed\FeedInterface; use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\User;
class LinkGeneratorCollection implements LinkGeneratorInterface class LinkGeneratorCollection implements LinkGeneratorInterface
{ {
@@ -31,7 +32,7 @@ class LinkGeneratorCollection implements LinkGeneratorInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function generate(FeedInterface $feed, \User_Adapter $user, $format, $page = null, $renew = false) public function generate(FeedInterface $feed, User $user, $format, $page = null, $renew = false)
{ {
if (null === $generator = $this->findGenerator($feed)) { if (null === $generator = $this->findGenerator($feed)) {
throw new InvalidArgumentException(sprintf('Unable to find a valid generator for %s', get_class($feed))); throw new InvalidArgumentException(sprintf('Unable to find a valid generator for %s', get_class($feed)));

View File

@@ -12,14 +12,15 @@
namespace Alchemy\Phrasea\Feed\Link; namespace Alchemy\Phrasea\Feed\Link;
use Alchemy\Phrasea\Feed\FeedInterface; use Alchemy\Phrasea\Feed\FeedInterface;
use Alchemy\Phrasea\Model\Entities\User;
interface LinkGeneratorInterface interface LinkGeneratorInterface
{ {
/** /**
* Generates a FeedLink based on given FeedInterface and User_Adapter. * Generates a FeedLink based on given FeedInterface and User.
* *
* @param FeedInterface $feed * @param FeedInterface $feed
* @param \User_Adapter $user * @param User $user
* @param type $format * @param type $format
* @param type $page * @param type $page
* @param type $renew * @param type $renew
@@ -28,7 +29,7 @@ interface LinkGeneratorInterface
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function generate(FeedInterface $feed, \User_Adapter $user, $format, $page = null, $renew = false); public function generate(FeedInterface $feed, User $user, $format, $page = null, $renew = false);
/** /**
* Generates a public FeedLink based on given FeedInterface. * Generates a public FeedLink based on given FeedInterface.

View File

@@ -27,9 +27,7 @@ class NewEmail extends Constraint
public function isAlreadyRegistered($email) public function isAlreadyRegistered($email)
{ {
$ret = (Boolean) \User_Adapter::get_usr_id_from_email($this->app, $email); return (Boolean) $this->app['manipulator.user']->getRepository()->findByEmail($email);
return $ret;
} }
public static function create(Application $app) public static function create(Application $app)

View File

@@ -27,9 +27,7 @@ class NewLogin extends Constraint
public function isAlreadyRegistered($login) public function isAlreadyRegistered($login)
{ {
$ret = (Boolean) \User_Adapter::get_usr_id_from_login($this->app, $login); return (Boolean) $this->app['manipulator.user']->getRepository()->findByLogin($login);
return $ret;
} }
public static function create(Application $app) public static function create(Application $app)

View File

@@ -11,6 +11,8 @@
namespace Alchemy\Phrasea\Helper; namespace Alchemy\Phrasea\Helper;
use Alchemy\Phrasea\Model\Entities\User;
class Prod extends Helper class Prod extends Helper
{ {
@@ -24,7 +26,7 @@ class Prod extends Helper
$bases = $fields = $dates = []; $bases = $fields = $dates = [];
if (! $this->app['authentication']->getUser() instanceof \User_Adapter) { if (! $this->app['authentication']->getUser() instanceof User) {
return $search_datas; return $search_datas;
} }

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Helper\User;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate; use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate;
use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Receiver;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -60,17 +61,17 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
public function delete_users() public function delete_users()
{ {
foreach ($this->users as $usr_id) { foreach ($this->users as $usr_id) {
if ($this->app['authentication']->getUser()->get_id() === (int) $usr_id) { if ($this->app['authentication']->getUser()->getId() === (int) $usr_id) {
continue; continue;
} }
$user = \User_Adapter::getInstance($usr_id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($usr_id);
$this->delete_user($user); $this->delete_user($user);
} }
return $this; return $this;
} }
protected function delete_user(\User_Adapter $user) protected function delete_user(User $user)
{ {
$list = array_keys($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['canadmin'])); $list = array_keys($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['canadmin']));
@@ -180,7 +181,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
if (count($this->users) == 1) { if (count($this->users) == 1) {
$usr_id = array_pop($this->users); $usr_id = array_pop($this->users);
$out['main_user'] = \User_Adapter::getInstance($usr_id, $this->app); $out['main_user'] = $this->app['manipulator.user']->getRepository()->find($usr_id);
} }
return $out; return $out;
@@ -565,9 +566,9 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
$users = $this->users; $users = $this->users;
$user = \User_adapter::getInstance(array_pop($users), $this->app); $user = $this->app['manipulator.user']->getRepository()->find(array_pop($users));
if ($user->is_template() || $user->is_special()) { if ($user->isTemplate() || $user->isSpecial()) {
return $this; return $this;
} }
@@ -592,7 +593,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
throw new \Exception_InvalidArgument('Email addess is not valid'); throw new \Exception_InvalidArgument('Email addess is not valid');
} }
$old_email = $user->get_email(); $old_email = $user->getEmail();
$user->set_firstname($parm['first_name']) $user->set_firstname($parm['first_name'])
->set_lastname($parm['last_name']) ->set_lastname($parm['last_name'])
@@ -607,7 +608,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
->set_tel($parm['telephone']) ->set_tel($parm['telephone'])
->set_fax($parm['fax']); ->set_fax($parm['fax']);
$new_email = $user->get_email(); $new_email = $user->getEmail();
if ($old_email != $new_email) { if ($old_email != $new_email) {
$oldReceiver = $newReceiver = null; $oldReceiver = $newReceiver = null;
@@ -639,18 +640,18 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
public function apply_template() public function apply_template()
{ {
$template = \User_adapter::getInstance($this->request->get('template'), $this->app); $template = $this->app['manipulator.user']->getRepository()->find($this->request->get('template'));
if ($template->get_template_owner()->get_id() != $this->app['authentication']->getUser()->get_id()) { if ($template->getLastModel()->getId() !== $this->app['authentication']->getUser()->getId()) {
throw new AccessDeniedHttpException('You are not the owner of the template'); throw new AccessDeniedHttpException('You are not the owner of the template');
} }
$base_ids = array_keys($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['canadmin'])); $base_ids = array_keys($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['canadmin']));
foreach ($this->users as $usr_id) { foreach ($this->users as $usr_id) {
$user = \User_adapter::getInstance($usr_id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($usr_id);
if ($user->is_template()) { if ($user->isTemplate()) {
continue; continue;
} }
@@ -665,7 +666,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
$this->base_id = (int) $this->request->get('base_id'); $this->base_id = (int) $this->request->get('base_id');
foreach ($this->users as $usr_id) { foreach ($this->users as $usr_id) {
$user = \User_Adapter::getInstance($usr_id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($usr_id);
if ($this->request->get('quota')) if ($this->request->get('quota'))
$this->app['acl']->get($user)->set_quotas_on_base($this->base_id, $this->request->get('droits'), $this->request->get('restes')); $this->app['acl']->get($user)->set_quotas_on_base($this->base_id, $this->request->get('droits'), $this->request->get('restes'));
else else
@@ -686,7 +687,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
if ($vand_and && $vand_or && $vxor_and && $vxor_or) { if ($vand_and && $vand_or && $vxor_and && $vxor_or) {
foreach ($this->users as $usr_id) { foreach ($this->users as $usr_id) {
$user = \User_Adapter::getInstance($usr_id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($usr_id);
$this->app['acl']->get($user)->set_masks_on_base($this->base_id, $vand_and, $vand_or, $vxor_and, $vxor_or); $this->app['acl']->get($user)->set_masks_on_base($this->base_id, $vand_and, $vand_or, $vxor_and, $vxor_or);
} }
@@ -708,7 +709,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
$base_ids = array_keys($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['canadmin'])); $base_ids = array_keys($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['canadmin']));
foreach ($this->users as $usr_id) { foreach ($this->users as $usr_id) {
$user = \User_Adapter::getInstance($usr_id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($usr_id);
if ($this->base_id > 0) { if ($this->base_id > 0) {
$this->app['acl']->get($user)->set_limits($this->base_id, $activate, $dmin, $dmax); $this->app['acl']->get($user)->set_limits($this->base_id, $activate, $dmin, $dmax);
@@ -727,13 +728,13 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
$base_ids = array_keys($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['canadmin'])); $base_ids = array_keys($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['canadmin']));
foreach ($this->users as $usr_id) { foreach ($this->users as $usr_id) {
$user = \User_Adapter::getInstance($usr_id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($usr_id);
$ACL = $this->app['acl']->get($user); $ACL = $this->app['acl']->get($user);
if ($user->is_template()) { if ($user->isTemplate()) {
$template = $user; $template = $user;
if ($template->get_template_owner()->get_id() !== $this->app['authentication']->getUser()->get_id()) { if ($template->getLastModel()->getId() !== $this->app['authentication']->getUser()->getId()) {
continue; continue;
} }
} }

View File

@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Helper\Helper;
use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Receiver;
use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup; use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup;
use Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation; use Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation;
use Alchemy\Phrasea\Model\Entities\User;
class Manage extends Helper class Manage extends Helper
{ {
@@ -44,7 +45,7 @@ class Manage extends Helper
$offset_start = (int) $request->get('offset_start'); $offset_start = (int) $request->get('offset_start');
$offset_start = $offset_start < 0 ? 0 : $offset_start; $offset_start = $offset_start < 0 ? 0 : $offset_start;
$this->query_parms = [ $this->query_parms = array(
'inactives' => $request->get('inactives') 'inactives' => $request->get('inactives')
, 'like_field' => $request->get('like_field') , 'like_field' => $request->get('like_field')
, 'like_value' => $request->get('like_value') , 'like_value' => $request->get('like_value')
@@ -54,7 +55,7 @@ class Manage extends Helper
, 'srt' => $request->get("srt", \User_Query::SORT_CREATIONDATE) , 'srt' => $request->get("srt", \User_Query::SORT_CREATIONDATE)
, 'ord' => $request->get("ord", \User_Query::ORD_DESC) , 'ord' => $request->get("ord", \User_Query::ORD_DESC)
, 'offset_start' => 0 , 'offset_start' => 0
]; );
$query = new \User_Query($this->app); $query = new \User_Query($this->app);
@@ -68,7 +69,7 @@ class Manage extends Helper
->last_model_is($this->query_parms['last_model']) ->last_model_is($this->query_parms['last_model'])
->get_inactives($this->query_parms['inactives']) ->get_inactives($this->query_parms['inactives'])
->include_templates(false) ->include_templates(false)
->on_bases_where_i_am($this->app['acl']->get($this->app['authentication']->getUser()), ['canadmin']) ->on_bases_where_i_am($this->app['acl']->get($this->app['authentication']->getUser()), array('canadmin'))
->execute(); ->execute();
return $this->results->get_results(); return $this->results->get_results();
@@ -81,7 +82,7 @@ class Manage extends Helper
$results_quantity = (int) $this->request->get('per_page'); $results_quantity = (int) $this->request->get('per_page');
$results_quantity = ($results_quantity < 10 || $results_quantity > 50) ? 20 : $results_quantity; $results_quantity = ($results_quantity < 10 || $results_quantity > 50) ? 20 : $results_quantity;
$this->query_parms = [ $this->query_parms = array(
'inactives' => $this->request->get('inactives') 'inactives' => $this->request->get('inactives')
, 'like_field' => $this->request->get('like_field') , 'like_field' => $this->request->get('like_field')
, 'like_value' => $this->request->get('like_value') , 'like_value' => $this->request->get('like_value')
@@ -92,7 +93,7 @@ class Manage extends Helper
, 'ord' => $this->request->get("ord", \User_Query::ORD_DESC) , 'ord' => $this->request->get("ord", \User_Query::ORD_DESC)
, 'per_page' => $results_quantity , 'per_page' => $results_quantity
, 'offset_start' => $offset_start , 'offset_start' => $offset_start
]; );
$query = new \User_Query($this->app); $query = new \User_Query($this->app);
@@ -106,22 +107,16 @@ class Manage extends Helper
->last_model_is($this->query_parms['last_model']) ->last_model_is($this->query_parms['last_model'])
->get_inactives($this->query_parms['inactives']) ->get_inactives($this->query_parms['inactives'])
->include_templates(true) ->include_templates(true)
->on_bases_where_i_am($this->app['acl']->get($this->app['authentication']->getUser()), ['canadmin']) ->on_bases_where_i_am($this->app['acl']->get($this->app['authentication']->getUser()), array('canadmin'))
->limit($offset_start, $results_quantity) ->limit($offset_start, $results_quantity)
->execute(); ->execute();
try { if (null === $invite = $this->app['manipulator.user']->getRepository()->findByLogin(User::USER_GUEST)) {
$invite_id = \User_Adapter::get_usr_id_from_login($this->app, 'invite'); $this->app['manipulator.user']->createUser(User::USER_GUEST, User::USER_GUEST);
$invite = \User_Adapter::getInstance($invite_id, $this->app);
} catch (\Exception $e) {
$invite = \User_Adapter::create($this->app, 'invite', 'invite', '', false);
} }
try { if (null == $autoregister = $this->app['manipulator.user']->getRepository()->findByLogin(User::USER_AUTOREGISTER)) {
$autoregister_id = \User_Adapter::get_usr_id_from_login($this->app, 'autoregister'); $this->app['manipulator.user']->createUser(User::USER_AUTOREGISTER, User::USER_AUTOREGISTER);
$autoregister = \User_Adapter::getInstance($autoregister_id, $this->app);
} catch (\Exception $e) {
$autoregister = \User_Adapter::create($this->app, 'autoregister', 'autoregister', '', false);
} }
foreach ($this->query_parms as $k => $v) { foreach ($this->query_parms as $k => $v) {
@@ -134,13 +129,13 @@ class Manage extends Helper
->only_templates(true) ->only_templates(true)
->execute()->get_results(); ->execute()->get_results();
return [ return array(
'users' => $this->results, 'users' => $this->results,
'parm' => $this->query_parms, 'parm' => $this->query_parms,
'invite_user' => $invite, 'invite_user' => $invite,
'autoregister_user' => $autoregister, 'autoregister_user' => $autoregister,
'templates' => $templates 'templates' => $templates
]; );
} }
public function create_newuser() public function create_newuser()
@@ -154,7 +149,7 @@ class Manage extends Helper
$conn = $this->app['phraseanet.appbox']->get_connection(); $conn = $this->app['phraseanet.appbox']->get_connection();
$sql = 'SELECT usr_id FROM usr WHERE usr_mail = :email'; $sql = 'SELECT usr_id FROM usr WHERE usr_mail = :email';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute([':email' => $email]); $stmt->execute(array(':email' => $email));
$row = $stmt->fetch(\PDO::FETCH_ASSOC); $row = $stmt->fetch(\PDO::FETCH_ASSOC);
$count = count($row); $count = count($row);
@@ -162,8 +157,7 @@ class Manage extends Helper
$sendCredentials = !!$this->request->get('send_credentials', false); $sendCredentials = !!$this->request->get('send_credentials', false);
$validateMail = !!$this->request->get('validate_mail', false); $validateMail = !!$this->request->get('validate_mail', false);
$createdUser = \User_Adapter::create($this->app, $email, \random::generatePassword(16), $email, false, false); $createdUser = $this->app['manipulator.user']->createUser($email, \random::generatePassword(16), $email);
/* @var $createdUser \User_Adapter */
$receiver = null; $receiver = null;
try { try {
@@ -173,12 +167,12 @@ class Manage extends Helper
} }
if ($sendCredentials) { if ($sendCredentials) {
$urlToken = $this->app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $createdUser->get_id()); $urlToken = $this->app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $createdUser->getId());
if ($receiver && false !== $urlToken) { if ($receiver && false !== $urlToken) {
$url = $this->app->url('login_renew_password', ['token' => $urlToken]); $url = $this->app->url('login_renew_password', array('token' => $urlToken));
$mail = MailRequestPasswordSetup::create($this->app, $receiver, null, '', $url); $mail = MailRequestPasswordSetup::create($this->app, $receiver, null, '', $url);
$mail->setLogin($createdUser->get_login()); $mail->setLogin($createdUser->getLogin());
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
} }
} }
@@ -188,18 +182,18 @@ class Manage extends Helper
if ($receiver) { if ($receiver) {
$expire = new \DateTime('+3 days'); $expire = new \DateTime('+3 days');
$token = $this->app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $createdUser->get_id(), $expire, $createdUser->get_email()); $token = $this->app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $createdUser->getId(), $expire, $createdUser->getEmail());
$url = $this->app->url('login_register_confirm', ['code' => $token]); $url = $this->app->url('login_register_confirm', array('code' => $token));
$mail = MailRequestEmailConfirmation::create($this->app, $receiver, null, '', $url, $expire); $mail = MailRequestEmailConfirmation::create($this->app, $receiver, null, '', $url, $expire);
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
} }
} }
$this->usr_id = $createdUser->get_id(); $this->usr_id = $createdUser->getId();
} else { } else {
$this->usr_id = $row['usr_id']; $this->usr_id = $row['usr_id'];
$createdUser = \User_Adapter::getInstance($this->usr_id, $this->app); $createdUser = $this->app['manipulator.user']->getRepository()->find($this->usr_id);
} }
return $createdUser; return $createdUser;
@@ -213,9 +207,9 @@ class Manage extends Helper
throw new \Exception_InvalidArgument('Invalid template name'); throw new \Exception_InvalidArgument('Invalid template name');
} }
$created_user = \User_Adapter::create($this->app, $name, \random::generatePassword(16), null, false, false); $created_user = $this->app['manipulator.user']->getRepository()->find($name, \random::generatePassword(16));
$created_user->set_template($this->app['authentication']->getUser()); $created_user->set_template($this->app['authentication']->getUser());
$this->usr_id = $this->app['authentication']->getUser()->get_id(); $this->usr_id = $this->app['authentication']->getUser()->getId();
return $created_user; return $created_user;
} }

View File

@@ -179,7 +179,7 @@ class Basket
public function setOwner(\User_Adapter $user) public function setOwner(\User_Adapter $user)
{ {
$this->setUsrId($user->get_id()); $this->setUsrId($user->getId());
} }
public function getOwner(Application $app) public function getOwner(Application $app)
@@ -237,7 +237,7 @@ class Basket
public function setPusher(\User_Adapter $user) public function setPusher(\User_Adapter $user)
{ {
$this->setPusherId($user->get_id()); $this->setPusherId($user->getId());
} }
public function getPusher(Application $app) public function getPusher(Application $app)

View File

@@ -283,11 +283,11 @@ class BasketElement
public function getUserValidationDatas(\User_Adapter $user, Application $app) public function getUserValidationDatas(\User_Adapter $user, Application $app)
{ {
foreach ($this->validation_datas as $validationData) { foreach ($this->validation_datas as $validationData) {
if ($validationData->getParticipant($app)->getUser($app)->get_id() == $user->get_id()) { if ($validationData->getParticipant($app)->getUser($app)->getId() == $user->getId()) {
return $validationData; return $validationData;
} }
} }
throw new \Exception('There is no such participant ' . $user->get_email()); throw new \Exception('There is no such participant ' . $user->getEmail());
} }
} }

View File

@@ -280,14 +280,14 @@ class Feed implements FeedInterface
/** /**
* Returns a boolean indicating whether the given User_Adapter is the owner of the feed. * Returns a boolean indicating whether the given User_Adapter is the owner of the feed.
* *
* @param \User_Adapter $user * @param User $user
* *
* @return boolean * @return boolean
*/ */
public function isOwner(\User_Adapter $user) public function isOwner(\User_Adapter $user)
{ {
$owner = $this->getOwner(); $owner = $this->getOwner();
if ($owner !== null && $user->get_id() === $owner->getUsrId()) { if ($owner !== null && $user->getId() === $owner->getUsrId()) {
return true; return true;
} }
@@ -374,14 +374,14 @@ class Feed implements FeedInterface
/** /**
* Returns a boolean indicating whether the given User_Adapter is a publisher of the feed. * Returns a boolean indicating whether the given User_Adapter is a publisher of the feed.
* *
* @param \User_Adapter $user * @param User $user
* *
* @return boolean * @return boolean
*/ */
public function isPublisher(\User_Adapter $user) public function isPublisher(\User_Adapter $user)
{ {
foreach ($this->getPublishers() as $publisher) { foreach ($this->getPublishers() as $publisher) {
if ($publisher->getUsrId() == $user->get_id()) { if ($publisher->getUsrId() == $user->getId()) {
return true; return true;
} }
} }
@@ -392,14 +392,14 @@ class Feed implements FeedInterface
/** /**
* Returns an instance of FeedPublisher matching to the given User_Adapter * Returns an instance of FeedPublisher matching to the given User_Adapter
* *
* @param \User_Adapter $user * @param User $user
* *
* @return FeedPublisher * @return FeedPublisher
*/ */
public function getPublisher(\User_Adapter $user) public function getPublisher(\User_Adapter $user)
{ {
foreach ($this->getPublishers() as $publisher) { foreach ($this->getPublishers() as $publisher) {
if ($publisher->getUsrId() == $user->get_id()) { if ($publisher->getUsrId() == $user->getId()) {
return $publisher; return $publisher;
} }
} }
@@ -453,7 +453,7 @@ class Feed implements FeedInterface
/** /**
* Returns a boolean indicating whether the given User_Adapter has access to the feed * Returns a boolean indicating whether the given User_Adapter has access to the feed
* *
* @param \User_Adapter $user * @param User $user
* @param Application $app * @param Application $app
* *
* @return boolean * @return boolean

View File

@@ -315,14 +315,14 @@ class FeedEntry
/** /**
* Returns a boolean indicating whether the given User_Adapter is the publisher of the entry. * Returns a boolean indicating whether the given User_Adapter is the publisher of the entry.
* *
* @param \User_Adapter $user * @param User $user
* *
* @return boolean * @return boolean
*/ */
public function isPublisher(\User_Adapter $user) public function isPublisher(\User_Adapter $user)
{ {
if ($this->publisher) { if ($this->publisher) {
if ($this->publisher->getUsrId() === $user->get_id()) { if ($this->publisher->getUsrId() === $user->getId()) {
return true; return true;
} }
} }

View File

@@ -478,13 +478,13 @@ class FtpExport
/** /**
* Set user * Set user
* *
* @param \User_Adapter $user * @param User $user
* *
* @return FtpExport * @return FtpExport
*/ */
public function setUser(\User_Adapter $user) public function setUser(\User_Adapter $user)
{ {
$this->setUsrId($user->get_id()); $this->setUsrId($user->getId());
return $this; return $this;
} }

View File

@@ -98,7 +98,7 @@ class OrderElement
if (isset($this->orderMasterId) && null !== $this->orderMasterId) { if (isset($this->orderMasterId) && null !== $this->orderMasterId) {
$user = \User_Adapter::getInstance($this->orderMasterId, $app); $user = \User_Adapter::getInstance($this->orderMasterId, $app);
return $user->get_firstname(); return $user->getFirstName();
} }
return null; return null;

View File

@@ -116,7 +116,7 @@ class Session
public function setUser(\User_Adapter $user) public function setUser(\User_Adapter $user)
{ {
return $this->setUsrId($user->get_id()); return $this->setUsrId($user->getId());
} }
/** /**

View File

@@ -142,7 +142,7 @@ class StoryWZ
public function setUser(\User_Adapter $user) public function setUser(\User_Adapter $user)
{ {
$this->setUsrId($user->get_id()); $this->setUsrId($user->getId());
} }
public function getUser(Application $app) public function getUser(Application $app)

View File

@@ -406,11 +406,11 @@ class User
*/ */
public function setGender($gender) public function setGender($gender)
{ {
if (null !== $gender && !in_array($gender, [ if (null !== $gender && !in_array($gender, array(
self::GENDER_MISS, self::GENDER_MISS,
self::GENDER_MR, self::GENDER_MR,
self::GENDER_MRS self::GENDER_MRS
])) { ))) {
throw new InvalidArgumentException(sprintf("Invalid gender %s.", $gender)); throw new InvalidArgumentException(sprintf("Invalid gender %s.", $gender));
} }
@@ -956,7 +956,7 @@ class User
*/ */
public function isSpecial() public function isSpecial()
{ {
return in_array($this->login, [self::USER_GUEST, self::USER_AUTOREGISTER]); return in_array($this->login, array(self::USER_GUEST, self::USER_AUTOREGISTER));
} }
/** /**

View File

@@ -212,7 +212,7 @@ class UsrList
public function hasAccess(\User_Adapter $user, Application $app) public function hasAccess(\User_Adapter $user, Application $app)
{ {
foreach ($this->getOwners() as $owner) { foreach ($this->getOwners() as $owner) {
if ($owner->getUser($app)->get_id() == $user->get_id()) { if ($owner->getUser($app)->getId() == $user->getId()) {
return true; return true;
} }
} }
@@ -228,7 +228,7 @@ class UsrList
public function getOwner(\User_Adapter $user, Application $app) public function getOwner(\User_Adapter $user, Application $app)
{ {
foreach ($this->getOwners() as $owner) { foreach ($this->getOwners() as $owner) {
if ($owner->getUser($app)->get_id() == $user->get_id()) { if ($owner->getUser($app)->getId() == $user->getId()) {
return $owner; return $owner;
} }
} }
@@ -246,7 +246,7 @@ class UsrList
{ {
return $this->entries->exists( return $this->entries->exists(
function ($key, $entry) use ($user, $app) { function ($key, $entry) use ($user, $app) {
return $entry->getUser($app)->get_id() === $user->get_id(); return $entry->getUser($app)->getId() === $user->getId();
} }
); );
} }

View File

@@ -91,7 +91,7 @@ class UsrListEntry
public function setUser(\User_Adapter $user) public function setUser(\User_Adapter $user)
{ {
return $this->setUsrId($user->get_id()); return $this->setUsrId($user->getId());
} }
/** /**

View File

@@ -95,7 +95,7 @@ class UsrListOwner
public function setUser(\User_Adapter $user) public function setUser(\User_Adapter $user)
{ {
return $this->setUsrId($user->get_id()); return $this->setUsrId($user->getId());
} }
public function getUser(Application $app) public function getUser(Application $app)

View File

@@ -116,7 +116,7 @@ class ValidationParticipant
*/ */
public function setUser(\User_Adapter $user) public function setUser(\User_Adapter $user)
{ {
$this->usr_id = $user->get_id(); $this->usr_id = $user->getId();
return $this; return $this;
} }

View File

@@ -105,12 +105,12 @@ class ValidationSession
public function isInitiator(\User_Adapter $user) public function isInitiator(\User_Adapter $user)
{ {
return $this->getInitiatorId() == $user->get_id(); return $this->getInitiatorId() == $user->getId();
} }
public function setInitiator(\User_Adapter $user) public function setInitiator(\User_Adapter $user)
{ {
$this->initiator_id = $user->get_id(); $this->initiator_id = $user->getId();
return; return;
} }
@@ -269,9 +269,9 @@ class ValidationSession
} }
} else { } else {
if ($this->getParticipant($user, $app)->getCanSeeOthers()) { if ($this->getParticipant($user, $app)->getCanSeeOthers()) {
return $app->trans('Processus de validation recu de %user% et concernant %n% utilisateurs', ['%user%' => $this->getInitiator($app)->get_display_name(), '%n%' => count($this->getParticipants()) - 1]); return $app->trans('Processus de validation recu de %user% et concernant %n% utilisateurs', ['%user%' => $this->getInitiator($app)->getDisplayName(), '%n%' => count($this->getParticipants()) - 1]);
} else { } else {
return $app->trans('Processus de validation recu de %user%', ['%user%' => $this->getInitiator($app)->get_display_name()]); return $app->trans('Processus de validation recu de %user%', ['%user%' => $this->getInitiator($app)->getDisplayName()]);
} }
} }
} }
@@ -284,11 +284,11 @@ class ValidationSession
public function getParticipant(\User_Adapter $user, Application $app) public function getParticipant(\User_Adapter $user, Application $app)
{ {
foreach ($this->getParticipants() as $participant) { foreach ($this->getParticipants() as $participant) {
if ($participant->getUser($app)->get_id() == $user->get_id()) { if ($participant->getUser($app)->getId() == $user->getId()) {
return $participant; return $participant;
} }
} }
throw new NotFoundHttpException('Participant not found ' . $user->get_email()); throw new NotFoundHttpException('Participant not found' . $user->get_email());
} }
} }

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Model\Manipulator;
use Alchemy\Phrasea\Authentication\ACLProvider; use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class ACLManipulator implements ManipulatorInterface class ACLManipulator implements ManipulatorInterface
{ {
@@ -39,13 +40,13 @@ class ACLManipulator implements ManipulatorInterface
/** /**
* Resets rights for users. * Resets rights for users.
* *
* @param User_Adapter $user * @param User[] $users
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function resetAdminRights($users) public function resetAdminRights($users)
{ {
foreach ($this->makeTraversable($users) as $user) { foreach($this->makeTraversable($users) as $user) {
$this->doResetAdminRights($user); $this->doResetAdminRights($user);
} }
} }
@@ -53,9 +54,9 @@ class ACLManipulator implements ManipulatorInterface
/** /**
* Resets rights for a user. * Resets rights for a user.
* *
* @param \User_adapter $user * @param User $user
*/ */
private function doResetAdminRights(\User_adapter $user) private function doResetAdminRights(User $user)
{ {
$acl = $this->ACLProvider->get($user); $acl = $this->ACLProvider->get($user);
$databoxes = $this->appbox->get_databoxes(); $databoxes = $this->appbox->get_databoxes();
@@ -79,12 +80,12 @@ class ACLManipulator implements ManipulatorInterface
{ {
$collections = $databox->get_collections(); $collections = $databox->get_collections();
$acl->update_rights_to_sbas($databox->get_sbas_id(), [ $acl->update_rights_to_sbas($databox->get_sbas_id(), array(
'bas_manage' => '1', 'bas_manage' => '1',
'bas_modify_struct' => '1', 'bas_modify_struct' => '1',
'bas_modif_th' => '1', 'bas_modif_th' => '1',
'bas_chupub' => '1' 'bas_chupub' => '1'
]); ));
$acl->give_access_to_base(array_map(function (\collection $collection) { $acl->give_access_to_base(array_map(function (\collection $collection) {
return $collection->get_base_id(); return $collection->get_base_id();
@@ -108,7 +109,7 @@ class ACLManipulator implements ManipulatorInterface
$acl->set_limits($baseId, false); $acl->set_limits($baseId, false);
$acl->remove_quotas_on_base($baseId); $acl->remove_quotas_on_base($baseId);
$acl->set_masks_on_base($baseId, '0', '0', '0', '0'); $acl->set_masks_on_base($baseId, '0', '0', '0', '0');
$acl->update_rights_to_base($baseId, [ $acl->update_rights_to_base($baseId, array(
'canputinalbum' => '1', 'canputinalbum' => '1',
'candwnldhd' => '1', 'candwnldhd' => '1',
'candwnldsubdef' => '1', 'candwnldsubdef' => '1',
@@ -127,7 +128,7 @@ class ACLManipulator implements ManipulatorInterface
'manage' => '1', 'manage' => '1',
'modify_struct' => '1', 'modify_struct' => '1',
'bas_modify_struct' => '1' 'bas_modify_struct' => '1'
]); ));
} }
/** /**
@@ -140,7 +141,7 @@ class ACLManipulator implements ManipulatorInterface
private function makeTraversable($var) private function makeTraversable($var)
{ {
if (!is_array($var) && !$var instanceof \Traversable) { if (!is_array($var) && !$var instanceof \Traversable) {
return [$var]; return array($var);
} }
return $var; return $var;

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Model\Repositories; namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Model\Entities\BasketElement; use Alchemy\Phrasea\Model\Entities\BasketElement;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -24,7 +25,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class BasketElementRepository extends EntityRepository class BasketElementRepository extends EntityRepository
{ {
public function findUserElement($element_id, \User_Adapter $user) public function findUserElement($element_id, User $user)
{ {
$dql = 'SELECT e $dql = 'SELECT e
FROM Phraseanet:BasketElement e FROM Phraseanet:BasketElement e
@@ -35,11 +36,11 @@ class BasketElementRepository extends EntityRepository
WHERE (b.usr_id = :usr_id OR p.usr_id = :same_usr_id) WHERE (b.usr_id = :usr_id OR p.usr_id = :same_usr_id)
AND e.id = :element_id'; AND e.id = :element_id';
$params = [ $params = array(
'usr_id' => $user->get_id(), 'usr_id' => $user->getId(),
'same_usr_id' => $user->get_id(), 'same_usr_id' => $user->getId(),
'element_id' => $element_id 'element_id' => $element_id
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -64,10 +65,10 @@ class BasketElementRepository extends EntityRepository
WHERE e.record_id = :record_id WHERE e.record_id = :record_id
AND e.sbas_id = :sbas_id'; AND e.sbas_id = :sbas_id';
$params = [ $params = array(
'sbas_id' => $record->get_sbas_id(), 'sbas_id' => $record->get_sbas_id(),
'record_id' => $record->get_record_id() 'record_id' => $record->get_record_id()
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -84,9 +85,9 @@ class BasketElementRepository extends EntityRepository
LEFT JOIN s.participants p LEFT JOIN s.participants p
WHERE e.sbas_id = :sbas_id'; WHERE e.sbas_id = :sbas_id';
$params = [ $params = array(
'sbas_id' => $databox->get_sbas_id(), 'sbas_id' => $databox->get_sbas_id(),
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -97,10 +98,10 @@ class BasketElementRepository extends EntityRepository
/** /**
* *
* @param \record_adapter $record * @param \record_adapter $record
* @param \User_Adapter $user * @param User $user
* @return \Doctrine\Common\Collections\ArrayCollection * @return \Doctrine\Common\Collections\ArrayCollection
*/ */
public function findReceivedElementsByRecord(\record_adapter $record, \User_Adapter $user) public function findReceivedElementsByRecord(\record_adapter $record, User $user)
{ {
$dql = 'SELECT e $dql = 'SELECT e
FROM Phraseanet:BasketElement e FROM Phraseanet:BasketElement e
@@ -112,11 +113,11 @@ class BasketElementRepository extends EntityRepository
AND e.record_id = :record_id AND e.record_id = :record_id
AND e.sbas_id = :sbas_id'; AND e.sbas_id = :sbas_id';
$params = [ $params = array(
'sbas_id' => $record->get_sbas_id(), 'sbas_id' => $record->get_sbas_id(),
'record_id' => $record->get_record_id(), 'record_id' => $record->get_record_id(),
'usr_id' => $user->get_id() 'usr_id' => $user->getId()
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -124,7 +125,7 @@ class BasketElementRepository extends EntityRepository
return $query->getResult(); return $query->getResult();
} }
public function findReceivedValidationElementsByRecord(\record_adapter $record, \User_Adapter $user) public function findReceivedValidationElementsByRecord(\record_adapter $record, User $user)
{ {
$dql = 'SELECT e $dql = 'SELECT e
FROM Phraseanet:BasketElement e FROM Phraseanet:BasketElement e
@@ -135,11 +136,11 @@ class BasketElementRepository extends EntityRepository
AND e.record_id = :record_id AND e.record_id = :record_id
AND e.sbas_id = :sbas_id'; AND e.sbas_id = :sbas_id';
$params = [ $params = array(
'sbas_id' => $record->get_sbas_id(), 'sbas_id' => $record->get_sbas_id(),
'record_id' => $record->get_record_id(), 'record_id' => $record->get_record_id(),
'usr_id' => $user->get_id() 'usr_id' => $user->getId()
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);

View File

@@ -11,8 +11,12 @@
namespace Alchemy\Phrasea\Model\Repositories; namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\Basket;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class BasketRepository extends EntityRepository class BasketRepository extends EntityRepository
{ {
@@ -24,10 +28,10 @@ class BasketRepository extends EntityRepository
/** /**
* Returns all basket for a given user that are not marked as archived * Returns all basket for a given user that are not marked as archived
* *
* @param \User_Adapter $user * @param User $user
* @return \Doctrine\Common\Collections\ArrayCollection * @return \Doctrine\Common\Collections\ArrayCollection
*/ */
public function findActiveByUser(\User_Adapter $user, $sort = null) public function findActiveByUser(User $user, $sort = null)
{ {
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
@@ -42,7 +46,7 @@ class BasketRepository extends EntityRepository
} }
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters(['usr_id' => $user->get_id()]); $query->setParameters(array('usr_id' => $user->getId()));
return $query->getResult(); return $query->getResult();
} }
@@ -50,10 +54,10 @@ class BasketRepository extends EntityRepository
/** /**
* Returns all unread basket for a given user that are not marked as archived * Returns all unread basket for a given user that are not marked as archived
* *
* @param \User_Adapter $user * @param User $user
* @return \Doctrine\Common\Collections\ArrayCollection * @return \Doctrine\Common\Collections\ArrayCollection
*/ */
public function findUnreadActiveByUser(\User_Adapter $user) public function findUnreadActiveByUser(User $user)
{ {
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
@@ -69,11 +73,11 @@ class BasketRepository extends EntityRepository
) )
AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP())'; AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP())';
$params = [ $params = array(
'usr_id_owner' => $user->get_id(), 'usr_id_owner' => $user->getId(),
'usr_id_ownertwo' => $user->get_id(), 'usr_id_ownertwo' => $user->getId(),
'usr_id_participant' => $user->get_id() 'usr_id_participant' => $user->getId()
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -85,10 +89,10 @@ class BasketRepository extends EntityRepository
* Returns all baskets that are in validation session not expired and * Returns all baskets that are in validation session not expired and
* where a specified user is participant (not owner) * where a specified user is participant (not owner)
* *
* @param \User_Adapter $user * @param User $user
* @return \Doctrine\Common\Collections\ArrayCollection * @return \Doctrine\Common\Collections\ArrayCollection
*/ */
public function findActiveValidationByUser(\User_Adapter $user, $sort = null) public function findActiveValidationByUser(User $user, $sort = null)
{ {
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
@@ -106,12 +110,57 @@ class BasketRepository extends EntityRepository
} }
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters([1 => $user->get_id(), 2 => $user->get_id()]); $query->setParameters(array(1 => $user->getId(), 2 => $user->getId()));
return $query->getResult(); return $query->getResult();
} }
public function findContainingRecordForUser(\record_adapter $record, \User_Adapter $user) /**
* Find a basket specified by his basket_id and his owner
*
* @throws NotFoundHttpException
* @throws AccessDeniedHttpException
* @param type $basket_id
* @param User $user
* @return Basket
*/
public function findUserBasket(Application $app, $basket_id, User $user, $requireOwner)
{
$dql = 'SELECT b
FROM Alchemy\Phrasea\Model\Entities\Basket b
LEFT JOIN b.elements e
WHERE b.id = :basket_id';
$query = $this->_em->createQuery($dql);
$query->setParameters(array('basket_id' => $basket_id));
$basket = $query->getOneOrNullResult();
/* @var $basket Basket */
if (null === $basket) {
throw new NotFoundHttpException(_('Basket is not found'));
}
if ($basket->getOwner($app)->getId() != $user->getId()) {
$participant = false;
if ($basket->getValidation() && !$requireOwner) {
try {
$basket->getValidation()->getParticipant($user, $app);
$participant = true;
} catch (\Exception $e) {
}
}
if (!$participant) {
throw new AccessDeniedHttpException(_('You have not access to this basket'));
}
}
return $basket;
}
public function findContainingRecordForUser(\record_adapter $record, User $user)
{ {
$dql = 'SELECT b $dql = 'SELECT b
@@ -120,10 +169,10 @@ class BasketRepository extends EntityRepository
WHERE e.record_id = :record_id AND e.sbas_id = e.sbas_id WHERE e.record_id = :record_id AND e.sbas_id = e.sbas_id
AND b.usr_id = :usr_id'; AND b.usr_id = :usr_id';
$params = [ $params = array(
'record_id' => $record->get_record_id(), 'record_id' => $record->get_record_id(),
'usr_id' => $user->get_id() 'usr_id' => $user->getId()
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -131,9 +180,9 @@ class BasketRepository extends EntityRepository
return $query->getResult(); return $query->getResult();
} }
public function findWorkzoneBasket(\User_Adapter $user, $query, $year, $type, $offset, $perPage) public function findWorkzoneBasket(User $user, $query, $year, $type, $offset, $perPage)
{ {
$params = []; $params = array();
switch ($type) { switch ($type) {
case self::RECEIVED: case self::RECEIVED:
@@ -141,9 +190,9 @@ class BasketRepository extends EntityRepository
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
JOIN b.elements e JOIN b.elements e
WHERE b.usr_id = :usr_id AND b.pusher_id IS NOT NULL'; WHERE b.usr_id = :usr_id AND b.pusher_id IS NOT NULL';
$params = [ $params = array(
'usr_id' => $user->get_id() 'usr_id' => $user->getId()
]; );
break; break;
case self::VALIDATION_DONE: case self::VALIDATION_DONE:
$dql = 'SELECT b $dql = 'SELECT b
@@ -152,10 +201,10 @@ class BasketRepository extends EntityRepository
JOIN b.validation s JOIN b.validation s
JOIN s.participants p JOIN s.participants p
WHERE b.usr_id != ?1 AND p.usr_id = ?2'; WHERE b.usr_id != ?1 AND p.usr_id = ?2';
$params = [ $params = array(
1 => $user->get_id() 1 => $user->getId()
, 2 => $user->get_id() , 2 => $user->getId()
]; );
break; break;
case self::VALIDATION_SENT: case self::VALIDATION_SENT:
$dql = 'SELECT b $dql = 'SELECT b
@@ -163,9 +212,9 @@ class BasketRepository extends EntityRepository
JOIN b.elements e JOIN b.elements e
JOIN b.validation v JOIN b.validation v
WHERE b.usr_id = :usr_id'; WHERE b.usr_id = :usr_id';
$params = [ $params = array(
'usr_id' => $user->get_id() 'usr_id' => $user->getId()
]; );
break; break;
default: default:
$dql = 'SELECT b $dql = 'SELECT b
@@ -174,10 +223,10 @@ class BasketRepository extends EntityRepository
LEFT JOIN b.validation s LEFT JOIN b.validation s
LEFT JOIN s.participants p LEFT JOIN s.participants p
WHERE (b.usr_id = :usr_id OR p.usr_id = :validating_usr_id)'; WHERE (b.usr_id = :usr_id OR p.usr_id = :validating_usr_id)';
$params = [ $params = array(
'usr_id' => $user->get_id(), 'usr_id' => $user->getId(),
'validating_usr_id' => $user->get_id() 'validating_usr_id' => $user->getId()
]; );
break; break;
case self::MYBASKETS: case self::MYBASKETS:
$dql = 'SELECT b $dql = 'SELECT b
@@ -186,9 +235,9 @@ class BasketRepository extends EntityRepository
LEFT JOIN b.validation s LEFT JOIN b.validation s
LEFT JOIN s.participants p LEFT JOIN s.participants p
WHERE (b.usr_id = :usr_id)'; WHERE (b.usr_id = :usr_id)';
$params = [ $params = array(
'usr_id' => $user->get_id() 'usr_id' => $user->getId()
]; );
break; break;
} }
@@ -221,11 +270,11 @@ class BasketRepository extends EntityRepository
/** /**
* Return all actives validation where current user is involved and user basket * Return all actives validation where current user is involved and user basket
* *
* @param \User_Adapter $user * @param User $user
* @param type $sort * @param type $sort
* @return Array * @return Array
*/ */
public function findActiveValidationAndBasketByUser(\User_Adapter $user, $sort = null) public function findActiveValidationAndBasketByUser(User $user, $sort = null)
{ {
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
@@ -244,7 +293,7 @@ class BasketRepository extends EntityRepository
} }
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters(['usr_id' => $user->get_id()]); $query->setParameters(array('usr_id' => $user->getId()));
return $query->getResult(); return $query->getResult();
} }

View File

@@ -24,7 +24,6 @@ class FeedRepository extends EntityRepository
/** /**
* Returns all the feeds a user can access. * Returns all the feeds a user can access.
* *
* @param User_Adapter $user
* @return \Doctrine\Common\Collections\Collection * @return \Doctrine\Common\Collections\Collection
*/ */
public function getAllForUser(\ACL $userACL) public function getAllForUser(\ACL $userACL)

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Model\Repositories; namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
/** /**
@@ -62,12 +63,12 @@ class FtpExportRepository extends EntityRepository
/** /**
* Returns the exports initiated by a given user. * Returns the exports initiated by a given user.
* *
* @param \User_Adapter $user * @param User $user
* *
* @return array * @return array
*/ */
public function findByUser(\User_Adapter $user) public function findByUser(User $user)
{ {
return $this->findBy(['usrId' => $user->get_id()]); return $this->findBy(array('usrId' => $user->getId()));
} }
} }

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Model\Repositories; namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
/** /**
@@ -24,13 +25,13 @@ class OrderRepository extends EntityRepository
/** /**
* Returns the orders initiated by a given user. * Returns the orders initiated by a given user.
* *
* @param \User_Adapter $user * @param User $user
* *
* @return array * @return array
*/ */
public function findByUser(\User_Adapter $user) public function findByUser(User $user)
{ {
return $this->findBy(['usrId' => $user->get_id()]); return $this->findBy(array('usrId' => $user->getId()));
} }
/** /**
@@ -75,7 +76,7 @@ class OrderRepository extends EntityRepository
* *
* @return integer * @return integer
*/ */
public function countTotalOrders(array $baseIds = []) public function countTotalOrders(array $baseIds = array())
{ {
$qb = $this $qb = $this
->createQueryBuilder('o'); ->createQueryBuilder('o');

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Model\Repositories; namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -25,7 +26,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class StoryWZRepository extends EntityRepository class StoryWZRepository extends EntityRepository
{ {
public function findByUser(Application $app, \User_Adapter $user, $sort) public function findByUser(Application $app, User $user, $sort)
{ {
$dql = 'SELECT s FROM Phraseanet:StoryWZ s WHERE s.usr_id = :usr_id '; $dql = 'SELECT s FROM Phraseanet:StoryWZ s WHERE s.usr_id = :usr_id ';
@@ -34,7 +35,7 @@ class StoryWZRepository extends EntityRepository
} }
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters(['usr_id' => $user->get_id()]); $query->setParameters(array('usr_id' => $user->getId()));
$stories = $query->getResult(); $stories = $query->getResult();
@@ -50,7 +51,7 @@ class StoryWZRepository extends EntityRepository
$this->getEntityManager()->flush(); $this->getEntityManager()->flush();
if ($sort == 'name') { if ($sort == 'name') {
$sortedStories = []; $sortedStories = array();
foreach ($stories as $story) { foreach ($stories as $story) {
$sortedStories[] = $story->getRecord($app)->get_title(); $sortedStories[] = $story->getRecord($app)->get_title();
} }
@@ -71,7 +72,7 @@ class StoryWZRepository extends EntityRepository
return $stories; return $stories;
} }
public function findByUserAndId(Application $app, \User_Adapter $user, $id) public function findByUserAndId(Application $app, User $user, $id)
{ {
$story = $this->find($id); $story = $this->find($id);
@@ -83,7 +84,7 @@ class StoryWZRepository extends EntityRepository
throw new NotFoundHttpException('Story not found'); throw new NotFoundHttpException('Story not found');
} }
if ($story->getUser($app)->get_id() !== $user->get_id()) { if ($story->getUser($app)->getId() !== $user->getId()) {
throw new AccessDeniedHttpException('You have not access to ths story'); throw new AccessDeniedHttpException('You have not access to ths story');
} }
} else { } else {
@@ -93,14 +94,14 @@ class StoryWZRepository extends EntityRepository
return $story; return $story;
} }
public function findUserStory(Application $app, \User_Adapter $user, \record_adapter $Story) public function findUserStory(Application $app, User $user, \record_adapter $Story)
{ {
$story = $this->findOneBy( $story = $this->findOneBy(
[ array(
'usr_id' => $user->get_id(), 'usr_id' => $user->getId(),
'sbas_id' => $Story->get_sbas_id(), 'sbas_id' => $Story->get_sbas_id(),
'record_id' => $Story->get_record_id(), 'record_id' => $Story->get_record_id(),
] )
); );
if ($story) { if ($story) {
@@ -122,10 +123,10 @@ class StoryWZRepository extends EntityRepository
AND s.record_id = :record_id'; AND s.record_id = :record_id';
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters([ $query->setParameters(array(
'sbas_id' => $Story->get_sbas_id(), 'sbas_id' => $Story->get_sbas_id(),
'record_id' => $Story->get_record_id(), 'record_id' => $Story->get_record_id(),
]); ));
$stories = $query->getResult(); $stories = $query->getResult();
@@ -147,9 +148,9 @@ class StoryWZRepository extends EntityRepository
$dql = 'SELECT s FROM Phraseanet:StoryWZ s WHERE s.sbas_id = :sbas_id'; $dql = 'SELECT s FROM Phraseanet:StoryWZ s WHERE s.sbas_id = :sbas_id';
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters([ $query->setParameters(array(
'sbas_id' => $databox->get_sbas_id(), 'sbas_id' => $databox->get_sbas_id(),
]); ));
$stories = $query->getResult(); $stories = $query->getResult();

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Model\Repositories; namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
/** /**
@@ -21,13 +22,13 @@ use Doctrine\ORM\EntityRepository;
*/ */
class UsrAuthProviderRepository extends EntityRepository class UsrAuthProviderRepository extends EntityRepository
{ {
public function findByUser(\User_Adapter $user) public function findByUser(User $user)
{ {
$dql = 'SELECT u $dql = 'SELECT u
FROM Phraseanet:UsrAuthProvider u FROM Phraseanet:UsrAuthProvider u
WHERE u.usr_id = :usrId'; WHERE u.usr_id = :usrId';
$params = ['usrId' => $user->get_id()]; $params = array('usrId' => $user->getId());
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -41,7 +42,7 @@ class UsrAuthProviderRepository extends EntityRepository
FROM Phraseanet:UsrAuthProvider u FROM Phraseanet:UsrAuthProvider u
WHERE u.provider = :providerId AND u.distant_id = :distantId'; WHERE u.provider = :providerId AND u.distant_id = :distantId';
$params = ['providerId' => $providerId, 'distantId' => $distantId]; $params = array('providerId' => $providerId, 'distantId' => $distantId);
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Model\Repositories; namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Entities\UsrList; use Alchemy\Phrasea\Model\Entities\UsrList;
use Alchemy\Phrasea\Model\Entities\UsrListEntry; use Alchemy\Phrasea\Model\Entities\UsrListEntry;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
@@ -29,17 +30,17 @@ class UsrListEntryRepository extends EntityRepository
/** /**
* Get all lists entries matching a given User * Get all lists entries matching a given User
* *
* @param \User_Adapter $user * @param User $user
* @param type $like * @param type $like
*/ */
public function findUserList(\User_Adapter $user) public function findUserList(User $user)
{ {
$dql = 'SELECT e FROM Phraseanet:UsrListEntry e $dql = 'SELECT e FROM Phraseanet:UsrListEntry e
WHERE e.usr_id = :usr_id'; WHERE e.usr_id = :usr_id';
$params = [ $params = array(
'usr_id' => $user->get_id(), 'usr_id' => $user->getId(),
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -69,10 +70,10 @@ class UsrListEntryRepository extends EntityRepository
JOIN e.list l JOIN e.list l
WHERE e.usr_id = :usr_id AND l.id = :list_id'; WHERE e.usr_id = :usr_id AND l.id = :list_id';
$params = [ $params = array(
'usr_id' => $usr_id, 'usr_id' => $usr_id,
'list_id' => $list->getId(), 'list_id' => $list->getId(),
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Model\Repositories; namespace Alchemy\Phrasea\Model\Repositories;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Entities\UsrList; use Alchemy\Phrasea\Model\Entities\UsrList;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -29,18 +30,18 @@ class UsrListRepository extends EntityRepository
/** /**
* Get all lists readable for a given User * Get all lists readable for a given User
* *
* @param \User_Adapter $user * @param User $user
* @return \Doctrine\Common\Collections\ArrayCollection * @return \Doctrine\Common\Collections\ArrayCollection
*/ */
public function findUserLists(\User_Adapter $user) public function findUserLists(User $user)
{ {
$dql = 'SELECT l FROM Phraseanet:UsrList l $dql = 'SELECT l FROM Phraseanet:UsrList l
JOIN l.owners o JOIN l.owners o
WHERE o.usr_id = :usr_id'; WHERE o.usr_id = :usr_id';
$params = [ $params = array(
'usr_id' => $user->get_id(), 'usr_id' => $user->getId(),
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);
@@ -50,11 +51,11 @@ class UsrListRepository extends EntityRepository
/** /**
* *
* @param \User_Adapter $user * @param User $user
* @param type $list_id * @param type $list_id
* @return UsrList * @return UsrList
*/ */
public function findUserListByUserAndId(Application $app, \User_Adapter $user, $list_id) public function findUserListByUserAndId(Application $app, User $user, $list_id)
{ {
$list = $this->find($list_id); $list = $this->find($list_id);
@@ -73,20 +74,20 @@ class UsrListRepository extends EntityRepository
/** /**
* Search for a UsrList like '' with a given value, for a user * Search for a UsrList like '' with a given value, for a user
* *
* @param \User_Adapter $user * @param User $user
* @param type $name * @param type $name
* @return \Doctrine\Common\Collections\ArrayCollection * @return \Doctrine\Common\Collections\ArrayCollection
*/ */
public function findUserListLike(\User_Adapter $user, $name) public function findUserListLike(User $user, $name)
{ {
$dql = 'SELECT l FROM Phraseanet:UsrList l $dql = 'SELECT l FROM Phraseanet:UsrList l
JOIN l.owners o JOIN l.owners o
WHERE o.usr_id = :usr_id AND l.name LIKE :name'; WHERE o.usr_id = :usr_id AND l.name LIKE :name';
$params = [ $params = array(
'usr_id' => $user->get_id(), 'usr_id' => $user->getId(),
'name' => $name . '%' 'name' => $name . '%'
]; );
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters($params); $query->setParameters($params);

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Notification; namespace Alchemy\Phrasea\Notification;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\User;
class Emitter implements EmitterInterface class Emitter implements EmitterInterface
{ {
@@ -47,14 +48,14 @@ class Emitter implements EmitterInterface
/** /**
* Creates an Emitter given a User * Creates an Emitter given a User
* *
* @param \User_Adapter $user * @param User $user
* *
* @return Emitter * @return Emitter
* *
* @throws InvalidArgumentException In case no valid email is found for user * @throws InvalidArgumentException In case no valid email is found for user
*/ */
public static function fromUser(\User_Adapter $user) public static function fromUser(User $user)
{ {
return new static($user->get_display_name(), $user->get_email()); return new static($user->getDisplayName(), $user->getEmail());
} }
} }

View File

@@ -12,18 +12,19 @@
namespace Alchemy\Phrasea\Notification\Mail; namespace Alchemy\Phrasea\Notification\Mail;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class MailInfoNewOrder extends AbstractMail class MailInfoNewOrder extends AbstractMail
{ {
/** @var \User_Adapter */ /** @var User */
private $user; private $user;
/** /**
* Set the user that initiates the order * Set the user that initiates the order
* *
* @param \User_Adapter $user * @param User $user
*/ */
public function setUser(\User_Adapter $user) public function setUser(User $user)
{ {
$this->user = $user; $this->user = $user;
} }
@@ -41,11 +42,11 @@ class MailInfoNewOrder extends AbstractMail
*/ */
public function getMessage() public function getMessage()
{ {
if (!$this->user instanceof \User_Adapter) { if (!$this->user instanceof User) {
throw new LogicException('You must set a user before calling getMessage()'); throw new LogicException('You must set a user before calling getMessage()');
} }
return $this->app->trans('%user% has ordered documents', ['%user%' => $this->user->get_display_name()]); return $this->app->trans('%user% has ordered documents', ['%user%' => $this->user->getDisplayName()]);
} }
/** /**

View File

@@ -12,10 +12,11 @@
namespace Alchemy\Phrasea\Notification\Mail; namespace Alchemy\Phrasea\Notification\Mail;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class MailInfoOrderCancelled extends AbstractMail class MailInfoOrderCancelled extends AbstractMail
{ {
/** @var \User_Adapter */ /** @var User */
private $deliverer; private $deliverer;
/** @var integer */ /** @var integer */
private $quantity; private $quantity;
@@ -33,9 +34,9 @@ class MailInfoOrderCancelled extends AbstractMail
/** /**
* Sets the user that has denied the some of the order * Sets the user that has denied the some of the order
* *
* @param \User_Adapter $deliverer * @param User $deliverer
*/ */
public function setDeliverer(\User_Adapter $deliverer) public function setDeliverer(User $deliverer)
{ {
$this->deliverer = $deliverer; $this->deliverer = $deliverer;
} }
@@ -53,7 +54,7 @@ class MailInfoOrderCancelled extends AbstractMail
*/ */
public function getMessage() public function getMessage()
{ {
if (!$this->deliverer instanceof \User_Adapter) { if (!$this->deliverer instanceof User) {
throw new LogicException('You must set a deliverer before calling getMessage()'); throw new LogicException('You must set a deliverer before calling getMessage()');
} }
if (null === $this->quantity) { if (null === $this->quantity) {
@@ -61,7 +62,7 @@ class MailInfoOrderCancelled extends AbstractMail
} }
return $this->app->trans('%user% a refuse %quantity% elements de votre commande', [ return $this->app->trans('%user% a refuse %quantity% elements de votre commande', [
'%user%' => $this->deliverer->get_display_name(), '%user%' => $this->deliverer->getDisplayName(),
'%quantity%' => $this->quantity, '%quantity%' => $this->quantity,
]); ]);
} }

View File

@@ -13,12 +13,13 @@ namespace Alchemy\Phrasea\Notification\Mail;
use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\Basket;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class MailInfoOrderDelivered extends AbstractMail class MailInfoOrderDelivered extends AbstractMail
{ {
/** @var Basket */ /** @var Basket */
private $basket; private $basket;
/** @var \User_Adapter */ /** @var User */
private $deliverer; private $deliverer;
/** /**
@@ -34,9 +35,9 @@ class MailInfoOrderDelivered extends AbstractMail
/** /**
* Sets the user that delivers the order * Sets the user that delivers the order
* *
* @param \User_Adapter $deliverer * @param User $deliverer
*/ */
public function setDeliverer(\User_Adapter $deliverer) public function setDeliverer(User $deliverer)
{ {
$this->deliverer = $deliverer; $this->deliverer = $deliverer;
} }
@@ -62,7 +63,7 @@ class MailInfoOrderDelivered extends AbstractMail
throw new LogicException('You must set a deliverer before calling getMessage'); throw new LogicException('You must set a deliverer before calling getMessage');
} }
return $this->app->trans('%user% vous a delivre votre commande, consultez la en ligne a l\'adresse suivante', ['%user%' => $this->deliverer->get_display_name()]); return $this->app->trans('%user% vous a delivre votre commande, consultez la en ligne a l\'adresse suivante', ['%user%' => $this->deliverer->getDisplayName()]);
} }
/** /**

View File

@@ -13,12 +13,13 @@ namespace Alchemy\Phrasea\Notification\Mail;
use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\Basket;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class MailInfoPushReceived extends AbstractMailWithLink class MailInfoPushReceived extends AbstractMailWithLink
{ {
/** @var Basket */ /** @var Basket */
private $basket; private $basket;
/** @var \User_Adapter */ /** @var User */
private $pusher; private $pusher;
/** /**
@@ -31,7 +32,7 @@ class MailInfoPushReceived extends AbstractMailWithLink
$this->basket = $basket; $this->basket = $basket;
} }
public function setPusher(\User_Adapter $pusher) public function setPusher(User $pusher)
{ {
$this->pusher = $pusher; $this->pusher = $pusher;
} }
@@ -61,7 +62,7 @@ class MailInfoPushReceived extends AbstractMailWithLink
} }
return return
$this->app->trans('You just received a push containing %quantity% documents from %user%', ['%quantity%' => count($this->basket->getElements()), '%user%' => $this->pusher->get_display_name()]) $this->app->trans('You just received a push containing %quantity% documents from %user%', ['%quantity%' => count($this->basket->getElements()), '%user%' => $this->pusher->getDisplayName()])
. "\n" . $this->message; . "\n" . $this->message;
} }

View File

@@ -12,18 +12,19 @@
namespace Alchemy\Phrasea\Notification\Mail; namespace Alchemy\Phrasea\Notification\Mail;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class MailInfoUserRegistered extends AbstractMail class MailInfoUserRegistered extends AbstractMail
{ {
/** @var \User_Adapter */ /** @var User */
private $registeredUser; private $registeredUser;
/** /**
* Sets the user that just registered * Sets the user that just registered
* *
* @param \User_Adapter $registeredUser * @param User $registeredUser
*/ */
public function setRegisteredUser(\User_Adapter $registeredUser) public function setRegisteredUser(User $registeredUser)
{ {
$this->registeredUser = $registeredUser; $this->registeredUser = $registeredUser;
} }
@@ -46,8 +47,8 @@ class MailInfoUserRegistered extends AbstractMail
} }
return $this->app->trans('admin::register: un utilisateur a fait une demande d\'inscription') return $this->app->trans('admin::register: un utilisateur a fait une demande d\'inscription')
. "\n\n" . sprintf('%s %s',$this->registeredUser->get_firstname(), $this->registeredUser->get_lastname()) . "\n\n" . sprintf('%s %s',$this->registeredUser->getFirstName(), $this->registeredUser->getLastName())
. "\n\n" . sprintf('%s %s',$this->registeredUser->get_job(), $this->registeredUser->get_company()); . "\n\n" . sprintf('%s %s',$this->registeredUser->getJob(), $this->registeredUser->getCompany());
} }
/** /**

View File

@@ -12,12 +12,13 @@
namespace Alchemy\Phrasea\Notification\Mail; namespace Alchemy\Phrasea\Notification\Mail;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class MailInfoValidationDone extends AbstractMailWithLink class MailInfoValidationDone extends AbstractMailWithLink
{ {
/** @var string */ /** @var string */
private $title; private $title;
/** @var \User_Adapter */ /** @var User */
private $user; private $user;
/** /**
@@ -33,9 +34,9 @@ class MailInfoValidationDone extends AbstractMailWithLink
/** /**
* Sets the user that finished validation * Sets the user that finished validation
* *
* @param \User_Adapter $user * @param User $user
*/ */
public function setUser(\User_Adapter $user) public function setUser(User $user)
{ {
$this->user = $user; $this->user = $user;
} }
@@ -53,7 +54,7 @@ class MailInfoValidationDone extends AbstractMailWithLink
} }
return $this->app->trans('push::mail:: Rapport de validation de %user% pour %title%', [ return $this->app->trans('push::mail:: Rapport de validation de %user% pour %title%', [
'%user%' => $this->user->get_display_name(), '%user%' => $this->user->getDisplayName(),
'%title%' => $this->title, '%title%' => $this->title,
]); ]);
} }
@@ -68,7 +69,7 @@ class MailInfoValidationDone extends AbstractMailWithLink
} }
return $this->app->trans('%user% has just sent its validation report, you can now see it', [ return $this->app->trans('%user% has just sent its validation report, you can now see it', [
'%user%' => $this->user->get_display_name(), '%user%' => $this->user->getDisplayName(),
]); ]);
} }

View File

@@ -12,12 +12,13 @@
namespace Alchemy\Phrasea\Notification\Mail; namespace Alchemy\Phrasea\Notification\Mail;
use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class MailInfoValidationRequest extends AbstractMailWithLink class MailInfoValidationRequest extends AbstractMailWithLink
{ {
/** @var string */ /** @var string */
private $title; private $title;
/** @var \User_Adapter */ /** @var User */
private $user; private $user;
/** @var integer */ /** @var integer */
private $duration; private $duration;
@@ -59,7 +60,7 @@ class MailInfoValidationRequest extends AbstractMailWithLink
throw new LogicException('You must set a title before calling getSubject'); throw new LogicException('You must set a title before calling getSubject');
} }
return $this->app->trans("Validation request from %user% for '%title%'", ['%user%' => $this->user->get_display_name(), '%title%' => $this->title]); return $this->app->trans("Validation request from %user% for '%title%'", ['%user%' => $this->user->getDisplayName(), '%title%' => $this->title]);
} }
/** /**

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Notification; namespace Alchemy\Phrasea\Notification;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\User;
class Receiver implements ReceiverInterface class Receiver implements ReceiverInterface
{ {
@@ -47,14 +48,14 @@ class Receiver implements ReceiverInterface
/** /**
* Creates a Receiver given a User * Creates a Receiver given a User
* *
* @param \User_Adapter $user * @param User $user
* *
* @return Receiver * @return Receiver
* *
* @throws InvalidArgumentException In case no valid email is found for user * @throws InvalidArgumentException In case no valid email is found for user
*/ */
public static function fromUser(\User_Adapter $user) public static function fromUser(User $user)
{ {
return new static($user->get_display_name(), $user->get_email()); return new static($user->getDisplayName(), $user->getEmail());
} }
} }

View File

@@ -194,8 +194,8 @@ class PhraseaEngine implements SearchEngineInterface
throw new \RuntimeException('Phrasea currently support only authenticated queries'); throw new \RuntimeException('Phrasea currently support only authenticated queries');
} }
if (!phrasea_open_session($this->app['session']->get('phrasea_session_id'), $this->app['authentication']->getUser()->get_id())) { if (!phrasea_open_session($this->app['session']->get('phrasea_session_id'), $this->app['authentication']->getUser()->getId())) {
if (!$ses_id = phrasea_create_session((string) $this->app['authentication']->getUser()->get_id())) { if (!$ses_id = phrasea_create_session((string) $this->app['authentication']->getUser()->getId())) {
throw new \Exception_InternalServerError('Unable to create phrasea session'); throw new \Exception_InternalServerError('Unable to create phrasea session');
} }
$this->app['session']->set('phrasea_session_id', $ses_id); $this->app['session']->set('phrasea_session_id', $ses_id);

View File

@@ -101,7 +101,7 @@ class Installer
private function createUser($email, $password) private function createUser($email, $password)
{ {
$user = \User_Adapter::create($this->app, $email, $password, $email, true); $user = $this->app['manipulator.user']->createUser($email, $password, $email, true);
$this->app['authentication']->openAccount($user); $this->app['authentication']->openAccount($user);
return $user; return $user;

View File

@@ -26,7 +26,7 @@ class MailChecker
* @param \Application $app * @param \Application $app
* @param string $table The table name where to look * @param string $table The table name where to look
* *
* @return array An array of User_Adapter * @return array An array of User
*/ */
public static function getWrongEmailUsers(Application $app, $table = 'usr') public static function getWrongEmailUsers(Application $app, $table = 'usr')
{ {

View File

@@ -55,13 +55,13 @@ class BridgeJob extends AbstractJob
{ {
$app = $data->getApplication(); $app = $data->getApplication();
$status = [ $status = array(
\Bridge_Element::STATUS_PENDING, \Bridge_Element::STATUS_PENDING,
\Bridge_Element::STATUS_PROCESSING, \Bridge_Element::STATUS_PROCESSING,
\Bridge_Element::STATUS_PROCESSING_SERVER \Bridge_Element::STATUS_PROCESSING_SERVER
]; );
$params = []; $params = array();
$n = 1; $n = 1;
foreach ($status as $stat) { foreach ($status as $stat) {
@@ -96,7 +96,7 @@ class BridgeJob extends AbstractJob
$this->log('error', sprintf("An error occured : %s", $e->getMessage())); $this->log('error', sprintf("An error occured : %s", $e->getMessage()));
$sql = 'UPDATE bridge_elements SET status = :status WHERE id = :id'; $sql = 'UPDATE bridge_elements SET status = :status WHERE id = :id';
$params = [':status' => \Bridge_Element::STATUS_ERROR, ':id' => $row['id']]; $params = array(':status' => \Bridge_Element::STATUS_ERROR, ':id' => $row['id']);
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -154,13 +154,13 @@ class BridgeJob extends AbstractJob
switch ($status) { switch ($status) {
case \Bridge_Element::STATUS_ERROR: case \Bridge_Element::STATUS_ERROR:
$params = [ $params = array(
'usr_id' => $account->get_user()->get_id(), 'usr_id' => $account->get_user()->getId(),
'reason' => $error_message, 'reason' => $error_message,
'account_id' => $account->get_id(), 'account_id' => $account->get_id(),
'sbas_id' => $element->get_record()->get_sbas_id(), 'sbas_id' => $element->get_record()->get_sbas_id(),
'record_id' => $element->get_record()->get_record_id(), 'record_id' => $element->get_record()->get_record_id(),
]; );
$app['events-manager']->trigger('__BRIDGE_UPLOAD_FAIL__', $params); $app['events-manager']->trigger('__BRIDGE_UPLOAD_FAIL__', $params);
break; break;

View File

@@ -11,6 +11,8 @@
namespace Alchemy\Phrasea\Vocabulary\ControlProvider; namespace Alchemy\Phrasea\Vocabulary\ControlProvider;
use Alchemy\Phrasea\Model\Entities\User;
interface ControlProviderInterface interface ControlProviderInterface
{ {
@@ -48,10 +50,10 @@ interface ControlProviderInterface
* Find matching Term in the vocabulary repository * Find matching Term in the vocabulary repository
* *
* @param string $query A scalar quaery * @param string $query A scalar quaery
* @param \User_Adapter $for_user The user doing the query * @param User $for_user The user doing the query
* @param \databox $on_databox The databox where vocabulary should be requested * @param \databox $on_databox The databox where vocabulary should be requested
* *
* @return Doctrine\Common\Collections\ArrayCollection * @return Doctrine\Common\Collections\ArrayCollection
*/ */
public function find($query, \User_Adapter $for_user, \databox $on_databox); public function find($query, User $for_user, \databox $on_databox);
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Vocabulary\ControlProvider; namespace Alchemy\Phrasea\Vocabulary\ControlProvider;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Alchemy\Phrasea\Vocabulary\Term; use Alchemy\Phrasea\Vocabulary\Term;
@@ -45,11 +46,11 @@ class UserProvider implements ControlProviderInterface
/** /**
* *
* @param string $query * @param string $query
* @param \User_Adapter $for_user * @param User $for_user
* @param \databox $on_databox * @param \databox $on_databox
* @return \Doctrine\Common\Collections\ArrayCollection * @return \Doctrine\Common\Collections\ArrayCollection
*/ */
public function find($query, \User_Adapter $for_user, \databox $on_databox = null) public function find($query, User $for_user, \databox $on_databox = null)
{ {
$user_query = new \User_Query($this->app); $user_query = new \User_Query($this->app);
@@ -67,7 +68,7 @@ class UserProvider implements ControlProviderInterface
foreach ($users as $user) { foreach ($users as $user) {
$results->add( $results->add(
new Term($user->get_display_name(), '', $this, $user->get_id()) new Term($user->getDisplayName(), '', $this, $user->getId())
); );
} }
@@ -81,15 +82,7 @@ class UserProvider implements ControlProviderInterface
*/ */
public function validate($id) public function validate($id)
{ {
try { return (Boolean) $this->app['manipulator.user']->getRepository()->find($id);
\User_Adapter::getInstance($id, $this->app);
return true;
} catch (\Exception $e) {
}
return false;
} }
/** /**
@@ -99,9 +92,9 @@ class UserProvider implements ControlProviderInterface
*/ */
public function getValue($id) public function getValue($id)
{ {
$user = \User_Adapter::getInstance($id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($id);
return $user->get_display_name(); return $user->getDisplayName();
} }
/** /**
@@ -111,6 +104,6 @@ class UserProvider implements ControlProviderInterface
*/ */
public function getRessource($id) public function getRessource($id)
{ {
return \User_Adapter::getInstance($id, $this->app); return $this->app['manipulator.user']->getRepository()->find($id);
} }
} }

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
class ACL implements cache_cacheableInterface class ACL implements cache_cacheableInterface
{ {
@@ -59,7 +60,7 @@ class ACL implements cache_cacheableInterface
* *
* @var Array * @var Array
*/ */
protected $_global_rights = [ protected $_global_rights = array(
'taskmanager' => false, 'taskmanager' => false,
'manageusers' => false, 'manageusers' => false,
'order' => false, 'order' => false,
@@ -80,7 +81,7 @@ class ACL implements cache_cacheableInterface
'bas_chupub' => false, 'bas_chupub' => false,
'candwnldpreview' => true, 'candwnldpreview' => true,
'candwnldhd' => true 'candwnldhd' => true
]; );
/** /**
* *
@@ -138,20 +139,20 @@ class ACL implements cache_cacheableInterface
return false; return false;
} }
public function grant_hd_on(record_adapter $record, User_Adapter $pusher, $action) public function grant_hd_on(record_adapter $record, User $pusher, $action)
{ {
$sql = 'REPLACE INTO records_rights $sql = 'REPLACE INTO records_rights
(id, usr_id, sbas_id, record_id, document, `case`, pusher_usr_id) (id, usr_id, sbas_id, record_id, document, `case`, pusher_usr_id)
VALUES VALUES
(null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)'; (null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)';
$params = [ $params = array(
':usr_id' => $this->user->get_id() ':usr_id' => $this->user->getId()
, ':sbas_id' => $record->get_sbas_id() , ':sbas_id' => $record->get_sbas_id()
, ':record_id' => $record->get_record_id() , ':record_id' => $record->get_record_id()
, ':case' => $action , ':case' => $action
, ':pusher' => $pusher->get_id() , ':pusher' => $pusher->getId()
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -162,20 +163,20 @@ class ACL implements cache_cacheableInterface
return $this; return $this;
} }
public function grant_preview_on(record_adapter $record, User_Adapter $pusher, $action) public function grant_preview_on(record_adapter $record, User $pusher, $action)
{ {
$sql = 'REPLACE INTO records_rights $sql = 'REPLACE INTO records_rights
(id, usr_id, sbas_id, record_id, preview, `case`, pusher_usr_id) (id, usr_id, sbas_id, record_id, preview, `case`, pusher_usr_id)
VALUES VALUES
(null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)'; (null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)';
$params = [ $params = array(
':usr_id' => $this->user->get_id() ':usr_id' => $this->user->getId()
, ':sbas_id' => $record->get_sbas_id() , ':sbas_id' => $record->get_sbas_id()
, ':record_id' => $record->get_record_id() , ':record_id' => $record->get_record_id()
, ':case' => $action , ':case' => $action
, ':pusher' => $pusher->get_id() , ':pusher' => $pusher->getId()
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -272,7 +273,7 @@ class ACL implements cache_cacheableInterface
return $this; return $this;
} }
$sbas_ids = []; $sbas_ids = array();
foreach ($base_ids as $base_id) { foreach ($base_ids as $base_id) {
$sbas_ids[] = phrasea::sbasFromBas($this->app, $base_id); $sbas_ids[] = phrasea::sbasFromBas($this->app, $base_id);
@@ -280,10 +281,10 @@ class ACL implements cache_cacheableInterface
$sbas_ids = array_unique($sbas_ids); $sbas_ids = array_unique($sbas_ids);
$sbas_rights = ['bas_manage', 'bas_modify_struct', 'bas_modif_th', 'bas_chupub']; $sbas_rights = array('bas_manage', 'bas_modify_struct', 'bas_modif_th', 'bas_chupub');
$sbas_to_acces = []; $sbas_to_acces = array();
$rights_to_give = []; $rights_to_give = array();
foreach ($this->app['acl']->get($template_user)->get_granted_sbas() as $databox) { foreach ($this->app['acl']->get($template_user)->get_granted_sbas() as $databox) {
$sbas_id = $databox->get_sbas_id(); $sbas_id = $databox->get_sbas_id();
@@ -308,27 +309,27 @@ class ACL implements cache_cacheableInterface
$this->update_rights_to_sbas($sbas_id, $rights); $this->update_rights_to_sbas($sbas_id, $rights);
} }
$bas_rights = ['canputinalbum', 'candwnldhd' $bas_rights = array('canputinalbum', 'candwnldhd'
, 'candwnldpreview', 'cancmd' , 'candwnldpreview', 'cancmd'
, 'canadmin', 'actif', 'canreport', 'canpush' , 'canadmin', 'actif', 'canreport', 'canpush'
, 'canaddrecord', 'canmodifrecord', 'candeleterecord' , 'canaddrecord', 'canmodifrecord', 'candeleterecord'
, 'chgstatus', 'imgtools' , 'chgstatus', 'imgtools'
, 'manage', 'modify_struct' , 'manage', 'modify_struct'
, 'nowatermark', 'order_master' , 'nowatermark', 'order_master'
]; );
$bas_to_acces = $masks_to_give = $rights_to_give = []; $bas_to_acces = $masks_to_give = $rights_to_give = array();
/** /**
* map masks (and+xor) of template to masks to apply to user on base * map masks (and+xor) of template to masks to apply to user on base
* (and_and, and_or, xor_and, xor_or) * (and_and, and_or, xor_and, xor_or)
*/ */
$sbmap = [ $sbmap = array(
'00' => ['aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'], '00' => array('aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'),
'01' => ['aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'], '01' => array('aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'),
'10' => ['aa' => '1', 'ao' => '1', 'xa' => '0', 'xo' => '0'], '10' => array('aa' => '1', 'ao' => '1', 'xa' => '0', 'xo' => '0'),
'11' => ['aa' => '1', 'ao' => '1', 'xa' => '1', 'xo' => '1'] '11' => array('aa' => '1', 'ao' => '1', 'xa' => '1', 'xo' => '1')
]; );
foreach ($this->app['acl']->get($template_user)->get_granted_base() as $collection) { foreach ($this->app['acl']->get($template_user)->get_granted_base() as $collection) {
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
@@ -362,7 +363,7 @@ class ACL implements cache_cacheableInterface
. decbin($mask_xor) . decbin($mask_xor)
, -32 , -32
); );
$m = ['aa' => '', 'ao' => '', 'xa' => '', 'xo' => '']; $m = array('aa' => '', 'ao' => '', 'xa' => '', 'xo' => '');
for ($i = 0; $i < 32; $i++) { for ($i = 0; $i < 32; $i++) {
$ax = $mand[$i] . $mxor[$i]; $ax = $mand[$i] . $mxor[$i];
@@ -371,12 +372,12 @@ class ACL implements cache_cacheableInterface
} }
} }
$masks_to_give[$base_id] = [ $masks_to_give[$base_id] = array(
'aa' => $m['aa'] 'aa' => $m['aa']
, 'ao' => $m['ao'] , 'ao' => $m['ao']
, 'xa' => $m['xa'] , 'xa' => $m['xa']
, 'xo' => $m['xo'] , 'xo' => $m['xo']
]; );
} }
$this->give_access_to_base($bas_to_acces); $this->give_access_to_base($bas_to_acces);
@@ -448,7 +449,7 @@ class ACL implements cache_cacheableInterface
*/ */
public function get_cache_key($option = null) public function get_cache_key($option = null)
{ {
return '_ACL_' . $this->user->get_id() . ($option ? '_' . $option : ''); return '_ACL_' . $this->user->getId() . ($option ? '_' . $option : '');
} }
/** /**
@@ -669,10 +670,10 @@ class ACL implements cache_cacheableInterface
* @param array|null $sbas_ids Optionnal sbas_id to restrict the query on * @param array|null $sbas_ids Optionnal sbas_id to restrict the query on
* @return array An array of collection * @return array An array of collection
*/ */
public function get_granted_base(Array $rights = [], array $sbas_ids = null) public function get_granted_base(Array $rights = array(), array $sbas_ids = null)
{ {
$this->load_rights_bas(); $this->load_rights_bas();
$ret = []; $ret = array();
foreach ($this->app['phraseanet.appbox']->get_databoxes() as $databox) { foreach ($this->app['phraseanet.appbox']->get_databoxes() as $databox) {
if ($sbas_ids && !in_array($databox->get_sbas_id(), $sbas_ids)) { if ($sbas_ids && !in_array($databox->get_sbas_id(), $sbas_ids)) {
@@ -716,16 +717,16 @@ class ACL implements cache_cacheableInterface
* @param Array $rights * @param Array $rights
* @return Array * @return Array
*/ */
public function get_granted_sbas($rights = []) public function get_granted_sbas($rights = array())
{ {
if (is_string($rights)) if (is_string($rights))
$rights = [$rights]; $rights = array($rights);
assert(is_array($rights)); assert(is_array($rights));
$this->load_rights_sbas(); $this->load_rights_sbas();
$ret = []; $ret = array();
foreach ($this->_rights_sbas as $sbas_id => $datas) { foreach ($this->_rights_sbas as $sbas_id => $datas) {
$continue = false; $continue = false;
@@ -761,10 +762,10 @@ class ACL implements cache_cacheableInterface
$sql = 'UPDATE usr SET create_db = :create_db WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET create_db = :create_db WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([ $stmt->execute(array(
':create_db' => $boolean ? '1' : '0', ':create_db' => $boolean ? '1' : '0',
':usr_id' => $this->user->get_id() ':usr_id' => $this->user->getId()
]); ));
$stmt->closeCursor(); $stmt->closeCursor();
$this->delete_data_from_cache(self::CACHE_IS_ADMIN); $this->delete_data_from_cache(self::CACHE_IS_ADMIN);
@@ -799,13 +800,13 @@ class ACL implements cache_cacheableInterface
FROM records_rights WHERE usr_id = :usr_id'; FROM records_rights WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]); $stmt->execute(array(':usr_id' => $this->user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
unset($stmt); unset($stmt);
$this->_rights_records_preview = []; $this->_rights_records_preview = array();
$this->_rights_records_document = []; $this->_rights_records_document = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$currentid = $row["sbas_id"] . "_" . $row["record_id"]; $currentid = $row["sbas_id"] . "_" . $row["record_id"];
@@ -814,10 +815,10 @@ class ACL implements cache_cacheableInterface
$this->_rights_records_preview[$currentid] = $currentid; $this->_rights_records_preview[$currentid] = $currentid;
} }
$datas = [ $datas = array(
'preview' => $this->_rights_records_preview 'preview' => $this->_rights_records_preview
, 'document' => $this->_rights_records_document , 'document' => $this->_rights_records_document
]; );
$this->set_data_to_cache($datas, self::CACHE_RIGHTS_RECORDS); $this->set_data_to_cache($datas, self::CACHE_RIGHTS_RECORDS);
@@ -841,7 +842,7 @@ class ACL implements cache_cacheableInterface
FROM usr WHERE usr_id = :usr_id'; FROM usr WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]); $stmt->execute(array(':usr_id' => $this->user->getId()));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
unset($stmt); unset($stmt);
@@ -878,11 +879,11 @@ class ACL implements cache_cacheableInterface
AND sbas.sbas_id = sbasusr.sbas_id'; AND sbas.sbas_id = sbasusr.sbas_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]); $stmt->execute(array(':usr_id' => $this->user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$this->_rights_sbas = []; $this->_rights_sbas = array();
$this->_global_rights['bas_modif_th'] = false; $this->_global_rights['bas_modif_th'] = false;
$this->_global_rights['bas_modify_struct'] = false; $this->_global_rights['bas_modify_struct'] = false;
@@ -939,11 +940,11 @@ class ACL implements cache_cacheableInterface
AND s.sbas_id = b.sbas_id '; AND s.sbas_id = b.sbas_id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]); $stmt->execute(array(':usr_id' => $this->user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$this->_rights_bas = $this->_limited = []; $this->_rights_bas = $this->_limited = array();
$this->_global_rights['manageusers'] = false; $this->_global_rights['manageusers'] = false;
$this->_global_rights['coll_manage'] = false; $this->_global_rights['coll_manage'] = false;
@@ -1000,10 +1001,10 @@ class ACL implements cache_cacheableInterface
if ($row['time_limited'] == '1' if ($row['time_limited'] == '1'
&& ($row['limited_from'] !== '' || $row['limited_to'] !== '')) { && ($row['limited_from'] !== '' || $row['limited_to'] !== '')) {
$this->_limited[$row['base_id']] = [ $this->_limited[$row['base_id']] = array(
'dmin' => $row['limited_from'] ? new DateTime($row['limited_from']) : null 'dmin' => $row['limited_from'] ? new DateTime($row['limited_from']) : null
, 'dmax' => $row['limited_to'] ? new DateTime($row['limited_to']) : null , 'dmax' => $row['limited_to'] ? new DateTime($row['limited_to']) : null
]; );
} }
$this->_rights_bas[$row['base_id']]['imgtools'] $this->_rights_bas[$row['base_id']]['imgtools']
@@ -1116,10 +1117,10 @@ class ACL implements cache_cacheableInterface
$sql_del = 'DELETE FROM basusr WHERE base_id = :base_id AND usr_id = :usr_id'; $sql_del = 'DELETE FROM basusr WHERE base_id = :base_id AND usr_id = :usr_id';
$stmt_del = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_del); $stmt_del = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_del);
$usr_id = $this->user->get_id(); $usr_id = $this->user->getId();
foreach ($base_ids as $base_id) { foreach ($base_ids as $base_id) {
if (!$stmt_del->execute([':base_id' => $base_id, ':usr_id' => $usr_id])) { if (!$stmt_del->execute(array(':base_id' => $base_id, ':usr_id' => $usr_id))) {
throw new Exception('Error while deleteing some rights'); throw new Exception('Error while deleteing some rights');
} }
} }
@@ -1138,13 +1139,13 @@ class ACL implements cache_cacheableInterface
$sql_ins = 'INSERT INTO basusr (id, base_id, usr_id, actif) $sql_ins = 'INSERT INTO basusr (id, base_id, usr_id, actif)
VALUES (null, :base_id, :usr_id, "1")'; VALUES (null, :base_id, :usr_id, "1")';
$stmt_ins = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_ins); $stmt_ins = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_ins);
$usr_id = $this->user->get_id(); $usr_id = $this->user->getId();
$to_update = []; $to_update = array();
$this->load_rights_bas(); $this->load_rights_bas();
foreach ($base_ids as $base_id) { foreach ($base_ids as $base_id) {
if (!isset($this->_rights_bas[$base_id])) { if (!isset($this->_rights_bas[$base_id])) {
$stmt_ins->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); $stmt_ins->execute(array(':base_id' => $base_id, ':usr_id' => $usr_id));
} elseif ($this->_rights_bas[$base_id]['actif'] === false) { } elseif ($this->_rights_bas[$base_id]['actif'] === false) {
$to_update[] = $base_id; $to_update[] = $base_id;
} }
@@ -1155,7 +1156,7 @@ class ACL implements cache_cacheableInterface
WHERE usr_id = :usr_id AND base_id = :base_id'; WHERE usr_id = :usr_id AND base_id = :base_id';
$stmt_upd = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_upd); $stmt_upd = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_upd);
foreach ($to_update as $base_id) { foreach ($to_update as $base_id) {
$stmt_upd->execute([':usr_id' => $usr_id, ':base_id' => $base_id]); $stmt_upd->execute(array(':usr_id' => $usr_id, ':base_id' => $base_id));
} }
$stmt_upd->closeCursor(); $stmt_upd->closeCursor();
@@ -1175,11 +1176,11 @@ class ACL implements cache_cacheableInterface
$sql_ins = 'INSERT INTO sbasusr (sbasusr_id, sbas_id, usr_id) VALUES (null, :sbas_id, :usr_id)'; $sql_ins = 'INSERT INTO sbasusr (sbasusr_id, sbas_id, usr_id) VALUES (null, :sbas_id, :usr_id)';
$stmt_ins = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_ins); $stmt_ins = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_ins);
$usr_id = $this->user->get_id(); $usr_id = $this->user->getId();
foreach ($sbas_ids as $sbas_id) { foreach ($sbas_ids as $sbas_id) {
if (!$this->has_access_to_sbas($sbas_id)) if (!$this->has_access_to_sbas($sbas_id))
$stmt_ins->execute([':sbas_id' => $sbas_id, ':usr_id' => $usr_id]); $stmt_ins->execute(array(':sbas_id' => $sbas_id, ':usr_id' => $usr_id));
} }
$this->delete_data_from_cache(self::CACHE_RIGHTS_SBAS); $this->delete_data_from_cache(self::CACHE_RIGHTS_SBAS);
@@ -1198,12 +1199,12 @@ class ACL implements cache_cacheableInterface
{ {
if (!$this->has_access_to_base($base_id) && (!isset($rights['actif']) || $rights['actif'] == '1')) { if (!$this->has_access_to_base($base_id) && (!isset($rights['actif']) || $rights['actif'] == '1')) {
$this->give_access_to_base([$base_id]); $this->give_access_to_base(array($base_id));
} }
$sql_up = "UPDATE basusr SET "; $sql_up = "UPDATE basusr SET ";
$sql_args = $params = []; $sql_args = $params = array();
foreach ($rights as $right => $v) { foreach ($rights as $right => $v) {
$sql_args[] = " " . $right . " = :" . $right; $sql_args[] = " " . $right . " = :" . $right;
switch ($right) { switch ($right) {
@@ -1221,14 +1222,14 @@ class ACL implements cache_cacheableInterface
return $this; return $this;
} }
$usr_id = $this->user->get_id(); $usr_id = $this->user->getId();
$sql_up .= implode(', ', $sql_args) . ' WHERE base_id = :base_id $sql_up .= implode(', ', $sql_args) . ' WHERE base_id = :base_id
AND usr_id = :usr_id'; AND usr_id = :usr_id';
$params = array_merge( $params = array_merge(
$params $params
, [':base_id' => $base_id, ':usr_id' => $usr_id] , array(':base_id' => $base_id, ':usr_id' => $usr_id)
); );
$stmt_up = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_up); $stmt_up = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_up);
@@ -1252,8 +1253,8 @@ class ACL implements cache_cacheableInterface
(SELECT distinct sbas_id FROM basusr bu, bas b (SELECT distinct sbas_id FROM basusr bu, bas b
WHERE usr_id = :usr_id_2 AND b.base_id = bu.base_id)'; WHERE usr_id = :usr_id_2 AND b.base_id = bu.base_id)';
$usr_id = $this->user->get_id(); $usr_id = $this->user->getId();
$params = [':usr_id_1' => $usr_id, ':usr_id_2' => $usr_id]; $params = array(':usr_id_1' => $usr_id, ':usr_id_2' => $usr_id);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -1273,13 +1274,13 @@ class ACL implements cache_cacheableInterface
public function update_rights_to_sbas($sbas_id, $rights) public function update_rights_to_sbas($sbas_id, $rights)
{ {
if (!$this->has_access_to_sbas($sbas_id)) if (!$this->has_access_to_sbas($sbas_id))
$this->give_access_to_sbas([$sbas_id]); $this->give_access_to_sbas(array($sbas_id));
$sql_up = "UPDATE sbasusr SET "; $sql_up = "UPDATE sbasusr SET ";
$sql_args = []; $sql_args = array();
$usr_id = $this->user->get_id(); $usr_id = $this->user->getId();
$params = [':sbas_id' => $sbas_id, ':usr_id' => $usr_id]; $params = array(':sbas_id' => $sbas_id, ':usr_id' => $usr_id);
foreach ($rights as $right => $v) { foreach ($rights as $right => $v) {
$sql_args[] = " " . $right . " = :" . $right; $sql_args[] = " " . $right . " = :" . $right;
@@ -1315,7 +1316,7 @@ class ACL implements cache_cacheableInterface
WHERE usr_id = :usr_id AND base_id = :base_id '; WHERE usr_id = :usr_id AND base_id = :base_id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id(), ':base_id' => $base_id]); $stmt->execute(array(':usr_id' => $this->user->getId(), ':base_id' => $base_id));
$stmt->closeCursor(); $stmt->closeCursor();
unset($stmt); unset($stmt);
@@ -1331,13 +1332,13 @@ class ACL implements cache_cacheableInterface
AND usr_id = :usr_id AND usr_id = :usr_id
AND MONTH(lastconn) != MONTH(NOW()) AND restrict_dwnld = 1'; AND MONTH(lastconn) != MONTH(NOW()) AND restrict_dwnld = 1';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]); $stmt->execute(array(':usr_id' => $this->user->getId()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = "UPDATE basusr SET lastconn=now() $sql = "UPDATE basusr SET lastconn=now()
WHERE usr_id = :usr_id AND actif = 1"; WHERE usr_id = :usr_id AND actif = 1";
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]); $stmt->execute(array(':usr_id' => $this->user->getId()));
$stmt->closeCursor(); $stmt->closeCursor();
unset($stmt); unset($stmt);
@@ -1359,12 +1360,12 @@ class ACL implements cache_cacheableInterface
SET remain_dwnld = :restes, restrict_dwnld = 1, month_dwnld_max = :droits SET remain_dwnld = :restes, restrict_dwnld = 1, month_dwnld_max = :droits
WHERE usr_id = :usr_id AND base_id = :base_id '; WHERE usr_id = :usr_id AND base_id = :base_id ';
$params = [ $params = array(
':usr_id' => $this->user->get_id(), ':usr_id' => $this->user->getId(),
':base_id' => $base_id, ':base_id' => $base_id,
':restes' => $restes, ':restes' => $restes,
':droits' => $droits ':droits' => $droits
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -1381,10 +1382,10 @@ class ACL implements cache_cacheableInterface
$sql = 'SELECT * FROM basusr $sql = 'SELECT * FROM basusr
WHERE base_id = :base_from AND usr_id = :usr_id'; WHERE base_id = :base_from AND usr_id = :usr_id';
$params = [ $params = array(
':base_from' => $base_id_from, ':base_from' => $base_id_from,
':usr_id' => $this->user->get_id() ':usr_id' => $this->user->getId()
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -1395,12 +1396,12 @@ class ACL implements cache_cacheableInterface
return $this; return $this;
} }
$this->give_access_to_base([$base_id_dest]); $this->give_access_to_base(array($base_id_dest));
$rights = [ $rights = array(
'mask_and' => $row['mask_and'], 'mask_and' => $row['mask_and'],
'mask_xor' => $row['mask_xor'], 'mask_xor' => $row['mask_xor'],
]; );
if ($row['canputinalbum']) if ($row['canputinalbum'])
$rights['canputinalbum'] = true; $rights['canputinalbum'] = true;
@@ -1470,7 +1471,7 @@ class ACL implements cache_cacheableInterface
foreach ($this->get_granted_base([], [$databox->get_sbas_id()]) as $collection) { foreach ($this->get_granted_base([], [$databox->get_sbas_id()]) as $collection) {
$stmt->execute([ $stmt->execute([
':site_id' => $this->app['conf']->get(['main', 'key']), ':site_id' => $this->app['conf']->get(['main', 'key']),
':usr_id' => $this->user->get_id(), ':usr_id' => $this->user->getId(),
':coll_id' => $collection->get_coll_id(), ':coll_id' => $collection->get_coll_id(),
':mask_and' => $this->get_mask_and($collection->get_base_id()), ':mask_and' => $this->get_mask_and($collection->get_base_id()),
':mask_xor' => $this->get_mask_xor($collection->get_base_id()), ':mask_xor' => $this->get_mask_xor($collection->get_base_id()),
@@ -1496,7 +1497,7 @@ class ACL implements cache_cacheableInterface
{ {
$sql = 'DELETE FROM collusr WHERE usr_id = :usr_id AND site = :site'; $sql = 'DELETE FROM collusr WHERE usr_id = :usr_id AND site = :site';
$params = [ $params = [
':usr_id' => $this->user->get_id() ':usr_id' => $this->user->getId()
, ':site' => $this->app['conf']->get(['main', 'key']) , ':site' => $this->app['conf']->get(['main', 'key'])
]; ];
$stmt = $databox->get_connection()->prepare($sql); $stmt = $databox->get_connection()->prepare($sql);
@@ -1508,13 +1509,13 @@ class ACL implements cache_cacheableInterface
public function set_masks_on_base($base_id, $and_and, $and_or, $xor_and, $xor_or) public function set_masks_on_base($base_id, $and_and, $and_or, $xor_and, $xor_or)
{ {
$vhex = []; $vhex = array();
$datas = [ $datas = array(
'and_and' => $and_and, 'and_and' => $and_and,
'and_or' => $and_or, 'and_or' => $and_or,
'xor_and' => $xor_and, 'xor_and' => $xor_and,
'xor_or' => $xor_or 'xor_or' => $xor_or
]; );
foreach ($datas as $name => $f) { foreach ($datas as $name => $f) {
$vhex[$name] = "0x"; $vhex[$name] = "0x";
@@ -1536,7 +1537,7 @@ class ACL implements cache_cacheableInterface
WHERE usr_id = :usr_id and base_id = :base_id"; WHERE usr_id = :usr_id and base_id = :base_id";
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':base_id' => $base_id, ':usr_id' => $this->user->get_id()]); $stmt->execute(array(':base_id' => $base_id, ':usr_id' => $this->user->getId()));
$stmt->closeCursor(); $stmt->closeCursor();
unset($stmt); unset($stmt);
@@ -1589,12 +1590,12 @@ class ACL implements cache_cacheableInterface
WHERE base_id = :base_id AND usr_id = :usr_id'; WHERE base_id = :base_id AND usr_id = :usr_id';
} }
$params = [ $params = array(
':usr_id' => $this->user->get_id() ':usr_id' => $this->user->getId()
, ':base_id' => $base_id , ':base_id' => $base_id
, 'limited_from' => ($limit_from ? $limit_from->format(DATE_ISO8601) : null) , 'limited_from' => ($limit_from ? $limit_from->format(DATE_ISO8601) : null)
, 'limited_to' => ($limit_to ? $limit_to->format(DATE_ISO8601) : null) , 'limited_to' => ($limit_to ? $limit_to->format(DATE_ISO8601) : null)
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
@@ -1616,11 +1617,11 @@ class ACL implements cache_cacheableInterface
{ {
$sql = 'SELECT base_id FROM basusr WHERE order_master="1" AND usr_id= :usr_id '; $sql = 'SELECT base_id FROM basusr WHERE order_master="1" AND usr_id= :usr_id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]); $stmt->execute(array(':usr_id' => $this->user->getId()));
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$collections = []; $collections = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$collections[] = \collection::get_from_base_id($this->app, $row['base_id']); $collections[] = \collection::get_from_base_id($this->app, $row['base_id']);
@@ -1643,11 +1644,11 @@ class ACL implements cache_cacheableInterface
WHERE usr_id = :usr_id AND base_id = :base_id'; WHERE usr_id = :usr_id AND base_id = :base_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([ $stmt->execute(array(
':master' => $bool ? 1 : 0, ':master' => $bool ? 1 : 0,
':usr_id' => $this->user->get_id(), ':usr_id' => $this->user->getId(),
':base_id' => $collection->get_base_id() ':base_id' => $collection->get_base_id()
]); ));
$stmt->closeCursor(); $stmt->closeCursor();
return $this; return $this;

View File

@@ -11,6 +11,7 @@
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Alchemy\Phrasea\Model\Entities\User;
class API_OAuth2_Account class API_OAuth2_Account
{ {
@@ -28,7 +29,7 @@ class API_OAuth2_Account
/** /**
* *
* @var User_Adapter * @var User
*/ */
protected $user; protected $user;
@@ -78,12 +79,12 @@ class API_OAuth2_Account
WHERE api_account_id = :api_account_id'; WHERE api_account_id = :api_account_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':api_account_id' => $this->id]); $stmt->execute(array(':api_account_id' => $this->id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$this->application_id = (int) $row['application_id']; $this->application_id = (int) $row['application_id'];
$this->user = User_Adapter::getInstance($row['usr_id'], $app); $this->user = $app['manipulator.user']->getRepository()->find($row['usr_id']);
$this->api_version = $row['api_version']; $this->api_version = $row['api_version'];
$this->revoked = ! ! $row['revoked']; $this->revoked = ! ! $row['revoked'];
@@ -103,7 +104,7 @@ class API_OAuth2_Account
/** /**
* *
* @return User_Adapter * @return User
*/ */
public function get_user() public function get_user()
{ {
@@ -140,10 +141,10 @@ class API_OAuth2_Account
$sql = 'UPDATE api_accounts SET revoked = :revoked $sql = 'UPDATE api_accounts SET revoked = :revoked
WHERE api_account_id = :account_id'; WHERE api_account_id = :account_id';
$params = [ $params = array(
':revoked' => ($boolean ? '1' : '0') ':revoked' => ($boolean ? '1' : '0')
, 'account_id' => $this->id , 'account_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -208,26 +209,26 @@ class API_OAuth2_Account
$sql = 'DELETE FROM api_accounts WHERE api_account_id = :account_id'; $sql = 'DELETE FROM api_accounts WHERE api_account_id = :account_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(['account_id' => $this->id]); $stmt->execute(array('account_id' => $this->id));
$stmt->closeCursor(); $stmt->closeCursor();
return; return;
} }
public static function create(Application $app, User_Adapter $user, API_OAuth2_Application $application) public static function create(Application $app, User $user, API_OAuth2_Application $application)
{ {
$sql = 'INSERT INTO api_accounts $sql = 'INSERT INTO api_accounts
(api_account_id, usr_id, revoked, api_version, application_id, created) (api_account_id, usr_id, revoked, api_version, application_id, created)
VALUES (null, :usr_id, :revoked, :api_version, :application_id, :created)'; VALUES (null, :usr_id, :revoked, :api_version, :application_id, :created)';
$datetime = new Datetime(); $datetime = new Datetime();
$params = [ $params = array(
':usr_id' => $user->get_id() ':usr_id' => $user->getId()
, ':application_id' => $application->get_id() , ':application_id' => $application->get_id()
, ':api_version' => API_OAuth2_Adapter::API_VERSION , ':api_version' => API_OAuth2_Adapter::API_VERSION
, ':revoked' => 0 , ':revoked' => 0
, ':created' => $datetime->format("Y-m-d H:i:s") , ':created' => $datetime->format("Y-m-d H:i:s")
]; );
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -238,15 +239,15 @@ class API_OAuth2_Account
return new self($app, $account_id); return new self($app, $account_id);
} }
public static function load_with_user(Application $app, API_OAuth2_Application $application, User_Adapter $user) public static function load_with_user(Application $app, API_OAuth2_Application $application, User $user)
{ {
$sql = 'SELECT api_account_id FROM api_accounts $sql = 'SELECT api_account_id FROM api_accounts
WHERE usr_id = :usr_id AND application_id = :application_id'; WHERE usr_id = :usr_id AND application_id = :application_id';
$params = [ $params = array(
":usr_id" => $user->get_id(), ":usr_id" => $user->getId(),
":application_id" => $application->get_id() ":application_id" => $application->get_id()
]; );
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);

View File

@@ -222,7 +222,7 @@ class API_OAuth2_Adapter extends OAuth2
, 'client_id' => $token->get_account()->get_application()->get_client_id() , 'client_id' => $token->get_account()->get_application()->get_client_id()
, 'session_id' => $token->get_session_id() , 'session_id' => $token->get_session_id()
, 'revoked' => ($token->get_account()->is_revoked() ? '1' : '0') , 'revoked' => ($token->get_account()->is_revoked() ? '1' : '0')
, 'usr_id' => $token->get_account()->get_user()->get_id() , 'usr_id' => $token->get_account()->get_user()->getId()
, 'oauth_token' => $token->get_value() , 'oauth_token' => $token->get_value()
]; ];
@@ -506,7 +506,7 @@ class API_OAuth2_Adapter extends OAuth2
throw new logicalException("Client property must be set before update an account"); throw new logicalException("Client property must be set before update an account");
try { try {
$user = User_Adapter::getInstance($usr_id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($usr_id);
$account = API_OAuth2_Account::load_with_user($this->app, $this->client, $user); $account = API_OAuth2_Account::load_with_user($this->app, $this->client, $user);
} catch (Exception $e) { } catch (Exception $e) {
$account = $this->createAccount($usr_id); $account = $this->createAccount($usr_id);
@@ -522,7 +522,7 @@ class API_OAuth2_Adapter extends OAuth2
*/ */
private function createAccount($usr_id) private function createAccount($usr_id)
{ {
$user = User_Adapter::getInstance($usr_id, $this->app); $user = $this->app['manipulator.user']->getRepository()->find($usr_id);
return API_OAuth2_Account::create($this->app, $user, $this->client); return API_OAuth2_Account::create($this->app, $user, $this->client);
} }

View File

@@ -11,6 +11,7 @@
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Alchemy\Phrasea\Model\Entities\User;
class API_OAuth2_Application class API_OAuth2_Application
{ {
@@ -41,7 +42,7 @@ class API_OAuth2_Application
/** /**
* *
* @var User_Adapter * @var User
*/ */
protected $creator; protected $creator;
@@ -137,7 +138,7 @@ class API_OAuth2_Application
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':application_id' => $this->id]); $stmt->execute(array(':application_id' => $this->id));
if (0 === $stmt->rowCount()) { if (0 === $stmt->rowCount()) {
throw new NotFoundHttpException(sprintf('Application with id %d not found', $this->id)); throw new NotFoundHttpException(sprintf('Application with id %d not found', $this->id));
@@ -145,7 +146,7 @@ class API_OAuth2_Application
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$this->creator = ! $row['creator'] ? null : User_Adapter::getInstance($row['creator'], $this->app); $this->creator = ! $row['creator'] ? null : $this->app['manipulator.user']->getRepository()->find($row['creator']);
$this->type = $row['type']; $this->type = $row['type'];
$this->name = $row['name']; $this->name = $row['name'];
$this->description = $row['description']; $this->description = $row['description'];
@@ -173,7 +174,7 @@ class API_OAuth2_Application
/** /**
* *
* @return User_Adapter * @return User
*/ */
public function get_creator() public function get_creator()
{ {
@@ -205,7 +206,7 @@ class API_OAuth2_Application
*/ */
public function set_type($type) public function set_type($type)
{ {
if ( ! in_array($type, [self::DESKTOP_TYPE, self::WEB_TYPE])) if ( ! in_array($type, array(self::DESKTOP_TYPE, self::WEB_TYPE)))
throw new Exception_InvalidArgument(); throw new Exception_InvalidArgument();
$this->type = $type; $this->type = $type;
@@ -216,10 +217,10 @@ class API_OAuth2_Application
$sql = 'UPDATE api_applications SET type = :type, last_modified = NOW() $sql = 'UPDATE api_applications SET type = :type, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':type' => $this->type ':type' => $this->type
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -249,10 +250,10 @@ class API_OAuth2_Application
$sql = 'UPDATE api_applications SET name = :name, last_modified = NOW() $sql = 'UPDATE api_applications SET name = :name, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':name' => $this->name ':name' => $this->name
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -283,10 +284,10 @@ class API_OAuth2_Application
SET description = :description, last_modified = NOW() SET description = :description, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':description' => $this->description ':description' => $this->description
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -317,10 +318,10 @@ class API_OAuth2_Application
SET website = :website, last_modified = NOW() SET website = :website, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':website' => $this->website ':website' => $this->website
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -351,10 +352,10 @@ class API_OAuth2_Application
SET activated = :activated, last_modified = NOW() SET activated = :activated, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':activated' => $this->activated ':activated' => $this->activated
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -385,10 +386,10 @@ class API_OAuth2_Application
SET grant_password = :grant_password, last_modified = NOW() SET grant_password = :grant_password, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':grant_password' => $this->grant_password ':grant_password' => $this->grant_password
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -437,10 +438,10 @@ class API_OAuth2_Application
SET client_id = :client_id, last_modified = NOW() SET client_id = :client_id, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':client_id' => $this->client_id ':client_id' => $this->client_id
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -471,10 +472,10 @@ class API_OAuth2_Application
SET client_secret = :client_secret, last_modified = NOW() SET client_secret = :client_secret, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':client_secret' => $this->client_secret ':client_secret' => $this->client_secret
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -504,10 +505,10 @@ class API_OAuth2_Application
SET redirect_uri = :redirect_uri, last_modified = NOW() SET redirect_uri = :redirect_uri, last_modified = NOW()
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$params = [ $params = array(
':redirect_uri' => $this->redirect_uri ':redirect_uri' => $this->redirect_uri
, ':application_id' => $this->id , ':application_id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -518,18 +519,18 @@ class API_OAuth2_Application
/** /**
* *
* @param User_Adapter $user * @param User $user
* @return API_OAuth2_Account * @return API_OAuth2_Account
*/ */
public function get_user_account(user_adapter $user) public function get_user_account(User $user)
{ {
$sql = 'SELECT api_account_id FROM api_accounts $sql = 'SELECT api_account_id FROM api_accounts
WHERE usr_id = :usr_id AND application_id = :id'; WHERE usr_id = :usr_id AND application_id = :id';
$params = [ $params = array(
':usr_id' => $user->get_id() ':usr_id' => $user->getId()
, ':id' => $this->id , ':id' => $this->id
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -556,7 +557,7 @@ class API_OAuth2_Application
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':application_id' => $this->get_id()]); $stmt->execute(array(':application_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
return; return;
@@ -572,11 +573,11 @@ class API_OAuth2_Application
WHERE application_id = :application_id'; WHERE application_id = :application_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':application_id' => $this->get_id()]); $stmt->execute(array(':application_id' => $this->get_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$accounts = []; $accounts = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$accounts[] = new API_OAuth2_Account($this->app, $row['api_account_id']); $accounts[] = new API_OAuth2_Account($this->app, $row['api_account_id']);
@@ -588,11 +589,11 @@ class API_OAuth2_Application
/** /**
* *
* @param Application $app * @param Application $app
* @param User_Adapter $user * @param User $user
* @param type $name * @param type $name
* @return API_OAuth2_Application * @return API_OAuth2_Application
*/ */
public static function create(Application $app, User_Adapter $user = null, $name) public static function create(Application $app, User $user = null, $name)
{ {
$sql = ' $sql = '
INSERT INTO api_applications ( INSERT INTO api_applications (
@@ -608,15 +609,15 @@ class API_OAuth2_Application
$client_secret = API_OAuth2_Token::generate_token(); $client_secret = API_OAuth2_Token::generate_token();
$client_token = API_OAuth2_Token::generate_token(); $client_token = API_OAuth2_Token::generate_token();
$params = [ $params = array(
':usr_id' => $user ? $user->get_id() : null, ':usr_id' => $user ? $user->getId() : null,
':name' => $name, ':name' => $name,
':client_id' => $client_token, ':client_id' => $client_token,
':client_secret' => $client_secret, ':client_secret' => $client_secret,
':nonce' => $nonce, ':nonce' => $nonce,
':activated' => 1, ':activated' => 1,
':grant_password' => 0 ':grant_password' => 0
]; );
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -645,7 +646,7 @@ class API_OAuth2_Application
WHERE client_id = :client_id'; WHERE client_id = :client_id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':client_id' => $client_id]); $stmt->execute(array(':client_id' => $client_id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -655,18 +656,18 @@ class API_OAuth2_Application
return new self($app, $row['application_id']); return new self($app, $row['application_id']);
} }
public static function load_dev_app_by_user(Application $app, User_Adapter $user) public static function load_dev_app_by_user(Application $app, User $user)
{ {
$sql = 'SELECT a.application_id $sql = 'SELECT a.application_id
FROM api_applications a, api_accounts b FROM api_applications a, api_accounts b
WHERE a.creator = :usr_id AND a.application_id = b.application_id'; WHERE a.creator = :usr_id AND a.application_id = b.application_id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $user->get_id()]); $stmt->execute(array(':usr_id' => $user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$apps = []; $apps = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$apps[] = new API_OAuth2_Application($app, $row['application_id']); $apps[] = new API_OAuth2_Application($app, $row['application_id']);
} }
@@ -674,18 +675,18 @@ class API_OAuth2_Application
return $apps; return $apps;
} }
public static function load_app_by_user(Application $app, user_adapter $user) public static function load_app_by_user(Application $app, User $user)
{ {
$sql = 'SELECT a.application_id $sql = 'SELECT a.application_id
FROM api_accounts a, api_applications c FROM api_accounts a, api_applications c
WHERE usr_id = :usr_id AND c.application_id = a.application_id'; WHERE usr_id = :usr_id AND c.application_id = a.application_id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $user->get_id()]); $stmt->execute(array(':usr_id' => $user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$apps = []; $apps = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$apps[] = new API_OAuth2_Application($app, $row['application_id']); $apps[] = new API_OAuth2_Application($app, $row['application_id']);
} }
@@ -693,7 +694,7 @@ class API_OAuth2_Application
return $apps; return $apps;
} }
public static function load_authorized_app_by_user(Application $app, user_adapter $user) public static function load_authorized_app_by_user(Application $app, User $user)
{ {
$sql = ' $sql = '
SELECT a.application_id SELECT a.application_id
@@ -702,11 +703,11 @@ class API_OAuth2_Application
AND revoked = 0'; AND revoked = 0';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $user->get_id()]); $stmt->execute(array(':usr_id' => $user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$apps = []; $apps = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$apps[] = new API_OAuth2_Application($app, $row['application_id']); $apps[] = new API_OAuth2_Application($app, $row['application_id']);
} }

View File

@@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\User;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Silex\Application; use Silex\Application;
@@ -199,7 +199,7 @@ interface API_V1_Interface
* BASKET_ID : required INT * BASKET_ID : required INT
* *
*/ */
public function delete_basket(Request $request, Basket $basket); public function delete_basket(Request $request, $basket_id);
/** /**
* Route : /baskets/BASKET_ID/content/FORMAT/ * Route : /baskets/BASKET_ID/content/FORMAT/
@@ -210,7 +210,7 @@ interface API_V1_Interface
* BASKET_ID : required INT * BASKET_ID : required INT
* *
*/ */
public function get_basket(Request $request, Basket $basket); public function get_basket(Request $request, $basket_id);
/** /**
* Route : /baskets/BASKET_ID/title/FORMAT/ * Route : /baskets/BASKET_ID/title/FORMAT/
@@ -221,7 +221,7 @@ interface API_V1_Interface
* BASKET_ID : required INT * BASKET_ID : required INT
* *
*/ */
public function set_basket_title(Request $request, Basket $basket); public function set_basket_title(Request $request, $basket_id);
/** /**
* Route : /baskets/BASKET_ID/description/FORMAT/ * Route : /baskets/BASKET_ID/description/FORMAT/
@@ -232,7 +232,7 @@ interface API_V1_Interface
* BASKET_ID : required INT * BASKET_ID : required INT
* *
*/ */
public function set_basket_description(Request $request, Basket $basket); public function set_basket_description(Request $request, $basket_id);
/** /**
* Route : /publications/list/FORMAT/ * Route : /publications/list/FORMAT/
@@ -242,7 +242,7 @@ interface API_V1_Interface
* Parameters : * Parameters :
* *
*/ */
public function search_publications(Request $request, User_Adapter $user); public function search_publications(Request $request, User $user);
/** /**
* Route : /publications/PUBLICATION_ID/remove/FORMAT/ * Route : /publications/PUBLICATION_ID/remove/FORMAT/
@@ -264,11 +264,11 @@ interface API_V1_Interface
* PUBLICATION_ID : required INT * PUBLICATION_ID : required INT
* *
*/ */
public function get_publication(Request $request, $publication_id, User_Adapter $user); public function get_publication(Request $request, $publication_id, User $user);
public function get_publications(Request $request, User_Adapter $user); public function get_publications(Request $request, User $user);
public function get_feed_entry(Request $request, $entry, User_Adapter $user); public function get_feed_entry(Request $request, $entry, User $user);
/** /**
* Route : /users/search/FORMAT/ * Route : /users/search/FORMAT/
* *

File diff suppressed because it is too large Load Diff

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
class Bridge_Account class Bridge_Account
{ {
@@ -39,7 +40,7 @@ class Bridge_Account
/** /**
* *
* @var User_Adapter * @var User
*/ */
protected $user; protected $user;
@@ -86,7 +87,7 @@ class Bridge_Account
FROM bridge_accounts WHERE id = :id'; FROM bridge_accounts WHERE id = :id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':id' => $this->id]); $stmt->execute(array(':id' => $this->id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -94,7 +95,7 @@ class Bridge_Account
throw new Bridge_Exception_AccountNotFound('Account Not Found'); throw new Bridge_Exception_AccountNotFound('Account Not Found');
$this->dist_id = $row['dist_id']; $this->dist_id = $row['dist_id'];
$this->user = User_Adapter::getInstance($row['usr_id'], $this->app); $this->user = $this->app['manipulator.user']->getRepository()->find($row['usr_id']);
$this->name = $row['name']; $this->name = $row['name'];
$this->updated_on = new DateTime($row['updated_on']); $this->updated_on = new DateTime($row['updated_on']);
$this->created_on = new DateTime($row['created_on']); $this->created_on = new DateTime($row['created_on']);
@@ -143,7 +144,7 @@ class Bridge_Account
/** /**
* *
* @return User_Adapter * @return User
*/ */
public function get_user() public function get_user()
{ {
@@ -190,11 +191,11 @@ class Bridge_Account
$sql = 'UPDATE bridge_accounts $sql = 'UPDATE bridge_accounts
SET name = :name, updated_on = :update WHERE id = :id'; SET name = :name, updated_on = :update WHERE id = :id';
$params = [ $params = array(
':name' => $this->name ':name' => $this->name
, ':id' => $this->id , ':id' => $this->id
, ':update' => $this->updated_on->format(DATE_ISO8601) , ':update' => $this->updated_on->format(DATE_ISO8601)
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -219,7 +220,7 @@ class Bridge_Account
$sql = 'DELETE FROM bridge_accounts WHERE id = :id'; $sql = 'DELETE FROM bridge_accounts WHERE id = :id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':id' => $this->id]); $stmt->execute(array(':id' => $this->id));
$stmt->closeCursor(); $stmt->closeCursor();
return; return;
@@ -236,7 +237,7 @@ class Bridge_Account
$sql = 'SELECT id, api_id FROM bridge_accounts WHERE id = :account_id'; $sql = 'SELECT id, api_id FROM bridge_accounts WHERE id = :account_id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':account_id' => $account_id]); $stmt->execute(array(':account_id' => $account_id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -253,20 +254,20 @@ class Bridge_Account
* *
* @param Application $app * @param Application $app
* @param Bridge_Api $api * @param Bridge_Api $api
* @param User_Adapter $user * @param User $user
* @param string $distant_id * @param string $distant_id
* @return Bridge_Account * @return Bridge_Account
*/ */
public static function load_account_from_distant_id(Application $app, Bridge_Api $api, User_Adapter $user, $distant_id) public static function load_account_from_distant_id(Application $app, Bridge_Api $api, User $user, $distant_id)
{ {
$sql = 'SELECT id FROM bridge_accounts $sql = 'SELECT id FROM bridge_accounts
WHERE api_id = :api_id AND usr_id = :usr_id AND dist_id = :dist_id'; WHERE api_id = :api_id AND usr_id = :usr_id AND dist_id = :dist_id';
$params = [ $params = array(
':api_id' => $api->get_id() ':api_id' => $api->get_id()
, ':usr_id' => $user->get_id() , ':usr_id' => $user->getId()
, ':dist_id' => $distant_id , ':dist_id' => $distant_id
]; );
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -292,11 +293,11 @@ class Bridge_Account
LIMIT 0,' . (int) $quantity; LIMIT 0,' . (int) $quantity;
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':api_id' => $api->get_id()]); $stmt->execute(array(':api_id' => $api->get_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$results = []; $results = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$results[] = new Bridge_Account($app, $api, $row['id']); $results[] = new Bridge_Account($app, $api, $row['id']);
@@ -308,20 +309,20 @@ class Bridge_Account
/** /**
* *
* @param Application $app * @param Application $app
* @param user_adapter $user * @param User $user
* @return Bridge_Account * @return Bridge_Account
*/ */
public static function get_accounts_by_user(Application $app, user_adapter $user) public static function get_accounts_by_user(Application $app, User $user)
{ {
$sql = 'SELECT id, api_id FROM bridge_accounts WHERE usr_id = :usr_id'; $sql = 'SELECT id, api_id FROM bridge_accounts WHERE usr_id = :usr_id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $user->get_id()]); $stmt->execute(array(':usr_id' => $user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$results = []; $results = array();
$apis = []; $apis = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$api_id = $row['api_id']; $api_id = $row['api_id'];
@@ -342,24 +343,24 @@ class Bridge_Account
* *
* @param Application $app * @param Application $app
* @param Bridge_Api $api * @param Bridge_Api $api
* @param User_Adapter $user * @param User $user
* @param string $dist_id * @param string $dist_id
* @param string $name * @param string $name
* *
* @return Bridge_Account * @return Bridge_Account
*/ */
public static function create(Application $app, Bridge_Api $api, User_Adapter $user, $dist_id, $name) public static function create(Application $app, Bridge_Api $api, User $user, $dist_id, $name)
{ {
$sql = 'INSERT INTO bridge_accounts $sql = 'INSERT INTO bridge_accounts
(id, api_id, dist_id, usr_id, name, created_on, updated_on) (id, api_id, dist_id, usr_id, name, created_on, updated_on)
VALUES (null, :api_id, :dist_id, :usr_id, :name, NOW(), NOW())'; VALUES (null, :api_id, :dist_id, :usr_id, :name, NOW(), NOW())';
$params = [ $params = array(
':api_id' => $api->get_id() ':api_id' => $api->get_id()
, ':dist_id' => $dist_id , ':dist_id' => $dist_id
, ':usr_id' => $user->get_id() , ':usr_id' => $user->getId()
, ':name' => $name , ':name' => $name
]; );
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);

View File

@@ -96,10 +96,10 @@ class Session_Logger
*/ */
public static function create(Application $app, databox $databox, Browser $browser) public static function create(Application $app, databox $databox, Browser $browser)
{ {
$colls = []; $colls = array();
if ($app['authentication']->getUser()) { if ($app['authentication']->getUser()) {
$bases = $app['acl']->get($app['authentication']->getUser())->get_granted_base([], [$databox->get_sbas_id()]); $bases = $app['acl']->get($app['authentication']->getUser())->get_granted_base(array(), array($databox->get_sbas_id()));
foreach ($bases as $collection) { foreach ($bases as $collection) {
$colls[] = $collection->get_coll_id(); $colls[] = $collection->get_coll_id();
} }
@@ -116,23 +116,23 @@ class Session_Logger
, :browser, :browser_version, :platform, :screen, :ip , :browser, :browser_version, :platform, :screen, :ip
, :user_agent, :appli, :fonction, :company, :activity, :country)"; , :user_agent, :appli, :fonction, :company, :activity, :country)";
$params = [ $params = array(
':ses_id' => $app['session']->get('session_id'), ':ses_id' => $app['session']->get('session_id'),
':usr_login' => $app['authentication']->getUser() ? $app['authentication']->getUser()->get_login() : null, ':usr_login' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getLogin() : null,
':site_id' => $app['conf']->get(['main', 'key']), ':site_id' => $app['conf']->get(['main', 'key']),
':usr_id' => $app['authentication']->isAuthenticated() ? $app['authentication']->getUser()->get_id() : null, ':usr_id' => $app['authentication']->isAuthenticated() ? $app['authentication']->getUser()->getId() : null,
':browser' => $browser->getBrowser(), ':browser' => $browser->getBrowser(),
':browser_version' => $browser->getExtendedVersion(), ':browser_version' => $browser->getExtendedVersion(),
':platform' => $browser->getPlatform(), ':platform' => $browser->getPlatform(),
':screen' => $browser->getScreenSize(), ':screen' => $browser->getScreenSize(),
':ip' => $browser->getIP(), ':ip' => $browser->getIP(),
':user_agent' => $browser->getUserAgent(), ':user_agent' => $browser->getUserAgent(),
':appli' => serialize([]), ':appli' => serialize(array()),
':fonction' => $app['authentication']->getUser() ? $app['authentication']->getUser()->get_job() : null, ':fonction' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getJob() : null,
':company' => $app['authentication']->getUser() ? $app['authentication']->getUser()->get_company() : null, ':company' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getCompany() : null,
':activity' => $app['authentication']->getUser() ? $app['authentication']->getUser()->get_position() : null, ':activity' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getActivity() : null,
':country' => $app['authentication']->getUser() ? $app['authentication']->getUser()->get_country() : null ':country' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getCountry() : null
]; );
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -143,10 +143,10 @@ class Session_Logger
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
foreach ($colls as $collId) { foreach ($colls as $collId) {
$stmt->execute([ $stmt->execute(array(
':log_id' => $log_id, ':log_id' => $log_id,
':coll_id' => $collId ':coll_id' => $collId
]); ));
} }
$stmt->closeCursor(); $stmt->closeCursor();
@@ -165,7 +165,7 @@ class Session_Logger
WHERE site = :site AND sit_session = :ses_id'; WHERE site = :site AND sit_session = :ses_id';
$params = [ $params = [
':site' => $app['conf']->get(['main', 'key']) ':site' => $app['conf']->get(['main', 'key']),
, ':ses_id' => $app['session']->get('session_id') , ':ses_id' => $app['session']->get('session_id')
]; ];
@@ -205,11 +205,7 @@ class Session_Logger
$app['EM']->flush(); $app['EM']->flush();
} }
$usrId = $app['authentication']->getUser()->get_id(); $appName = array(
$user = User_Adapter::getInstance($usrId, $app);
$appName = [
'1' => 'Prod', '1' => 'Prod',
'2' => 'Client', '2' => 'Client',
'3' => 'Admin', '3' => 'Admin',
@@ -219,10 +215,10 @@ class Session_Logger
'7' => 'Validate', '7' => 'Validate',
'8' => 'Upload', '8' => 'Upload',
'9' => 'API' '9' => 'API'
]; );
if (isset($appName[$appId])) { if (isset($appName[$appId])) {
$sbas_ids = array_keys($app['acl']->get($user)->get_granted_sbas()); $sbas_ids = array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_sbas());
foreach ($sbas_ids as $sbas_id) { foreach ($sbas_ids as $sbas_id) {
try { try {
@@ -231,7 +227,7 @@ class Session_Logger
$connbas = connection::getPDOConnection($app, $sbas_id); $connbas = connection::getPDOConnection($app, $sbas_id);
$sql = 'SELECT appli FROM log WHERE id = :log_id'; $sql = 'SELECT appli FROM log WHERE id = :log_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute([':log_id' => $logger->get_id()]); $stmt->execute(array(':log_id' => $logger->get_id()));
$row3 = $stmt->fetch(PDO::FETCH_ASSOC); $row3 = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -245,10 +241,10 @@ class Session_Logger
$sql = 'UPDATE log SET appli = :applis WHERE id = :log_id'; $sql = 'UPDATE log SET appli = :applis WHERE id = :log_id';
$params = [ $params = array(
':applis' => serialize($applis) ':applis' => serialize($applis)
, ':log_id' => $logger->get_id() , ':log_id' => $logger->get_id()
]; );
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute($params); $stmt->execute($params);

View File

@@ -39,13 +39,13 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
* *
* @var array * @var array
*/ */
protected static $_instance = []; protected static $_instance = array();
/** /**
* *
* @var array * @var array
*/ */
protected $_prefs = []; protected $_prefs = array();
/** /**
* *
@@ -57,14 +57,14 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
* *
* @var array * @var array
*/ */
public static $def_values = [ public static $def_values = array(
'view' => 'thumbs', 'view' => 'thumbs',
'images_per_page' => 20, 'images_per_page' => 20,
'images_size' => 120, 'images_size' => 120,
'editing_images_size' => 134, 'editing_images_size' => 134,
'editing_top_box' => 30, 'editing_top_box' => '180px',
'editing_right_box' => 48, 'editing_right_box' => '400px',
'editing_left_box' => 33, 'editing_left_box' => '710px',
'basket_sort_field' => 'name', 'basket_sort_field' => 'name',
'basket_sort_order' => 'ASC', 'basket_sort_order' => 'ASC',
'warning_on_delete_story' => 'true', 'warning_on_delete_story' => 'true',
@@ -80,21 +80,21 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
'basket_caption_display' => '0', 'basket_caption_display' => '0',
'basket_status_display' => '0', 'basket_status_display' => '0',
'basket_title_display' => '0' 'basket_title_display' => '0'
]; );
/** /**
* *
* @var array * @var array
*/ */
protected static $available_values = [ protected static $available_values = array(
'view' => ['thumbs', 'list'], 'view' => array('thumbs', 'list'),
'basket_sort_field' => ['name', 'date'], 'basket_sort_field' => array('name', 'date'),
'basket_sort_order' => ['ASC', 'DESC'], 'basket_sort_order' => array('ASC', 'DESC'),
'start_page' => ['PUBLI', 'QUERY', 'LAST_QUERY', 'HELP'], 'start_page' => array('PUBLI', 'QUERY', 'LAST_QUERY', 'HELP'),
'technical_display' => ['0', '1', 'group'], 'technical_display' => array('0', '1', 'group'),
'rollover_thumbnail' => ['caption', 'preview'], 'rollover_thumbnail' => array('caption', 'preview'),
'bask_val_order' => ['nat', 'asc', 'desc'] 'bask_val_order' => array('nat', 'asc', 'desc')
]; );
/** /**
* *
@@ -326,18 +326,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return array_key_exists($id, self::$_instance) ? self::$_instance[$id] : false; return array_key_exists($id, self::$_instance) ? self::$_instance[$id] : false;
} }
/**
*
* @param Application $app
*/
protected function set_app(Application $app)
{
$this->app = $app;
if (null !== $app['acl']->get($this)) {
$app['acl']->get($this)->set_app($app);
}
}
/** /**
* *
* @param type $pasword * @param type $pasword
@@ -351,7 +339,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$password = $this->app['auth.password-encoder']->encodePassword($pasword, $this->get_nonce()); $password = $this->app['auth.password-encoder']->encodePassword($pasword, $this->get_nonce());
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':password' => $password, ':usr_id' => $this->get_id()]); $stmt->execute(array(':password' => $password, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->password = $password; $this->password = $password;
@@ -378,7 +366,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$sql = 'UPDATE usr SET usr_mail = :new_email WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET usr_mail = :new_email WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':new_email' => $email, ':usr_id' => $this->get_id()]); $stmt->execute(array(':new_email' => $email, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->email = $email; $this->email = $email;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -386,50 +374,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return $this; return $this;
} }
/**
*
* @return string
*/
public function get_country()
{
if ($this->geonameid) {
try {
$country = $this->app['geonames.connector']
->geoname($this->geonameid)
->get('country');
if (isset($country['name'])) {
return $country['name'];
}
} catch (GeonamesExceptionInterface $e) {
}
}
return '';
}
/**
*
* @param Application $app
* @param string $login
*
* @return integer
*/
public static function get_usr_id_from_login(Application $app, $login)
{
$conn = connection::getPDOConnection($app);
$sql = 'SELECT usr_id FROM usr WHERE usr_login = :login';
$stmt = $conn->prepare($sql);
$stmt->execute([':login' => trim($login)]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$usr_id = $row ? (int) $row['usr_id'] : false;
return $usr_id;
}
/** /**
* *
* @param bollean $boolean * @param bollean $boolean
@@ -440,7 +384,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$value = $boolean ? '1' : '0'; $value = $boolean ? '1' : '0';
$sql = 'UPDATE usr SET mail_notifications = :mail_notifications WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET mail_notifications = :mail_notifications WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':mail_notifications' => $value, ':usr_id' => $this->get_id()]); $stmt->execute(array(':mail_notifications' => $value, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->mail_notifications = !!$boolean; $this->mail_notifications = !!$boolean;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -458,7 +402,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$value = $boolean ? '1' : '0'; $value = $boolean ? '1' : '0';
$sql = 'UPDATE usr SET ldap_created = :ldap_created WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET ldap_created = :ldap_created WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':ldap_created' => $value, ':usr_id' => $this->get_id()]); $stmt->execute(array(':ldap_created' => $value, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->ldap_created = $boolean; $this->ldap_created = $boolean;
@@ -469,7 +413,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET usr_prenom = :usr_prenom WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET usr_prenom = :usr_prenom WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_prenom' => $firstname, ':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_prenom' => $firstname, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->firstname = $firstname; $this->firstname = $firstname;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -481,7 +425,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET usr_nom = :usr_nom WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET usr_nom = :usr_nom WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_nom' => $lastname, ':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_nom' => $lastname, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->lastname = $lastname; $this->lastname = $lastname;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -493,7 +437,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET adresse = :adresse WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET adresse = :adresse WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':adresse' => $address, ':usr_id' => $this->get_id()]); $stmt->execute(array(':adresse' => $address, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->address = $address; $this->address = $address;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -505,7 +449,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET ville = :city WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET ville = :city WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':city' => $city, ':usr_id' => $this->get_id()]); $stmt->execute(array(':city' => $city, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->city = $city; $this->city = $city;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -531,11 +475,11 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$sql = 'UPDATE usr SET geonameid = :geonameid, pays=:country_code WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET geonameid = :geonameid, pays=:country_code WHERE usr_id = :usr_id';
$datas = [ $datas = array(
':geonameid' => $geonameid, ':geonameid' => $geonameid,
':usr_id' => $this->get_id(), ':usr_id' => $this->get_id(),
':country_code' => $country_code ':country_code' => $country_code
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($datas); $stmt->execute($datas);
@@ -551,7 +495,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET cpostal = :cpostal WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET cpostal = :cpostal WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':cpostal' => $zip, ':usr_id' => $this->get_id()]); $stmt->execute(array(':cpostal' => $zip, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->zip = $zip; $this->zip = $zip;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -563,7 +507,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET usr_sexe = :usr_sexe WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET usr_sexe = :usr_sexe WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_sexe' => $gender, ':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_sexe' => $gender, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->gender = $gender; $this->gender = $gender;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -575,7 +519,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET tel = :tel WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET tel = :tel WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':tel' => $tel, ':usr_id' => $this->get_id()]); $stmt->execute(array(':tel' => $tel, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->tel = $tel; $this->tel = $tel;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -587,7 +531,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET fax = :fax WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET fax = :fax WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':fax' => $fax, ':usr_id' => $this->get_id()]); $stmt->execute(array(':fax' => $fax, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->fax = $fax; $this->fax = $fax;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -599,7 +543,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET fonction = :fonction WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET fonction = :fonction WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':fonction' => $job, ':usr_id' => $this->get_id()]); $stmt->execute(array(':fonction' => $job, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->job = $job; $this->job = $job;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -611,7 +555,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET activite = :activite WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET activite = :activite WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':activite' => $position, ':usr_id' => $this->get_id()]); $stmt->execute(array(':activite' => $position, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->position = $position; $this->position = $position;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -623,7 +567,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET societe = :company WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET societe = :company WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':company' => $company, ':usr_id' => $this->get_id()]); $stmt->execute(array(':company' => $company, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->company = $company; $this->company = $company;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -641,7 +585,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$sql = 'UPDATE usr SET model_of = :owner_id WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET model_of = :owner_id WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':owner_id' => $owner->get_id(), ':usr_id' => $this->get_id()]); $stmt->execute(array(':owner_id' => $owner->get_id(), ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this $this
@@ -669,62 +613,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return $this; return $this;
} }
/**
* @return FtpCredential
*/
public function getFtpCredential()
{
if (null === $this->ftpCredential) {
$this->ftpCredential = $this->app['EM']->getRepository('Phraseanet:FtpCredential')->findOneBy([
'usrId' => $this->get_id()
]);
if (null === $this->ftpCredential) {
$this->ftpCredential = new FtpCredential();
$this->ftpCredential->setUsrId($this->get_id());
}
}
return $this->ftpCredential;
}
public function is_template()
{
return $this->is_template;
}
public function is_special()
{
return in_array($this->login, ['invite', 'autoregister']);
}
public function get_template_owner()
{
return $this->template_owner;
}
public static function get_usr_id_from_email(Application $app, $email)
{
if (is_null($email)) {
return false;
}
$conn = connection::getPDOConnection($app);
$sql = 'SELECT usr_id FROM usr
WHERE usr_mail = :email
AND usr_login NOT LIKE "(#deleted_%"
AND invite="0" AND usr_login != "autoregister"';
$stmt = $conn->prepare($sql);
$stmt->execute([':email' => trim($email)]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$usr_id = $row ? $row['usr_id'] : false;
return $usr_id;
}
/** /**
* @todo close all open session * @todo close all open session
* @return type * @return type
@@ -757,37 +645,37 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$sql = 'UPDATE usr SET usr_login = :usr_login , usr_mail = null $sql = 'UPDATE usr SET usr_login = :usr_login , usr_mail = null
WHERE usr_id = :usr_id'; WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_login' => '(#deleted_' . $this->get_login() . '_' . $this->get_id(), ':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_login' => '(#deleted_' . $this->get_login() . '_' . $this->get_id(), ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = 'DELETE FROM basusr WHERE usr_id = :usr_id'; $sql = 'DELETE FROM basusr WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = 'DELETE FROM sbasusr WHERE usr_id = :usr_id'; $sql = 'DELETE FROM sbasusr WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = 'DELETE FROM dsel WHERE usr_id = :usr_id'; $sql = 'DELETE FROM dsel WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = 'DELETE FROM edit_presets WHERE usr_id = :usr_id'; $sql = 'DELETE FROM edit_presets WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = 'DELETE FROM tokens WHERE usr_id = :usr_id'; $sql = 'DELETE FROM tokens WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = 'DELETE FROM usr_settings WHERE usr_id = :usr_id'; $sql = 'DELETE FROM usr_settings WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]); $stmt->execute(array(':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
unset(self::$_instance[$this->get_id()]); unset(self::$_instance[$this->get_id()]);
@@ -813,7 +701,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
FROM usr WHERE usr_id= :id '; FROM usr WHERE usr_id= :id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':id' => $id]); $stmt->execute(array(':id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -866,10 +754,10 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET lastModel = :template_id WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET lastModel = :template_id WHERE usr_id = :usr_id';
$params = [ $params = array(
':usr_id' => $this->get_id() ':usr_id' => $this->get_id()
, ':template_id' => $template->get_login() , ':template_id' => $template->get_login()
]; );
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
@@ -883,207 +771,13 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$sql = 'UPDATE usr SET mail_locked = :mail_locked WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET mail_locked = :mail_locked WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id(), ':mail_locked' => ($boolean ? '1' : '0')]); $stmt->execute(array(':usr_id' => $this->get_id(), ':mail_locked' => ($boolean ? '1' : '0')));
$stmt->closeCursor(); $stmt->closeCursor();
$this->mail_locked = !!$boolean; $this->mail_locked = !!$boolean;
return $this; return $this;
} }
public function get_mail_locked()
{
return $this->mail_locked;
}
/**
*
* @return int
*/
public function get_id()
{
return $this->id;
}
public function get_ldap_created()
{
return $this->ldap_created;
}
public function is_guest()
{
return $this->is_guest;
}
public function get_login()
{
return $this->login;
}
public function get_password()
{
return $this->password;
}
public function get_email()
{
return $this->email;
}
public function get_firstname()
{
return $this->firstname;
}
public function get_lastname()
{
return $this->lastname;
}
public function get_company()
{
return $this->company;
}
public function get_tel()
{
return $this->tel;
}
public function get_fax()
{
return $this->fax;
}
public function get_job()
{
return $this->job;
}
public function get_position()
{
return $this->position;
}
public function get_zipcode()
{
return $this->zip;
}
public function get_city()
{
return $this->city;
}
public function get_address()
{
return $this->address;
}
public function get_gender()
{
return $this->gender;
}
public function get_geonameid()
{
return $this->geonameid;
}
public function get_last_connection()
{
$sql = 'SELECT last_conn FROM usr WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$date_obj = new DateTime($row['last_conn']);
return $date_obj;
}
public function get_applied_template()
{
return $this->applied_template;
}
public function get_creation_date()
{
return $this->creationdate;
}
public function get_modification_date()
{
return $this->modificationdate;
}
protected function load_preferences()
{
if ($this->preferences_loaded) {
return $this;
}
foreach (self::$def_values as $k => $v) {
if (!isset($this->_prefs[$k])) {
if ($k == 'start_page_query' && $this->app['conf']->get(['registry', 'searchengine', 'default-query'])) {
$v = $this->app['conf']->get(['registry', 'searchengine', 'default-query']);
}
$this->_prefs[$k] = $v;
}
}
if ($this->app['conf']->has('user-settings')) {
$this->_prefs = array_replace(
$this->_prefs,
// remove keys that are not defined in default values
array_intersect_key(
$this->app['conf']->get('user-settings'),
self::$def_values
)
);
}
$sql = 'SELECT prop, value FROM usr_settings WHERE usr_id= :id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':id' => $this->id]);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
$this->_prefs[$row['prop']] = $row['value'];
}
$this->preferences_loaded = true;
return $this;
}
public function purgePreferences()
{
$this->notifications_preferences_loaded = $this->preferences_loaded = false;
}
protected function load_notifications_preferences(Application $app)
{
$this->load_preferences();
$notifications = $app['events-manager']->list_notifications_available($this->id);
foreach ($notifications as $notification_group => $nots) {
foreach ($nots as $notification) {
if (!isset($this->_prefs['notification_' . $notification['id']])) {
$this->_prefs['notification_' . $notification['id']] = '1';
}
}
}
$this->notifications_preferences_loaded = true;
}
public function get_notifications_preference(Application $app, $notification_id) public function get_notifications_preference(Application $app, $notification_id)
{ {
if (!$this->notifications_preferences_loaded) if (!$this->notifications_preferences_loaded)
@@ -1105,40 +799,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return ; return ;
} }
public function get_display_name()
{
if ($this->is_template())
$display_name = $this->app->trans('modele %name%', ['%name%' => $this->get_login()]);
elseif (trim($this->lastname) !== '' || trim($this->firstname) !== '')
$display_name = $this->firstname . ' ' . $this->lastname;
elseif (trim($this->email) !== '')
$display_name = $this->email;
else
$display_name = $this->app->trans('phraseanet::utilisateur inconnu');
return $display_name;
}
protected function update_pref($prop, $value)
{
try {
$sql = 'REPLACE INTO usr_settings (usr_id, prop, value)
VALUES (:usr_id, :prop, :value)';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([
':usr_id' => $this->id,
':prop' => $prop,
':value' => $value
]);
$this->delete_data_from_cache();
} catch (Exception $e) {
}
return $this;
}
public function get_cache_key($option = null) public function get_cache_key($option = null)
{ {
return '_user_' . $this->get_id() . ($option ? '_' . $option : ''); return '_user_' . $this->get_id() . ($option ? '_' . $option : '');
@@ -1195,32 +855,12 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return array_key_exists($prop, $this->_prefs) ? $this->_prefs[$prop] : $default; return array_key_exists($prop, $this->_prefs) ? $this->_prefs[$prop] : $default;
} }
public static function get_sys_admins(Application $app)
{
$sql = 'SELECT usr_id, usr_login FROM usr
WHERE create_db="1"
AND model_of="0"
AND usr_login NOT LIKE "(#deleted%"';
$conn = connection::getPDOConnection($app);
$stmt = $conn->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$users = [];
foreach ($rs as $row)
$users[$row['usr_id']] = $row['usr_login'];
return $users;
}
public static function set_sys_admins(Application $app, $admins) public static function set_sys_admins(Application $app, $admins)
{ {
try { try {
$sql = "UPDATE usr SET create_db='0' WHERE create_db='1' AND usr_id != :usr_id"; $sql = "UPDATE usr SET create_db='0' WHERE create_db='1' AND usr_id != :usr_id";
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $app['authentication']->getUser()->get_id()]); $stmt->execute(array(':usr_id' => $app['authentication']->getUser()->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = "UPDATE usr SET create_db='1' WHERE usr_id IN (" . implode(',', $admins) . ")"; $sql = "UPDATE usr SET create_db='1' WHERE usr_id IN (" . implode(',', $admins) . ")";
@@ -1249,7 +889,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$sql = 'UPDATE usr SET locale = :locale WHERE usr_id = :usr_id'; $sql = 'UPDATE usr SET locale = :locale WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':locale' => $locale, ':usr_id' => $this->get_id()]); $stmt->execute(array(':locale' => $locale, ':usr_id' => $this->get_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->delete_data_from_cache(); $this->delete_data_from_cache();
@@ -1258,88 +898,11 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return $this->locale; return $this->locale;
} }
public static function create(Application $app, $login, $password, $email, $admin, $invite = false)
{
$conn = $app['phraseanet.appbox']->get_connection();
if (trim($login) == '') {
throw new \InvalidArgumentException('Invalid username');
}
if (strlen($login) > 100) {
throw new \InvalidArgumentException('Username is too long');
}
if (trim($password) == '') {
throw new \InvalidArgumentException('Invalid password');
}
$login = $invite ? 'invite' . random::generatePassword(16) : $login;
$nonce = random::generatePassword(16);
$sql = 'INSERT INTO usr
(usr_id, usr_login, usr_password, usr_creationdate, usr_mail, create_db, nonce, salted_password, invite)
VALUES (null, :login, :password, NOW(), :email, :admin, :nonce, 1, :invite)';
$stmt = $conn->prepare($sql);
$stmt->execute([
':login' => $login,
':nonce' => $nonce,
':password' => $app['auth.password-encoder']->encodePassword($password, $nonce),
':email' => ($email ? $email : null),
':admin' => ($admin ? '1' : '0'),
':invite' => ($invite ? '1' : '0')
]);
$stmt->closeCursor();
$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 = :login
WHERE usr_id = :usr_id';
$stmt = $conn->prepare($sql);
$stmt->execute([':login' => 'invite'.$usr_id, ':usr_id' => $usr_id]);
$stmt->closeCursor();
}
return self::getInstance($usr_id, $app);
}
protected $nonce;
public function get_nonce()
{
if ($this->nonce) {
return $this->nonce;
}
$nonce = false;
$sql = 'SELECT nonce FROM usr WHERE usr_id = :usr_id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->get_id()]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
unset($stmt);
$nonce = $row['nonce'];
$this->nonce = $nonce;
return $this->nonce;
}
public function __sleep() public function __sleep()
{ {
$vars = []; $vars = array();
foreach ($this as $key => $value) { foreach ($this as $key => $value) {
if (in_array($key, ['ACL', 'app'])) if (in_array($key, array('ACL', 'app')))
continue; continue;
$vars[] = $key; $vars[] = $key;
} }

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
class User_Query implements User_QueryInterface class User_Query implements User_QueryInterface
@@ -231,11 +232,11 @@ class User_Query implements User_QueryInterface
if (!$this->app['authentication']->getUser()) { if (!$this->app['authentication']->getUser()) {
throw new InvalidArgumentException('Unable to load templates while disconnected'); throw new InvalidArgumentException('Unable to load templates while disconnected');
} }
$sql .= ' AND model_of = ' . $this->app['authentication']->getUser()->get_id(); $sql .= ' AND model_of = ' . $this->app['authentication']->getUser()->getId();
} elseif ($this->include_templates === false) { } elseif ($this->include_templates === false) {
$sql .= ' AND model_of=0'; $sql .= ' AND model_of=0';
} elseif ($this->app['authentication']->getUser()) { } elseif ($this->app['authentication']->getUser()) {
$sql .= ' AND (model_of=0 OR model_of = ' . $this->app['authentication']->getUser()->get_id() . ' ) '; $sql .= ' AND (model_of=0 OR model_of = ' . $this->app['authentication']->getUser()->getId() . ' ) ';
} else { } else {
$sql .= ' AND model_of=0'; $sql .= ' AND model_of=0';
} }
@@ -396,7 +397,7 @@ class User_Query implements User_QueryInterface
public function last_model_is($login = null) public function last_model_is($login = null)
{ {
$this->last_model = $login instanceof \User_Adapter ? $login->get_login() : $login; $this->last_model = $login instanceof User ? $login->getLogin() : $login;
return $this; return $this;
} }
@@ -511,7 +512,7 @@ class User_Query implements User_QueryInterface
$users = new ArrayCollection(); $users = new ArrayCollection();
foreach ($rs as $row) { foreach ($rs as $row) {
$users[] = User_Adapter::getInstance($row['usr_id'], $this->app); $users[] = $this->app['manipulator.user']->getRepository()->find($row['usr_id']);
} }
$this->results = $users; $this->results = $users;

Some files were not shown because too many files have changed in this diff Show More