Update prod controllers

This commit is contained in:
Romain Neutron
2012-09-18 17:32:03 +02:00
parent 462793d90c
commit 1fc9a78e7f
20 changed files with 475 additions and 538 deletions

View File

@@ -126,20 +126,18 @@ class Basket implements ControllerProviderInterface
public function displayBasket(Application $app, Request $request, $basket_id) public function displayBasket(Application $app, Request $request, $basket_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], false);
$basket = $em->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), false);
if ($basket->getIsRead() === false) { if ($basket->getIsRead() === false) {
$basket->setIsRead(true); $basket->setIsRead(true);
$em->flush(); $app['EM']->flush();
} }
if ($basket->getValidation()) { if ($basket->getValidation()) {
if ($basket->getValidation()->getParticipant($app['phraseanet.core']->getAuthenticatedUser())->getIsAware() === false) { if ($basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->getIsAware() === false) {
$basket->getValidation()->getParticipant($app['phraseanet.core']->getAuthenticatedUser())->setIsAware(true); $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true);
$em->flush(); $app['EM']->flush();
} }
} }
@@ -156,22 +154,20 @@ class Basket implements ControllerProviderInterface
$request = $app['request']; $request = $app['request'];
/* @var $request \Symfony\Component\HttpFoundation\Request */ /* @var $request \Symfony\Component\HttpFoundation\Request */
$em = $app['phraseanet.core']->getEntityManager();
$Basket = new BasketEntity(); $Basket = new BasketEntity();
$Basket->setName($request->request->get('name', '')); $Basket->setName($request->request->get('name', ''));
$Basket->setOwner($app['phraseanet.core']->getAuthenticatedUser()); $Basket->setOwner($app['phraseanet.user']);
$Basket->setDescription($request->request->get('desc')); $Basket->setDescription($request->request->get('desc'));
$em->persist($Basket); $app['EM']->persist($Basket);
$n = 0; $n = 0;
$records = RecordsRequest::fromRequest($app, $request, true); $records = RecordsRequest::fromRequest($app, $request, true);
foreach ($records as $record) { foreach ($records as $record) {
if ($Basket->hasRecord($record)) { if ($Basket->hasRecord($app, $record)) {
continue; continue;
} }
@@ -179,14 +175,14 @@ class Basket implements ControllerProviderInterface
$basket_element->setRecord($record); $basket_element->setRecord($record);
$basket_element->setBasket($Basket); $basket_element->setBasket($Basket);
$em->persist($basket_element); $app['EM']->persist($basket_element);
$Basket->addBasketElement($basket_element); $Basket->addBasketElement($basket_element);
$n++; $n++;
} }
$em->flush(); $app['EM']->flush();
if ($request->getRequestFormat() == 'json') { if ($request->getRequestFormat() == 'json') {
$data = array( $data = array(
@@ -205,13 +201,11 @@ class Basket implements ControllerProviderInterface
public function deleteBasket(Application $app, Request $request, $basket_id) public function deleteBasket(Application $app, Request $request, $basket_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
$basket = $em->getRepository('\Entities\Basket') $app['EM']->remove($basket);
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); $app['EM']->flush();
$em->remove($basket);
$em->flush();
$data = array( $data = array(
'success' => true 'success' => true
@@ -227,20 +221,17 @@ class Basket implements ControllerProviderInterface
public function removeBasketElement(Application $app, Request $request, $basket_id, $basket_element_id) public function removeBasketElement(Application $app, Request $request, $basket_id, $basket_element_id)
{ {
/* @var $em \Doctrine\ORM\EntityManager */ $basket = $app['EM']->getRepository('\Entities\Basket')
$em = $app['phraseanet.core']->getEntityManager(); ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
$basket = $em->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true);
foreach ($basket->getElements() as $basket_element) { foreach ($basket->getElements() as $basket_element) {
/* @var $basket_element \Entities\BasketElement */ /* @var $basket_element \Entities\BasketElement */
if ($basket_element->getId() == $basket_element_id) { if ($basket_element->getId() == $basket_element_id) {
$em->remove($basket_element); $app['EM']->remove($basket_element);
} }
} }
$em->flush(); $app['EM']->flush();
$data = array( $data = array(
'success' => true 'success' => true
@@ -259,16 +250,14 @@ class Basket implements ControllerProviderInterface
$success = false; $success = false;
try { try {
$em = $app['phraseanet.core']->getEntityManager(); $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
$basket = $em->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true);
$basket->setName($request->request->get('name', '')); $basket->setName($request->request->get('name', ''));
$basket->setDescription($request->request->get('description')); $basket->setDescription($request->request->get('description'));
$em->merge($basket); $app['EM']->merge($basket);
$em->flush(); $app['EM']->flush();
$success = true; $success = true;
$msg = _('Basket has been updated'); $msg = _('Basket has been updated');
@@ -295,17 +284,18 @@ class Basket implements ControllerProviderInterface
public function displayUpdateForm(Application $app, $basket_id) public function displayUpdateForm(Application $app, $basket_id)
{ {
$basket = $app['phraseanet.core']->getEntityManager() $basket = $app['EM']
->getRepository('\Entities\Basket') ->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
return $app['twig']->render('prod/Baskets/Update.html.twig', array('basket' => $basket)); return $app['twig']->render('prod/Baskets/Update.html.twig', array('basket' => $basket));
} }
public function displayReorderForm(Application $app, $basket_id) public function displayReorderForm(Application $app, $basket_id)
{ {
$basket = $app['phraseanet.core']->getEntityManager()->getRepository('\Entities\Basket') $basket = $app['EM']
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true); ->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
return $app['twig']->render('prod/Baskets/Reorder.html.twig', array('basket' => $basket)); return $app['twig']->render('prod/Baskets/Reorder.html.twig', array('basket' => $basket));
} }
@@ -314,11 +304,8 @@ class Basket implements ControllerProviderInterface
{ {
$ret = array('success' => false, 'message' => _('An error occured')); $ret = array('success' => false, 'message' => _('An error occured'));
try { try {
/* @var $em \Doctrine\ORM\EntityManager */ $basket = $app['EM']->getRepository('\Entities\Basket')
$em = $app['phraseanet.core']->getEntityManager(); ->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
$basket = $em->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true);
$order = $app['request']->request->get('element'); $order = $app['request']->request->get('element');
@@ -327,11 +314,11 @@ class Basket implements ControllerProviderInterface
if (isset($order[$basketElement->getId()])) { if (isset($order[$basketElement->getId()])) {
$basketElement->setOrd($order[$basketElement->getId()]); $basketElement->setOrd($order[$basketElement->getId()]);
$em->merge($basketElement); $app['EM']->merge($basketElement);
} }
} }
$em->flush(); $app['EM']->flush();
$ret = array('success' => true, 'message' => _('Basket updated')); $ret = array('success' => true, 'message' => _('Basket updated'));
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -342,17 +329,15 @@ class Basket implements ControllerProviderInterface
public function archiveBasket(Application $app, Request $request, $basket_id) public function archiveBasket(Application $app, Request $request, $basket_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
$basket = $em->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true);
$archive_status = !!$request->request->get('archive'); $archive_status = !!$request->request->get('archive');
$basket->setArchived($archive_status); $basket->setArchived($archive_status);
$em->merge($basket); $app['EM']->merge($basket);
$em->flush(); $app['EM']->flush();
if ($archive_status) { if ($archive_status) {
$message = _('Basket has been archived'); $message = _('Basket has been archived');
@@ -375,24 +360,22 @@ class Basket implements ControllerProviderInterface
public function addElements(Application $app, Request $request, $basket_id) public function addElements(Application $app, Request $request, $basket_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
$basket = $em->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true);
$n = 0; $n = 0;
$records = RecordsRequest::fromRequest($app, $request, true); $records = RecordsRequest::fromRequest($app, $request, true);
foreach ($records as $record) { foreach ($records as $record) {
if ($basket->hasRecord($record)) if ($basket->hasRecord($app, $record))
continue; continue;
$basket_element = new BasketElement(); $basket_element = new BasketElement();
$basket_element->setRecord($record); $basket_element->setRecord($record);
$basket_element->setBasket($basket); $basket_element->setBasket($basket);
$em->persist($basket_element); $app['EM']->persist($basket_element);
$basket->addBasketElement($basket_element); $basket->addBasketElement($basket_element);
@@ -405,14 +388,14 @@ class Basket implements ControllerProviderInterface
$validationData->setParticipant($participant); $validationData->setParticipant($participant);
$validationData->setBasketElement($basket_element); $validationData->setBasketElement($basket_element);
$em->persist($validationData); $app['EM']->persist($validationData);
} }
} }
$n++; $n++;
} }
$em->flush(); $app['EM']->flush();
$data = array( $data = array(
'success' => true 'success' => true
@@ -428,20 +411,17 @@ class Basket implements ControllerProviderInterface
public function stealElements(Application $app, Request $request, $basket_id) public function stealElements(Application $app, Request $request, $basket_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true);
/* @var $em \Doctrine\ORM\EntityManager */ $user = $app['phraseanet.user'];
$basket = $em->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), true);
$user = $app['phraseanet.core']->getAuthenticatedUser();
/* @var $user \User_Adapter */ /* @var $user \User_Adapter */
$n = 0; $n = 0;
foreach ($request->request->get('elements') as $bask_element_id) { foreach ($request->request->get('elements') as $bask_element_id) {
try { try {
$basket_element = $em->getRepository('\Entities\BasketElement') $basket_element = $app['EM']->getRepository('\Entities\BasketElement')
->findUserElement($bask_element_id, $user); ->findUserElement($bask_element_id, $user);
} catch (\Exception $e) { } catch (\Exception $e) {
continue; continue;
@@ -452,7 +432,7 @@ class Basket implements ControllerProviderInterface
$n++; $n++;
} }
$em->flush(); $app['EM']->flush();
$data = array( $data = array(
'success' => true 'success' => true

View File

@@ -46,13 +46,13 @@ class Bridge implements ControllerProviderInterface
$controllers->post('/manager/' $controllers->post('/manager/'
, function(Application $app) { , function(Application $app) {
$route = new RecordHelper\Bridge($app['phraseanet.core'], $app['request']); $route = new RecordHelper\Bridge($app, $app['request']);
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox); $user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $app);
$params = array( $params = array(
'user_accounts' => \Bridge_Account::get_accounts_by_user($appbox, $user) 'user_accounts' => \Bridge_Account::get_accounts_by_user($app, $user)
, 'available_apis' => \Bridge_Api::get_availables($appbox) , 'available_apis' => \Bridge_Api::get_availables($app)
, 'route' => $route , 'route' => $route
, 'current_account_id' => '' , 'current_account_id' => ''
); );
@@ -72,8 +72,8 @@ class Bridge implements ControllerProviderInterface
$error_message = ''; $error_message = '';
try { try {
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox); $user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $app);
$api = \Bridge_Api::get_by_api_name($appbox, $api_name); $api = \Bridge_Api::get_by_api_name($app, $api_name);
$connector = $api->get_connector(); $connector = $api->get_connector();
$response = $connector->connect(); $response = $connector->connect();
@@ -81,9 +81,9 @@ class Bridge implements ControllerProviderInterface
$user_id = $connector->get_user_id(); $user_id = $connector->get_user_id();
try { try {
$account = \Bridge_Account::load_account_from_distant_id($appbox, $api, $user, $user_id); $account = \Bridge_Account::load_account_from_distant_id($app, $api, $user, $user_id);
} catch (\Bridge_Exception_AccountNotFound $e) { } catch (\Bridge_Exception_AccountNotFound $e) {
$account = \Bridge_Account::create($appbox, $api, $user, $user_id, $connector->get_user_name()); $account = \Bridge_Account::create($app, $api, $user, $user_id, $connector->get_user_name());
} }
$settings = $account->get_settings(); $settings = $account->get_settings();
@@ -106,7 +106,7 @@ class Bridge implements ControllerProviderInterface
$controllers->get('/adapter/{account_id}/logout/', function(Application $app, $account_id) { $controllers->get('/adapter/{account_id}/logout/', function(Application $app, $account_id) {
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$account = \Bridge_Account::load_account($appbox, $account_id); $account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account); $app['require_connection']($account);
$account->get_api()->get_connector()->disconnect(); $account->get_api()->get_connector()->disconnect();
@@ -118,8 +118,8 @@ class Bridge implements ControllerProviderInterface
$quantity = 10; $quantity = 10;
$offset_start = max(($page - 1) * $quantity, 0); $offset_start = max(($page - 1) * $quantity, 0);
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$account = \Bridge_Account::load_account($appbox, $account_id); $account = \Bridge_Account::load_account($app, $account_id);
$elements = \Bridge_Element::get_elements_by_account($appbox, $account, $offset_start, $quantity); $elements = \Bridge_Element::get_elements_by_account($app, $account, $offset_start, $quantity);
$app['require_connection']($account); $app['require_connection']($account);
@@ -141,7 +141,7 @@ class Bridge implements ControllerProviderInterface
$quantity = 5; $quantity = 5;
$offset_start = max(($page - 1) * $quantity, 0); $offset_start = max(($page - 1) * $quantity, 0);
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$account = \Bridge_Account::load_account($appbox, $account_id); $account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account); $app['require_connection']($account);
@@ -167,7 +167,7 @@ class Bridge implements ControllerProviderInterface
$quantity = 5; $quantity = 5;
$offset_start = max(($page - 1) * $quantity, 0); $offset_start = max(($page - 1) * $quantity, 0);
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$account = \Bridge_Account::load_account($appbox, $account_id); $account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account); $app['require_connection']($account);
$elements = $account->get_api()->list_containers($type, $offset_start, $quantity); $elements = $account->get_api()->list_containers($type, $offset_start, $quantity);
@@ -189,7 +189,7 @@ class Bridge implements ControllerProviderInterface
, function(Application $app, $account_id, $action, $element_type) { , function(Application $app, $account_id, $action, $element_type) {
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$account = \Bridge_Account::load_account($appbox, $account_id); $account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account); $app['require_connection']($account);
$request = $app['request']; $request = $app['request'];
@@ -254,7 +254,7 @@ class Bridge implements ControllerProviderInterface
$controllers->post('/action/{account_id}/{action}/{element_type}/' $controllers->post('/action/{account_id}/{action}/{element_type}/'
, function(Application $app, $account_id, $action, $element_type) { , function(Application $app, $account_id, $action, $element_type) {
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$account = \Bridge_Account::load_account($appbox, $account_id); $account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account); $app['require_connection']($account);
@@ -357,10 +357,10 @@ class Bridge implements ControllerProviderInterface
$controllers->get('/upload/', function(Application $app) { $controllers->get('/upload/', function(Application $app) {
$request = $app['request']; $request = $app['request'];
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$account = \Bridge_Account::load_account($appbox, $request->query->get('account_id')); $account = \Bridge_Account::load_account($app, $request->query->get('account_id'));
$app['require_connection']($account); $app['require_connection']($account);
$route = new RecordHelper\Bridge($app['phraseanet.core'], $app['request']); $route = new RecordHelper\Bridge($app, $app['request']);
$route->grep_records($account->get_api()->acceptable_records()); $route->grep_records($account->get_api()->acceptable_records());
@@ -382,10 +382,10 @@ class Bridge implements ControllerProviderInterface
$errors = array(); $errors = array();
$request = $app['request']; $request = $app['request'];
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$account = \Bridge_Account::load_account($appbox, $request->request->get('account_id')); $account = \Bridge_Account::load_account($app, $request->request->get('account_id'));
$app['require_connection']($account); $app['require_connection']($account);
$route = new RecordHelper\Bridge($app['phraseanet.core'], $app['request']); $route = new RecordHelper\Bridge($app, $app['request']);
$route->grep_records($account->get_api()->acceptable_records()); $route->grep_records($account->get_api()->acceptable_records());
$connector = $account->get_api()->get_connector(); $connector = $account->get_api()->get_connector();
@@ -415,62 +415,62 @@ class Bridge implements ControllerProviderInterface
$datas = $connector->get_upload_datas($request, $record); $datas = $connector->get_upload_datas($request, $record);
$title = isset($datas["title"]) ? $datas["title"] : ''; $title = isset($datas["title"]) ? $datas["title"] : '';
$default_type = $connector->get_default_element_type(); $default_type = $connector->get_default_element_type();
\Bridge_Element::create($appbox, $account, $record, $title, \Bridge_Element::STATUS_PENDING, $default_type, $datas); \Bridge_Element::create($app, $account, $record, $title, \Bridge_Element::STATUS_PENDING, $default_type, $datas);
} }
return $app->redirect('/prod/bridge/adapter/' . $account->get_id() . '/load-records/?notice=' . sprintf(_('%d elements en attente'), count($route->get_elements()))); return $app->redirect('/prod/bridge/adapter/' . $account->get_id() . '/load-records/?notice=' . sprintf(_('%d elements en attente'), count($route->get_elements())));
}); });
//
// $app->error(function(\Exception $e, $code) use ($app) {
//
// $request = $app['request'];
//
// if ($e instanceof \Bridge_Exception) {
//
// $params = array(
// 'message' => $e->getMessage()
// , 'file' => $e->getFile()
// , 'line' => $e->getLine()
// , 'r_method' => $request->getMethod()
// , 'r_action' => $request->getRequestUri()
// , 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all())
// );
//
// if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) {
// $params = array_merge($params, array('account' => $app['current_account']));
//
// $response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200);
// } elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
// $params = array_merge($params, array('account' => $app['current_account']));
//
// $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200);
// } elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
// $params = array_merge($params, array('account' => $app['current_account']));
//
// $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200);
// } elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
// $params = array_merge($params, array('api' => $e->get_api()));
//
// $response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200);
// } else {
// $response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200);
// }
//
// $response->headers->set('Phrasea-StatusCode', 200);
//
// return $response;
// }
// });
$app->error(function(\Exception $e, $code) use ($app) { // /**
// * Temporary fix for https://github.com/fabpot/Silex/issues/438
$request = $app['request']; // */
// $app['dispatcher']->addListener(KernelEvents::RESPONSE, function(FilterResponseEvent $event){
if ($e instanceof \Bridge_Exception) { // if ($event->getResponse()->headers->has('Phrasea-StatusCode')) {
// $event->getResponse()->setStatusCode($event->getResponse()->headers->get('Phrasea-StatusCode'));
$params = array( // $event->getResponse()->headers->remove('Phrasea-StatusCode');
'message' => $e->getMessage() // }
, 'file' => $e->getFile() // });
, 'line' => $e->getLine()
, 'r_method' => $request->getMethod()
, 'r_action' => $request->getRequestUri()
, 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all())
);
if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) {
$params = array_merge($params, array('account' => $app['current_account']));
$response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200);
} elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
$params = array_merge($params, array('account' => $app['current_account']));
$response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200);
} elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
$params = array_merge($params, array('account' => $app['current_account']));
$response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200);
} elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
$params = array_merge($params, array('api' => $e->get_api()));
$response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200);
} else {
$response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200);
}
$response->headers->set('Phrasea-StatusCode', 200);
return $response;
}
});
/**
* Temporary fix for https://github.com/fabpot/Silex/issues/438
*/
$app['dispatcher']->addListener(KernelEvents::RESPONSE, function(FilterResponseEvent $event){
if ($event->getResponse()->headers->has('Phrasea-StatusCode')) {
$event->getResponse()->setStatusCode($event->getResponse()->headers->get('Phrasea-StatusCode'));
$event->getResponse()->headers->remove('Phrasea-StatusCode');
}
});
return $controllers; return $controllers;
} }

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Controller\Prod; namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController;
use Alchemy\Phrasea\Controller\RecordsRequest; use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Metadata\Tag\TfEditdate; use Alchemy\Phrasea\Metadata\Tag\TfEditdate;
use Silex\Application; use Silex\Application;
@@ -113,8 +114,8 @@ class Edit implements ControllerProviderInterface
/** /**
* generate javascript status * generate javascript status
*/ */
if ($app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right('changestatus')) { if ($app['phraseanet.user']->ACL()->has_right('changestatus')) {
$dbstatus = \databox_status::getDisplayStatus(); $dbstatus = \databox_status::getDisplayStatus($app);
if (isset($dbstatus[$databox->get_sbas_id()])) { if (isset($dbstatus[$databox->get_sbas_id()])) {
foreach ($dbstatus[$databox->get_sbas_id()] as $n => $statbit) { foreach ($dbstatus[$databox->get_sbas_id()] as $n => $statbit) {
$status[$n] = array(); $status[$n] = array();
@@ -149,7 +150,7 @@ class Edit implements ControllerProviderInterface
); );
$elements[$indice]['statbits'] = array(); $elements[$indice]['statbits'] = array();
if ($app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right_on_base($record->get_base_id(), 'chgstatus')) { if ($app['phraseanet.user']->ACL()->has_right_on_base($record->get_base_id(), 'chgstatus')) {
foreach ($status as $n => $s) { foreach ($status as $n => $s) {
$tmp_val = substr(strrev($record->get_status()), $n, 1); $tmp_val = substr(strrev($record->get_status()), $n, 1);
$elements[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0'; $elements[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0';
@@ -233,7 +234,7 @@ class Edit implements ControllerProviderInterface
throw new \Exception('Invalid sbas_id'); throw new \Exception('Invalid sbas_id');
} }
$VC = \Alchemy\Phrasea\Vocabulary\Controller::get($vocabulary); $VC = VocabularyController::get($app, $vocabulary);
$databox = $app['phraseanet.appbox']->get_databox($sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
} catch (\Exception $e) { } catch (\Exception $e) {
$datas['message'] = _('Vocabulary not found'); $datas['message'] = _('Vocabulary not found');
@@ -243,7 +244,7 @@ class Edit implements ControllerProviderInterface
$query = $request->query->get('query'); $query = $request->query->get('query');
$results = $VC->find($query, $app['phraseanet.core']->getAuthenticatedUser(), $databox); $results = $VC->find($query, $app['phraseanet.user'], $databox);
$list = array(); $list = array();
@@ -277,7 +278,7 @@ class Edit implements ControllerProviderInterface
try { try {
$reg_record = $records->singleStory(); $reg_record = $records->singleStory();
$newsubdef_reg = new \record_adapter($reg_record->get_sbas_id(), $request->request->get('newrepresent')); $newsubdef_reg = new \record_adapter($app, $reg_record->get_sbas_id(), $request->request->get('newrepresent'));
if ($newsubdef_reg->get_type() !== 'image') { if ($newsubdef_reg->get_type() !== 'image') {
throw new \Exception('A reg image must come from image data'); throw new \Exception('A reg image must come from image data');
@@ -287,8 +288,8 @@ class Edit implements ControllerProviderInterface
if (!in_array($name, array('thumbnail', 'preview'))) { if (!in_array($name, array('thumbnail', 'preview'))) {
continue; continue;
} }
$media = $app['phraseanet.core']['mediavorus']->guess($value->get_pathfile()); $media = $app['mediavorus']->guess($value->get_pathfile());
$reg_record->substitute_subdef($name, $media); $reg_record->substitute_subdef($name, $media, $app);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -296,7 +297,7 @@ class Edit implements ControllerProviderInterface
} }
if (!is_array($request->get('mds'))) { if (!is_array($request->get('mds'))) {
return $this; return;
} }
$databox = array_pop($records->databoxes()); $databox = array_pop($records->databoxes());
@@ -367,13 +368,13 @@ class Edit implements ControllerProviderInterface
if (!in_array($statbits, array('', 'null'))) { if (!in_array($statbits, array('', 'null'))) {
$mask_and = ltrim(str_replace(array('x', '0', '1', 'z'), array('1', 'z', '0', '1'), $statbits), '0'); $mask_and = ltrim(str_replace(array('x', '0', '1', 'z'), array('1', 'z', '0', '1'), $statbits), '0');
if ($mask_and != '') { if ($mask_and != '') {
$newstat = \databox_status::operation_and_not($newstat, $mask_and); $newstat = \databox_status::operation_and_not($app, $newstat, $mask_and);
} }
$mask_or = ltrim(str_replace('x', '0', $statbits), '0'); $mask_or = ltrim(str_replace('x', '0', $statbits), '0');
if ($mask_or != '') { if ($mask_or != '') {
$newstat = \databox_status::operation_or($newstat, $mask_or); $newstat = \databox_status::operation_or($app, $newstat, $mask_or);
} }
$record->set_binary_status($newstat); $record->set_binary_status($newstat);

View File

@@ -33,8 +33,8 @@ class Feed implements ControllerProviderInterface
* I got a selection of docs, which publications are available forthese docs ? * I got a selection of docs, which publications are available forthese docs ?
*/ */
$controllers->post('/requestavailable/', function(Application $app, Request $request) { $controllers->post('/requestavailable/', function(Application $app, Request $request) {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); $feeds = \Feed_Collection::load_all($app, $user);
$publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub')); $publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub'));
return new Response($app['twig']->render('prod/actions/publish/publish.html.twig', array('publishing' => $publishing, 'feeds' => $feeds))); return new Response($app['twig']->render('prod/actions/publish/publish.html.twig', array('publishing' => $publishing, 'feeds' => $feeds)));
@@ -45,8 +45,8 @@ class Feed implements ControllerProviderInterface
*/ */
$controllers->post('/entry/create/', function(Application $app, Request $request) { $controllers->post('/entry/create/', function(Application $app, Request $request) {
try { try {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$feed = new \Feed_Adapter($app['phraseanet.appbox'], $request->request->get('feed_id')); $feed = new \Feed_Adapter($app, $request->request->get('feed_id'));
$publisher = \Feed_Publisher_Adapter::getPublisher($app['phraseanet.appbox'], $feed, $user); $publisher = \Feed_Publisher_Adapter::getPublisher($app['phraseanet.appbox'], $feed, $user);
$title = $request->request->get('title'); $title = $request->request->get('title');
@@ -54,7 +54,7 @@ class Feed implements ControllerProviderInterface
$author_name = $request->request->get('author_name'); $author_name = $request->request->get('author_name');
$author_mail = $request->request->get('author_mail'); $author_mail = $request->request->get('author_mail');
$entry = \Feed_Entry_Adapter::create($app['phraseanet.appbox'], $feed, $publisher, $title, $subtitle, $author_name, $author_mail); $entry = \Feed_Entry_Adapter::create($app, $feed, $publisher, $title, $subtitle, $author_name, $author_mail);
$publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub')); $publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub'));
@@ -71,15 +71,15 @@ class Feed implements ControllerProviderInterface
$controllers->get('/entry/{id}/edit/', function(Application $app, Request $request, $id) { $controllers->get('/entry/{id}/edit/', function(Application $app, Request $request, $id) {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$entry = \Feed_Entry_Adapter::load_from_id($app['phraseanet.appbox'], $id); $entry = \Feed_Entry_Adapter::load_from_id($app, $id);
if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id()) { if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id()) {
throw new \Exception_UnauthorizedAction(); throw new \Exception_UnauthorizedAction();
} }
$feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); $feeds = \Feed_Collection::load_all($app, $user);
$datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', array('entry' => $entry, 'feeds' => $feeds)); $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', array('entry' => $entry, 'feeds' => $feeds));
@@ -91,9 +91,9 @@ class Feed implements ControllerProviderInterface
try { try {
$app['phraseanet.appbox']->get_connection()->beginTransaction(); $app['phraseanet.appbox']->get_connection()->beginTransaction();
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$entry = \Feed_Entry_Adapter::load_from_id($app['phraseanet.appbox'], $id); $entry = \Feed_Entry_Adapter::load_from_id($app, $id);
if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id()) { if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id()) {
throw new \Exception_UnauthorizedAction(); throw new \Exception_UnauthorizedAction();
@@ -113,7 +113,7 @@ class Feed implements ControllerProviderInterface
$new_feed_id = $request->request->get('feed_id', $current_feed_id); $new_feed_id = $request->request->get('feed_id', $current_feed_id);
if ($current_feed_id != $new_feed_id) { if ($current_feed_id != $new_feed_id) {
try { try {
$new_feed = \Feed_Adapter::load_with_user($app['phraseanet.appbox'], $user, $new_feed_id); $new_feed = \Feed_Adapter::load_with_user($app, $user, $new_feed_id);
} catch (\Exception_NotFound $e) { } catch (\Exception_NotFound $e) {
throw new \Exception_Forbidden('You have no access to this feed'); throw new \Exception_Forbidden('You have no access to this feed');
} }
@@ -164,9 +164,9 @@ class Feed implements ControllerProviderInterface
try { try {
$app['phraseanet.appbox']->get_connection()->beginTransaction(); $app['phraseanet.appbox']->get_connection()->beginTransaction();
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$entry = \Feed_Entry_Adapter::load_from_id($app['phraseanet.appbox'], $id); $entry = \Feed_Entry_Adapter::load_from_id($app, $id);
if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id() if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id()
&& $entry->get_feed()->is_owner($user) === false) { && $entry->get_feed()->is_owner($user) === false) {
@@ -193,9 +193,9 @@ class Feed implements ControllerProviderInterface
$page = (int) $request->query->get('page'); $page = (int) $request->query->get('page');
$page = $page > 0 ? $page : 1; $page = $page > 0 ? $page : 1;
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); $feeds = \Feed_Collection::load_all($app, $user);
$datas = $app['twig']->render('prod/feeds/feeds.html.twig' $datas = $app['twig']->render('prod/feeds/feeds.html.twig'
, array( , array(
@@ -212,10 +212,10 @@ class Feed implements ControllerProviderInterface
$page = (int) $request->query->get('page'); $page = (int) $request->query->get('page');
$page = $page > 0 ? $page : 1; $page = $page > 0 ? $page : 1;
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$feed = \Feed_Adapter::load_with_user($app['phraseanet.appbox'], $user, $id); $feed = \Feed_Adapter::load_with_user($app, $user, $id);
$feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); $feeds = \Feed_Collection::load_all($app, $user);
$datas = $app['twig']->render('prod/feeds/feeds.html.twig', array('feed' => $feed, 'feeds' => $feeds, 'page' => $page)); $datas = $app['twig']->render('prod/feeds/feeds.html.twig', array('feed' => $feed, 'feeds' => $feeds, 'page' => $page));
@@ -225,9 +225,9 @@ class Feed implements ControllerProviderInterface
$controllers->get('/subscribe/aggregated/', function(Application $app, Request $request) { $controllers->get('/subscribe/aggregated/', function(Application $app, Request $request) {
$renew = ($request->query->get('renew') === 'true'); $renew = ($request->query->get('renew') === 'true');
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$feeds = \Feed_Collection::load_all($app['phraseanet.appbox'], $user); $feeds = \Feed_Collection::load_all($app, $user);
$registry = $app['phraseanet.appbox']->get_registry(); $registry = $app['phraseanet.appbox']->get_registry();
$output = array( $output = array(
@@ -242,8 +242,8 @@ class Feed implements ControllerProviderInterface
$controllers->get('/subscribe/{id}/', function(Application $app, Request $request, $id) { $controllers->get('/subscribe/{id}/', function(Application $app, Request $request, $id) {
$renew = ($request->query->get('renew') === 'true'); $renew = ($request->query->get('renew') === 'true');
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$feed = \Feed_Adapter::load_with_user($app['phraseanet.appbox'], $user, $id); $feed = \Feed_Adapter::load_with_user($app, $user, $id);
$registry = $app['phraseanet.appbox']->get_registry(); $registry = $app['phraseanet.appbox']->get_registry();
$output = array( $output = array(

View File

@@ -27,7 +27,7 @@ class Language implements ControllerProviderInterface
$controller = $app['controllers_factory']; $controller = $app['controllers_factory'];
$controller->get("/", function(Application $app) { $controller->get("/", function(Application $app) {
$registry = $app['phraseanet.core']->getRegistry(); $registry = $app['phraseanet.registry'];
$out = array(); $out = array();
$out['thesaurusBasesChanged'] = _('prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee.'); $out['thesaurusBasesChanged'] = _('prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee.');

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Entities\LazaretFile; use Entities\LazaretFile;
use Alchemy\Phrasea\Border; use Alchemy\Phrasea\Border;
use Alchemy\Phrasea\Border\Attribute\AttributeInterface;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -168,15 +169,14 @@ class Lazaret implements ControllerProviderInterface
*/ */
public function listElement(Application $app, Request $request) public function listElement(Application $app, Request $request)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
/* @var $user \User_Adapter */ /* @var $user \User_Adapter */
$baseIds = array_keys($user->ACL()->get_granted_base(array('canaddrecord'))); $baseIds = array_keys($user->ACL()->get_granted_base(array('canaddrecord')));
$lazaretFiles = null; $lazaretFiles = null;
if (count($baseIds) > 0) { if (count($baseIds) > 0) {
$lazaretRepository = $em->getRepository('Entities\LazaretFile'); $lazaretRepository = $app['EM']->getRepository('Entities\LazaretFile');
$lazaretFiles = $lazaretRepository->findPerPage( $lazaretFiles = $lazaretRepository->findPerPage(
$baseIds, $request->query->get('offset', 0), $request->query->get('limit', 10) $baseIds, $request->query->get('offset', 0), $request->query->get('limit', 10)
@@ -203,7 +203,7 @@ class Lazaret implements ControllerProviderInterface
{ {
$ret = array('success' => false, 'message' => '', 'result' => array()); $ret = array('success' => false, 'message' => '', 'result' => array());
$lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id);
/* @var $lazaretFile \Entities\LazaretFile */ /* @var $lazaretFile \Entities\LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
@@ -217,7 +217,7 @@ class Lazaret implements ControllerProviderInterface
'base_id' => $lazaretFile->getBaseId(), 'base_id' => $lazaretFile->getBaseId(),
'created' => $lazaretFile->getCreated()->format(\DateTime::ATOM), 'created' => $lazaretFile->getCreated()->format(\DateTime::ATOM),
'updated' => $lazaretFile->getUpdated()->format(\DateTime::ATOM), 'updated' => $lazaretFile->getUpdated()->format(\DateTime::ATOM),
'pathname' => $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(), 'pathname' => $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(),
'sha256' => $lazaretFile->getSha256(), 'sha256' => $lazaretFile->getSha256(),
'uuid' => $lazaretFile->getUuid(), 'uuid' => $lazaretFile->getUuid(),
); );
@@ -253,7 +253,7 @@ class Lazaret implements ControllerProviderInterface
} }
$lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id);
/* @var $lazaretFile \Entities\LazaretFile */ /* @var $lazaretFile \Entities\LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
@@ -262,12 +262,12 @@ class Lazaret implements ControllerProviderInterface
return $app->json($ret); return $app->json($ret);
} }
$lazaretFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); $lazaretFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename();
$lazaretThumbFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); $lazaretThumbFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename();
try { try {
$borderFile = Border\File::buildFromPathfile( $borderFile = Border\File::buildFromPathfile(
$lazaretFileName, $lazaretFile->getCollection(), $lazaretFile->getOriginalName() $lazaretFileName, $lazaretFile->getCollection($app), $app['mediavorus'], $lazaretFile->getOriginalName()
); );
$record = null; $record = null;
@@ -279,7 +279,7 @@ class Lazaret implements ControllerProviderInterface
}; };
//Force creation record //Force creation record
$app['phraseanet.core']['border-manager']->process( $app['border-manager']->process(
$lazaretFile->getSession(), $borderFile, $callBack, Border\Manager::FORCE_RECORD $lazaretFile->getSession(), $borderFile, $callBack, Border\Manager::FORCE_RECORD
); );
@@ -295,26 +295,26 @@ class Lazaret implements ControllerProviderInterface
} }
try { try {
$attribute = Border\Attribute\Factory::getFileAttribute($attr->getName(), $attr->getValue()); $attribute = Border\Attribute\Factory::getFileAttribute($app, $attr->getName(), $attr->getValue());
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
continue; continue;
} }
/* @var $attribute Border\Attribute\Attribute */ /* @var $attribute AttributeInterface */
switch ($attribute->getName()) { switch ($attribute->getName()) {
case Border\Attribute\Attribute::NAME_METADATA: case AttributeInterface::NAME_METADATA:
/** /**
* @todo romain neutron * @todo romain neutron
*/ */
break; break;
case Border\Attribute\Attribute::NAME_STORY: case AttributeInterface::NAME_STORY:
$attribute->getValue()->appendChild($record); $attribute->getValue()->appendChild($record);
break; break;
case Border\Attribute\Attribute::NAME_STATUS: case AttributeInterface::NAME_STATUS:
$record->set_binary_status($attribute->getValue()); $record->set_binary_status($attribute->getValue());
break; break;
case Border\Attribute\Attribute::NAME_METAFIELD: case AttributeInterface::NAME_METAFIELD:
/** /**
* @todo romain neutron * @todo romain neutron
*/ */
@@ -324,8 +324,8 @@ class Lazaret implements ControllerProviderInterface
} }
//Delete lazaret file //Delete lazaret file
$app['phraseanet.core']['EM']->remove($lazaretFile); $app['EM']->remove($lazaretFile);
$app['phraseanet.core']['EM']->flush(); $app['EM']->flush();
$ret['success'] = true; $ret['success'] = true;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -354,7 +354,7 @@ class Lazaret implements ControllerProviderInterface
{ {
$ret = array('success' => false, 'message' => '', 'result' => array()); $ret = array('success' => false, 'message' => '', 'result' => array());
$lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id);
/* @var $lazaretFile \Entities\LazaretFile */ /* @var $lazaretFile \Entities\LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
$ret['message'] = _('File is not present in quarantine anymore, please refresh'); $ret['message'] = _('File is not present in quarantine anymore, please refresh');
@@ -374,11 +374,11 @@ class Lazaret implements ControllerProviderInterface
protected function denyLazaretFile(Application $app, LazaretFile $lazaretFile) protected function denyLazaretFile(Application $app, LazaretFile $lazaretFile)
{ {
$lazaretFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); $lazaretFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename();
$lazaretThumbFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); $lazaretThumbFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename();
$app['phraseanet.core']['EM']->remove($lazaretFile); $app['EM']->remove($lazaretFile);
$app['phraseanet.core']['EM']->flush(); $app['EM']->flush();
try { try {
$app['filesystem']->remove(array($lazaretFileName, $lazaretThumbFileName)); $app['filesystem']->remove(array($lazaretFileName, $lazaretThumbFileName));
@@ -401,18 +401,18 @@ class Lazaret implements ControllerProviderInterface
{ {
$ret = array('success' => false, 'message' => '', 'result' => array()); $ret = array('success' => false, 'message' => '', 'result' => array());
$lazaretFiles = $app['phraseanet.core']['EM']->getRepository('Entities\LazaretFile')->findAll(); $lazaretFiles = $app['EM']->getRepository('Entities\LazaretFile')->findAll();
$app['phraseanet.core']['EM']->beginTransaction(); $app['EM']->beginTransaction();
try { try {
foreach ($lazaretFiles as $lazaretFile) { foreach ($lazaretFiles as $lazaretFile) {
$this->denyLazaretFile($app, $lazaretFile); $this->denyLazaretFile($app, $lazaretFile);
} }
$app['phraseanet.core']['EM']->commit(); $app['EM']->commit();
$ret['success'] = true; $ret['success'] = true;
} catch (\Exception $e) { } catch (\Exception $e) {
$app['phraseanet.core']['EM']->rollback(); $app['EM']->rollback();
$ret['message'] = _('An error occured'); $ret['message'] = _('An error occured');
} }
@@ -439,7 +439,7 @@ class Lazaret implements ControllerProviderInterface
return $app->json($ret); return $app->json($ret);
} }
$lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id);
/* @var $lazaretFile \Entities\LazaretFile */ /* @var $lazaretFile \Entities\LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
@@ -451,7 +451,7 @@ class Lazaret implements ControllerProviderInterface
$found = false; $found = false;
//Check if the choosen record is eligible to the substitution //Check if the choosen record is eligible to the substitution
foreach ($lazaretFile->getRecordsToSubstitute() as $record) { foreach ($lazaretFile->getRecordsToSubstitute($app) as $record) {
if ($record->get_record_id() !== (int) $recordId) { if ($record->get_record_id() !== (int) $recordId) {
continue; continue;
} }
@@ -466,18 +466,18 @@ class Lazaret implements ControllerProviderInterface
return $app->json($ret); return $app->json($ret);
} }
$lazaretFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename(); $lazaretFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getFilename();
$lazaretThumbFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); $lazaretThumbFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename();
try { try {
$media = $app['phraseanet.core']['mediavorus']->guess(new \SplFileInfo($lazaretFileName)); $media = $app['mediavorus']->guess($lazaretFileName);
$record = $lazaretFile->getCollection()->get_databox()->get_record($recordId); $record = $lazaretFile->getCollection($app)->get_databox()->get_record($recordId);
$record->substitute_subdef('document', $media, $app['filesystem'], $app['phraseanet.core']['media-alchemyst'], $app['phraseanet.core']['mediavorus']); $record->substitute_subdef('document', $media, $app);
//Delete lazaret file //Delete lazaret file
$app['phraseanet.core']['EM']->remove($lazaretFile); $app['EM']->remove($lazaretFile);
$app['phraseanet.core']['EM']->flush(); $app['EM']->flush();
$ret['success'] = true; $ret['success'] = true;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -504,7 +504,7 @@ class Lazaret implements ControllerProviderInterface
*/ */
public function thumbnailElement(Application $app, Request $request, $file_id) public function thumbnailElement(Application $app, Request $request, $file_id)
{ {
$lazaretFile = $app['phraseanet.core']['EM']->find('Entities\LazaretFile', $file_id); $lazaretFile = $app['EM']->find('Entities\LazaretFile', $file_id);
/* @var $lazaretFile \Entities\LazaretFile */ /* @var $lazaretFile \Entities\LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
@@ -512,10 +512,10 @@ class Lazaret implements ControllerProviderInterface
return new Response(null, 404); return new Response(null, 404);
} }
$lazaretThumbFileName = $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename(); $lazaretThumbFileName = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/lazaret/' . $lazaretFile->getThumbFilename();
$response = \set_export::stream_file( $response = \set_export::stream_file(
$lazaretThumbFileName, $lazaretFile->getOriginalName(), 'image/jpeg', 'inline' $app['phraseanet.registry'], $lazaretThumbFileName, $lazaretFile->getOriginalName(), 'image/jpeg', 'inline'
); );
return $response; return $response;

View File

@@ -42,7 +42,7 @@ class MoveCollection implements ControllerProviderInterface
return $databox->get_sbas_id(); return $databox->get_sbas_id();
}, $records->databoxes()); }, $records->databoxes());
$collections = $app['phraseanet.core']->getAuthenticatedUser()->ACL() $collections = $app['phraseanet.user']->ACL()
->get_granted_base(array('canaddrecord'), $sbas_ids); ->get_granted_base(array('canaddrecord'), $sbas_ids);
$parameters = array( $parameters = array(
@@ -64,7 +64,7 @@ class MoveCollection implements ControllerProviderInterface
); );
try { try {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
if (null === $request->request->get('base_id')) { if (null === $request->request->get('base_id')) {
$datas['message'] = _('Missing target collection'); $datas['message'] = _('Missing target collection');
@@ -72,12 +72,12 @@ class MoveCollection implements ControllerProviderInterface
} }
if ( ! $user->ACL()->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) { if ( ! $user->ACL()->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) {
$datas['message'] = sprintf(_("You do not have the permission to move records to %s"), \phrasea::bas_names($move->getBaseIdDestination())); $datas['message'] = sprintf(_("You do not have the permission to move records to %s"), \phrasea::bas_names($move->getBaseIdDestination(), $app));
return $app->json($datas); return $app->json($datas);
} }
try { try {
$collection = \collection::get_from_base_id($request->request->get('base_id')); $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
} catch (\Exception_Databox_CollectionNotFound $e) { } catch (\Exception_Databox_CollectionNotFound $e) {
$datas['message'] = _('Invalid target collection'); $datas['message'] = _('Invalid target collection');
return $app->json($datas); return $app->json($datas);

View File

@@ -50,7 +50,7 @@ class Order implements ControllerProviderInterface
*/ */
$controllers->get('/', $this->call('displayOrders')) $controllers->get('/', $this->call('displayOrders'))
->before(function(Request $request) use ($app) { ->before(function(Request $request) use ($app) {
$app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); $app['firewall']->requireOrdersAdmin($app);
}) })
->bind('prod_orders'); ->bind('prod_orders');
@@ -85,7 +85,7 @@ class Order implements ControllerProviderInterface
*/ */
$controllers->get('/{order_id}/', $this->call('displayOneOrder')) $controllers->get('/{order_id}/', $this->call('displayOneOrder'))
->before(function(Request $request) use ($app) { ->before(function(Request $request) use ($app) {
$app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); $app['firewall']->requireOrdersAdmin($app);
}) })
->bind('prod_order') ->bind('prod_order')
->assert('order_id', '\d+'); ->assert('order_id', '\d+');
@@ -105,7 +105,7 @@ class Order implements ControllerProviderInterface
*/ */
$controllers->post('/{order_id}/send/', $this->call('sendOrder')) $controllers->post('/{order_id}/send/', $this->call('sendOrder'))
->before(function(Request $request) use ($app) { ->before(function(Request $request) use ($app) {
$app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); $app['firewall']->requireOrdersAdmin($app);
}) })
->bind('prod_order_send') ->bind('prod_order_send')
->assert('order_id', '\d+'); ->assert('order_id', '\d+');
@@ -125,7 +125,7 @@ class Order implements ControllerProviderInterface
*/ */
$controllers->post('/{order_id}/deny/', $this->call('denyOrder')) $controllers->post('/{order_id}/deny/', $this->call('denyOrder'))
->before(function(Request $request) use ($app) { ->before(function(Request $request) use ($app) {
$app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); $app['firewall']->requireOrdersAdmin($app);
}) })
->bind('prod_order_deny') ->bind('prod_order_deny')
->assert('order_id', '\d+'); ->assert('order_id', '\d+');
@@ -149,7 +149,7 @@ class Order implements ControllerProviderInterface
try { try {
$records = RecordsRequest::fromRequest($app, $request, true, array('cancmd')); $records = RecordsRequest::fromRequest($app, $request, true, array('cancmd'));
$query = new \User_Query($app['phraseanet.appbox']); $query = new \User_Query($app);
foreach ($records as $key => $record) { foreach ($records as $key => $record) {
if ($collectionHasOrderAdmins->containsKey($record->get_base_id())) { if ($collectionHasOrderAdmins->containsKey($record->get_base_id())) {
@@ -185,7 +185,7 @@ class Order implements ControllerProviderInterface
if (count($records) > 0) { if (count($records) > 0) {
\set_order::create( \set_order::create(
$app['phraseanet.appbox'], $records, $app['phraseanet.core']->getAuthenticatedUser(), $request->request->get('use', ''), ( (null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine) $app, $records, $app['phraseanet.user'], $request->request->get('use', ''), ( (null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine)
); );
$success = true; $success = true;
@@ -226,9 +226,9 @@ class Order implements ControllerProviderInterface
$perPage = (int) $request->query->get('per-page', 10); $perPage = (int) $request->query->get('per-page', 10);
$sort = $request->query->get('sort'); $sort = $request->query->get('sort');
$baseIds = array_keys($app['phraseanet.core']->getAuthenticatedUser()->ACL()->get_granted_base(array('order_master'))); $baseIds = array_keys($app['phraseanet.user']->ACL()->get_granted_base(array('order_master')));
$ordersList = \set_order::listOrders($app['phraseanet.appbox'], $baseIds, $offsetStart, $perPage, $sort); $ordersList = \set_order::listOrders($app, $baseIds, $offsetStart, $perPage, $sort);
$total = \set_order::countTotalOrder($app['phraseanet.appbox'], $baseIds); $total = \set_order::countTotalOrder($app['phraseanet.appbox'], $baseIds);
return $app['twig']->render('prod/orders/order_box.html.twig', array( return $app['twig']->render('prod/orders/order_box.html.twig', array(
@@ -252,7 +252,7 @@ class Order implements ControllerProviderInterface
public function displayOneOrder(Application $app, Request $request, $order_id) public function displayOneOrder(Application $app, Request $request, $order_id)
{ {
try { try {
$order = new \set_order($order_id); $order = new \set_order($app, $order_id);
} catch (\Exception_NotFound $e) { } catch (\Exception_NotFound $e) {
$app->abort(404); $app->abort(404);
} }
@@ -275,13 +275,13 @@ class Order implements ControllerProviderInterface
$success = false; $success = false;
try { try {
$order = new \set_order($order_id); $order = new \set_order($app, $order_id);
} catch (\Exception_NotFound $e) { } catch (\Exception_NotFound $e) {
$app->abort(404); $app->abort(404);
} }
try { try {
$order->send_elements($request->request->get('elements', array()), ! ! $request->request->get('force', false)); $order->send_elements($app, $request->request->get('elements', array()), ! ! $request->request->get('force', false));
$success = true; $success = true;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -315,7 +315,7 @@ class Order implements ControllerProviderInterface
$success = false; $success = false;
try { try {
$order = new \set_order($order_id); $order = new \set_order($app, $order_id);
} catch (\Exception_NotFound $e) { } catch (\Exception_NotFound $e) {
$app->abort(404); $app->abort(404);
} }

View File

@@ -30,18 +30,18 @@ class Printer implements ControllerProviderInterface
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->post('/', function(Application $app) { $controllers->post('/', function(Application $app) {
$printer = new RecordHelper\Printer($app['phraseanet.core'], $app['request']); $printer = new RecordHelper\Printer($app, $app['request']);
return $app['twig']->render('prod/actions/printer_default.html.twig', array('printer' => $printer, 'message' => '')); return $app['twig']->render('prod/actions/printer_default.html.twig', array('printer' => $printer, 'message' => ''));
} }
); );
$controllers->post('/print.pdf', function(Application $app) { $controllers->post('/print.pdf', function(Application $app) {
$printer = new RecordHelper\Printer($app['phraseanet.core'], $app['request']); $printer = new RecordHelper\Printer($app, $app['request']);
$request = $app['request']; $request = $app['request'];
$session = \Session_Handler::getInstance($app['phraseanet.appbox']); $session = \Session_Handler::getInstance($app);
$layout = $request->request->get('lay'); $layout = $request->request->get('lay');
@@ -49,7 +49,7 @@ class Printer implements ControllerProviderInterface
$session->get_logger($record->get_databox()) $session->get_logger($record->get_databox())
->log($record, \Session_Logger::EVENT_PRINT, $layout, ''); ->log($record, \Session_Logger::EVENT_PRINT, $layout, '');
} }
$PDF = new PDFExport($printer->get_elements(), $layout); $PDF = new PDFExport($app, $printer->get_elements(), $layout);
/** /**
* *

View File

@@ -51,7 +51,7 @@ class Push implements ControllerProviderInterface
/* @var $entry \Entities\UsrListEntry */ /* @var $entry \Entities\UsrListEntry */
$entries[] = array( $entries[] = array(
'Id' => $entry->getId(), 'Id' => $entry->getId(),
'User' => $userFormatter($entry->getUser()) 'User' => $userFormatter($entry->getUser($app))
); );
} }
@@ -102,17 +102,16 @@ class Push implements ControllerProviderInterface
$userSelection = $this->getUsersInSelectionExtractor(); $userSelection = $this->getUsersInSelectionExtractor();
$controllers->post('/sendform/', function(Application $app) use ($userSelection) { $controllers->post('/sendform/', function(Application $app) use ($userSelection) {
$push = new RecordHelper\Push($app['phraseanet.core'], $app['request']); $push = new RecordHelper\Push($app, $app['request']);
$em = $app['phraseanet.core']->getEntityManager(); $repository = $app['EM']->getRepository('\Entities\UsrList');
$repository = $em->getRepository('\Entities\UsrList');
$RecommendedUsers = $userSelection($push->get_elements()); $RecommendedUsers = $userSelection($push->get_elements());
$params = array( $params = array(
'push' => $push, 'push' => $push,
'message' => '', 'message' => '',
'lists' => $repository->findUserLists($app['phraseanet.core']->getAuthenticatedUser()), 'lists' => $repository->findUserLists($app['phraseanet.user']),
'context' => 'Push', 'context' => 'Push',
'RecommendedUsers' => $RecommendedUsers 'RecommendedUsers' => $RecommendedUsers
); );
@@ -122,17 +121,16 @@ class Push implements ControllerProviderInterface
); );
$controllers->post('/validateform/', function(Application $app) use ($userSelection) { $controllers->post('/validateform/', function(Application $app) use ($userSelection) {
$push = new RecordHelper\Push($app['phraseanet.core'], $app['request']); $push = new RecordHelper\Push($app, $app['request']);
$em = $app['phraseanet.core']->getEntityManager(); $repository = $app['EM']->getRepository('\Entities\UsrList');
$repository = $em->getRepository('\Entities\UsrList');
$RecommendedUsers = $userSelection($push->get_elements()); $RecommendedUsers = $userSelection($push->get_elements());
$params = array( $params = array(
'push' => $push, 'push' => $push,
'message' => '', 'message' => '',
'lists' => $repository->findUserLists($app['phraseanet.core']->getAuthenticatedUser()), 'lists' => $repository->findUserLists($app['phraseanet.user']),
'context' => 'Feedback', 'context' => 'Feedback',
'RecommendedUsers' => $RecommendedUsers 'RecommendedUsers' => $RecommendedUsers
); );
@@ -150,13 +148,11 @@ class Push implements ControllerProviderInterface
); );
try { try {
$em = $app['phraseanet.core']->getEntityManager(); $registry = $app['phraseanet.registry'];
$registry = $app['phraseanet.core']->getRegistry(); $pusher = new RecordHelper\Push($app, $app['request']);
$pusher = new RecordHelper\Push($app['phraseanet.core'], $app['request']); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
@@ -178,11 +174,11 @@ class Push implements ControllerProviderInterface
throw new ControllerException(_('No elements to push')); throw new ControllerException(_('No elements to push'));
} }
$events_manager = $app['phraseanet.core']['events-manager']; $events_manager = $app['events-manager'];
foreach ($receivers as $receiver) { foreach ($receivers as $receiver) {
try { try {
$user_receiver = \User_Adapter::getInstance($receiver['usr_id'], $appbox); $user_receiver = \User_Adapter::getInstance($receiver['usr_id'], $app);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new ControllerException(sprintf(_('Unknown user %d'), $receiver['usr_id'])); throw new ControllerException(sprintf(_('Unknown user %d'), $receiver['usr_id']));
} }
@@ -194,37 +190,37 @@ class Push implements ControllerProviderInterface
$Basket->setPusher($user); $Basket->setPusher($user);
$Basket->setIsRead(false); $Basket->setIsRead(false);
$em->persist($Basket); $app['EM']->persist($Basket);
foreach ($pusher->get_elements() as $element) { foreach ($pusher->get_elements() as $element) {
$BasketElement = new \Entities\BasketElement(); $BasketElement = new \Entities\BasketElement();
$BasketElement->setRecord($element); $BasketElement->setRecord($element);
$BasketElement->setBasket($Basket); $BasketElement->setBasket($Basket);
$em->persist($BasketElement); $app['EM']->persist($BasketElement);
$Basket->addBasketElement($BasketElement); $Basket->addBasketElement($BasketElement);
if ($receiver['HD']) { if ($receiver['HD']) {
$user_receiver->ACL()->grant_hd_on( $user_receiver->ACL()->grant_hd_on(
$BasketElement->getRecord() $BasketElement->getRecord($app)
, $user , $user
, \ACL::GRANT_ACTION_PUSH , \ACL::GRANT_ACTION_PUSH
); );
} else { } else {
$user_receiver->ACL()->grant_preview_on( $user_receiver->ACL()->grant_preview_on(
$BasketElement->getRecord() $BasketElement->getRecord($app)
, $user , $user
, \ACL::GRANT_ACTION_PUSH , \ACL::GRANT_ACTION_PUSH
); );
} }
} }
$em->flush(); $app['EM']->flush();
$url = $registry->get('GV_ServerName') $url = $registry->get('GV_ServerName')
. 'lightbox/index.php?LOG=' . 'lightbox/index.php?LOG='
. \random::getUrlToken(\random::TYPE_VIEW, $user_receiver->get_id(), null, $Basket->getId()); . \random::getUrlToken($app, \random::TYPE_VIEW, $user_receiver->get_id(), null, $Basket->getId());
$params = array( $params = array(
'from' => $user->get_id() 'from' => $user->get_id()
@@ -241,10 +237,10 @@ class Push implements ControllerProviderInterface
$events_manager->trigger('__PUSH_DATAS__', $params); $events_manager->trigger('__PUSH_DATAS__', $params);
} }
$appbox->get_session()->get_logger($BasketElement->getRecord()->get_databox()) $appbox->get_session()->get_logger($BasketElement->getRecord($app)->get_databox())
->log($BasketElement->getRecord(), \Session_Logger::EVENT_VALIDATE, $user_receiver->get_id(), ''); ->log($BasketElement->getRecord($app), \Session_Logger::EVENT_VALIDATE, $user_receiver->get_id(), '');
$em->flush(); $app['EM']->flush();
$message = sprintf( $message = sprintf(
_('%1$d records have been sent to %2$d users') _('%1$d records have been sent to %2$d users')
@@ -273,20 +269,17 @@ class Push implements ControllerProviderInterface
'message' => _('Unable to send the documents') 'message' => _('Unable to send the documents')
); );
$em = $app['phraseanet.core']->getEntityManager(); $registry = $app['phraseanet.registry'];
$registry = $app['phraseanet.core']->getRegistry(); $app['EM']->beginTransaction();
/* @var $em \Doctrine\ORM\EntityManager */
$em->beginTransaction();
try { try {
$pusher = new RecordHelper\Push($app['phraseanet.core'], $app['request']); $pusher = new RecordHelper\Push($app, $app['request']);
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$events_manager = $app['phraseanet.core']['events-manager']; $events_manager = $app['events-manager'];
$repository = $em->getRepository('\Entities\Basket'); $repository = $app['EM']->getRepository('\Entities\Basket');
$validation_name = $request->request->get('name'); $validation_name = $request->request->get('name');
@@ -315,25 +308,25 @@ class Push implements ControllerProviderInterface
$Basket->setOwner($user); $Basket->setOwner($user);
$Basket->setIsRead(false); $Basket->setIsRead(false);
$em->persist($Basket); $app['EM']->persist($Basket);
foreach ($pusher->get_elements() as $element) { foreach ($pusher->get_elements() as $element) {
$BasketElement = new \Entities\BasketElement(); $BasketElement = new \Entities\BasketElement();
$BasketElement->setRecord($element); $BasketElement->setRecord($element);
$BasketElement->setBasket($Basket); $BasketElement->setBasket($Basket);
$em->persist($BasketElement); $app['EM']->persist($BasketElement);
$Basket->addBasketElement($BasketElement); $Basket->addBasketElement($BasketElement);
} }
$em->flush(); $app['EM']->flush();
} }
$em->refresh($Basket); $app['EM']->refresh($Basket);
if ( ! $Basket->getValidation()) { if ( ! $Basket->getValidation()) {
$Validation = new \Entities\ValidationSession(); $Validation = new \Entities\ValidationSession();
$Validation->setInitiator($app['phraseanet.core']->getAuthenticatedUser()); $Validation->setInitiator($app['phraseanet.user']);
$Validation->setBasket($Basket); $Validation->setBasket($Basket);
$duration = (int) $request->request->get('duration'); $duration = (int) $request->request->get('duration');
@@ -344,7 +337,7 @@ class Push implements ControllerProviderInterface
} }
$Basket->setValidation($Validation); $Basket->setValidation($Validation);
$em->persist($Validation); $app['EM']->persist($Validation);
} else { } else {
$Validation = $Basket->getValidation(); $Validation = $Basket->getValidation();
} }
@@ -375,13 +368,13 @@ class Push implements ControllerProviderInterface
} }
try { try {
$participant_user = \User_Adapter::getInstance($participant['usr_id'], $appbox); $participant_user = \User_Adapter::getInstance($participant['usr_id'], $app);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new ControllerException(sprintf(_('Unknown user %d'), $receiver['usr_id'])); throw new ControllerException(sprintf(_('Unknown user %d'), $receiver['usr_id']));
} }
try { try {
$Participant = $Validation->getParticipant($participant_user); $Participant = $Validation->getParticipant($participant_user, $app);
continue; continue;
} catch (\Exception_NotFound $e) { } catch (\Exception_NotFound $e) {
@@ -394,7 +387,7 @@ class Push implements ControllerProviderInterface
$Participant->setCanAgree($participant['agree']); $Participant->setCanAgree($participant['agree']);
$Participant->setCanSeeOthers($participant['see_others']); $Participant->setCanSeeOthers($participant['see_others']);
$em->persist($Participant); $app['EM']->persist($Participant);
foreach ($Basket->getElements() as $BasketElement) { foreach ($Basket->getElements() as $BasketElement) {
$ValidationData = new \Entities\ValidationData(); $ValidationData = new \Entities\ValidationData();
@@ -404,34 +397,34 @@ class Push implements ControllerProviderInterface
if ($participant['HD']) { if ($participant['HD']) {
$participant_user->ACL()->grant_hd_on( $participant_user->ACL()->grant_hd_on(
$BasketElement->getRecord() $BasketElement->getRecord($app)
, $user , $user
, \ACL::GRANT_ACTION_VALIDATE , \ACL::GRANT_ACTION_VALIDATE
); );
} else { } else {
$participant_user->ACL()->grant_preview_on( $participant_user->ACL()->grant_preview_on(
$BasketElement->getRecord() $BasketElement->getRecord($app)
, $user , $user
, \ACL::GRANT_ACTION_VALIDATE , \ACL::GRANT_ACTION_VALIDATE
); );
} }
$em->merge($BasketElement); $app['EM']->merge($BasketElement);
$em->persist($ValidationData); $app['EM']->persist($ValidationData);
$appbox->get_session()->get_logger($BasketElement->getRecord()->get_databox()) $appbox->get_session()->get_logger($BasketElement->getRecord($app)->get_databox())
->log($BasketElement->getRecord(), \Session_Logger::EVENT_PUSH, $participant_user->get_id(), ''); ->log($BasketElement->getRecord($app), \Session_Logger::EVENT_PUSH, $participant_user->get_id(), '');
$Participant->addValidationData($ValidationData); $Participant->addValidationData($ValidationData);
} }
$Participant = $em->merge($Participant); $Participant = $app['EM']->merge($Participant);
$em->flush(); $app['EM']->flush();
$url = $registry->get('GV_ServerName') $url = $registry->get('GV_ServerName')
. 'lightbox/index.php?LOG=' . 'lightbox/index.php?LOG='
. \random::getUrlToken(\random::TYPE_VIEW, $participant_user->get_id(), null, $Basket->getId()); . \random::getUrlToken($app, \random::TYPE_VIEW, $participant_user->get_id(), null, $Basket->getId());
$params = array( $params = array(
'from' => $user->get_id() 'from' => $user->get_id()
@@ -448,10 +441,10 @@ class Push implements ControllerProviderInterface
$events_manager->trigger('__PUSH_VALIDATION__', $params); $events_manager->trigger('__PUSH_VALIDATION__', $params);
} }
$Basket = $em->merge($Basket); $Basket = $app['EM']->merge($Basket);
$Validation = $em->merge($Validation); $Validation = $app['EM']->merge($Validation);
$em->flush(); $app['EM']->flush();
$message = sprintf( $message = sprintf(
_('%1$d records have been sent for validation to %2$d users') _('%1$d records have been sent for validation to %2$d users')
@@ -464,10 +457,10 @@ class Push implements ControllerProviderInterface
'message' => $message 'message' => $message
); );
$em->commit(); $app['EM']->commit();
} catch (ControllerException $e) { } catch (ControllerException $e) {
$ret['message'] = $e->getMessage(); $ret['message'] = $e->getMessage();
$em->rollback(); $app['EM']->rollback();
} }
return $app->json($ret); return $app->json($ret);
@@ -479,10 +472,9 @@ class Push implements ControllerProviderInterface
$datas = null; $datas = null;
$request = $app['request']; $request = $app['request'];
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
$query = new \User_Query($app['phraseanet.appbox']); $query = new \User_Query($app);
$query->on_bases_where_i_am($user->ACL(), array('canpush')); $query->on_bases_where_i_am($user->ACL(), array('canpush'));
@@ -504,12 +496,11 @@ class Push implements ControllerProviderInterface
$controllers->get('/list/{list_id}/', function(Application $app, $list_id) use ($listFormatter) { $controllers->get('/list/{list_id}/', function(Application $app, $list_id) use ($listFormatter) {
$datas = null; $datas = null;
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
if ($list) { if ($list) {
$datas = $listFormatter($list); $datas = $listFormatter($list);
@@ -521,7 +512,7 @@ class Push implements ControllerProviderInterface
$controllers->post('/add-user/', function(Application $app, Request $request) use ($userFormatter) { $controllers->post('/add-user/', function(Application $app, Request $request) use ($userFormatter) {
$result = array('success' => false, 'message' => '', 'user' => null); $result = array('success' => false, 'message' => '', 'user' => null);
$AdminUser = $app['phraseanet.core']->getAuthenticatedUser(); $AdminUser = $app['phraseanet.user'];
try { try {
/* @var $AdminUser \User_Adapter */ /* @var $AdminUser \User_Adapter */
@@ -551,8 +542,8 @@ 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($email); $usr_id = \User_Adapter::get_usr_id_from_email($app, $email);
$user = \User_Adapter::getInstance($usr_id, $appbox); $user = \User_Adapter::getInstance($usr_id, $app);
$result['message'] = _('User already exists'); $result['message'] = _('User already exists');
$result['success'] = true; $result['success'] = true;
@@ -565,7 +556,7 @@ class Push implements ControllerProviderInterface
try { try {
$password = \random::generatePassword(); $password = \random::generatePassword();
$user = \User_Adapter::create($appbox, $email, $password, $email, false); $user = \User_Adapter::create($app, $email, $password, $email, false);
$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'));
@@ -596,10 +587,9 @@ class Push implements ControllerProviderInterface
$controllers->get('/search-user/', function(Application $app) use ($userFormatter, $listFormatter) { $controllers->get('/search-user/', function(Application $app) use ($userFormatter, $listFormatter) {
$request = $app['request']; $request = $app['request'];
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
$query = new \User_Query($app['phraseanet.appbox']); $query = new \User_Query($app);
$query->on_bases_where_i_am($user->ACL(), array('canpush')); $query->on_bases_where_i_am($user->ACL(), array('canpush'));
@@ -612,7 +602,7 @@ class Push implements ControllerProviderInterface
->limit(0, 50) ->limit(0, 50)
->execute()->get_results(); ->execute()->get_results();
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$lists = $repository->findUserListLike($user, $request->query->get('query')); $lists = $repository->findUserListLike($user, $request->query->get('query'));
@@ -636,14 +626,13 @@ class Push implements ControllerProviderInterface
$controllers->match('/edit-list/{list_id}/', function(Application $app, Request $request, $list_id) { $controllers->match('/edit-list/{list_id}/', function(Application $app, Request $request, $list_id) {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$em = $app['phraseanet.core']->getEntityManager();
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
$query = new \User_Query($app['phraseanet.appbox']); $query = new \User_Query($app);
$query->on_bases_where_i_am($user->ACL(), array('canpush')); $query->on_bases_where_i_am($user->ACL(), array('canpush'));

View File

@@ -32,7 +32,7 @@ class Query implements ControllerProviderInterface
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$query = (string) $request->request->get('qry'); $query = (string) $request->request->get('qry');
@@ -79,7 +79,7 @@ class Query implements ControllerProviderInterface
$perPage = (int) $user->getPrefs('images_per_page'); $perPage = (int) $user->getPrefs('images_per_page');
$search_engine = new \searchEngine_adapter($registry); $search_engine = new \searchEngine_adapter($app);
$search_engine->set_options($options); $search_engine->set_options($options);
$page = (int) $request->request->get('pag'); $page = (int) $request->request->get('pag');
@@ -165,7 +165,7 @@ class Query implements ControllerProviderInterface
$prop = null; $prop = null;
if ($search_engine->is_first_page()) { if ($search_engine->is_first_page()) {
$propals = $result->get_suggestions(); $propals = $result->get_suggestions($app['phraseanet.appbox']->get_session()->get_I18n());
if (count($propals) > 0) { if (count($propals) > 0) {
foreach ($propals as $prop_array) { foreach ($propals as $prop_array) {
if ($prop_array['value'] !== $query && $prop_array['hits'] > $result->get_count_total_results()) { if ($prop_array['value'] !== $query && $prop_array['hits'] > $result->get_count_total_results()) {

View File

@@ -32,11 +32,11 @@ class Root implements ControllerProviderInterface
$controllers->get('/', function(Application $app) { $controllers->get('/', function(Application $app) {
\User_Adapter::updateClientInfos(1); \User_Adapter::updateClientInfos($app, 1);
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$registry = $app['phraseanet.core']->getRegistry(); $registry = $app['phraseanet.registry'];
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$cssPath = $registry->get('GV_RootPath') . 'www/skins/prod/'; $cssPath = $registry->get('GV_RootPath') . 'www/skins/prod/';
$css = array(); $css = array();
@@ -63,7 +63,7 @@ class Root implements ControllerProviderInterface
$cssfile = '000000'; $cssfile = '000000';
} }
$user_feeds = \Feed_Collection::load_all($appbox, $user); $user_feeds = \Feed_Collection::load_all($app, $user);
$feeds = array_merge(array($user_feeds->get_aggregate()), $user_feeds->get_feeds()); $feeds = array_merge(array($user_feeds->get_aggregate()), $user_feeds->get_feeds());
$thjslist = ""; $thjslist = "";
@@ -71,9 +71,9 @@ class Root implements ControllerProviderInterface
$queries_topics = ''; $queries_topics = '';
if ($registry->get('GV_client_render_topics') == 'popups') { if ($registry->get('GV_client_render_topics') == 'popups') {
$queries_topics = \queries::dropdown_topics(); $queries_topics = \queries::dropdown_topics($appbox->get_session()->get_I18n());
} elseif ($registry->get('GV_client_render_topics') == 'tree') { } elseif ($registry->get('GV_client_render_topics') == 'tree') {
$queries_topics = \queries::tree_topics(); $queries_topics = \queries::tree_topics($appbox->get_session()->get_I18n());
} }
$sbas = $bas2sbas = array(); $sbas = $bas2sbas = array();
@@ -96,21 +96,21 @@ class Root implements ControllerProviderInterface
$out = $app['twig']->render('prod/index.html.twig', array( $out = $app['twig']->render('prod/index.html.twig', array(
'module_name' => 'Production', 'module_name' => 'Production',
'WorkZone' => new Helper\WorkZone($app['phraseanet.core'], $app['request']), 'WorkZone' => new Helper\WorkZone($app, $app['request']),
'module_prod' => new Helper\Prod($app['phraseanet.core'], $app['request']), 'module_prod' => new Helper\Prod($app, $app['request']),
'cssfile' => $cssfile, 'cssfile' => $cssfile,
'module' => 'prod', 'module' => 'prod',
'events' => $app['phraseanet.core']['events-manager'], 'events' => $app['events-manager'],
'GV_defaultQuery_type' => $registry->get('GV_defaultQuery_type'), 'GV_defaultQuery_type' => $registry->get('GV_defaultQuery_type'),
'GV_multiAndReport' => $registry->get('GV_multiAndReport'), 'GV_multiAndReport' => $registry->get('GV_multiAndReport'),
'GV_thesaurus' => $registry->get('GV_thesaurus'), 'GV_thesaurus' => $registry->get('GV_thesaurus'),
'cgus_agreement' => \databox_cgu::askAgreement(), 'cgus_agreement' => \databox_cgu::askAgreement($app),
'css' => $css, 'css' => $css,
'feeds' => $feeds, 'feeds' => $feeds,
'GV_google_api' => $registry->get('GV_google_api'), 'GV_google_api' => $registry->get('GV_google_api'),
'queries_topics' => $queries_topics, 'queries_topics' => $queries_topics,
'search_status' => \databox_status::getSearchStatus(), 'search_status' => \databox_status::getSearchStatus($app),
'queries_history' => \queries::history(), 'queries_history' => \queries::history($app['phraseanet.appbox'], $app['phraseanet.user']->get_id()),
'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),
@@ -122,14 +122,14 @@ class Root implements ControllerProviderInterface
$controllers->post('/multi-export/', function(Application $app, Request $request) { $controllers->post('/multi-export/', function(Application $app, Request $request) {
$download = new \set_export($request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story')); $download = new \set_export($app, $request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story'));
return $app['twig']->render('common/dialog_export.html.twig', array( return $app['twig']->render('common/dialog_export.html.twig', array(
'download' => $download, 'download' => $download,
'ssttid' => (int) $request->request->get('ssel'), 'ssttid' => (int) $request->request->get('ssel'),
'lst' => $download->serialize_list(), 'lst' => $download->serialize_list(),
'default_export_title' => $app['phraseanet.core']['Registry']->get('GV_default_export_title'), 'default_export_title' => $app['phraseanet.registry']->get('GV_default_export_title'),
'choose_export_title' => $app['phraseanet.core']['Registry']->get('GV_choose_export_title') 'choose_export_title' => $app['phraseanet.registry']->get('GV_choose_export_title')
)); ));
}); });

View File

@@ -36,17 +36,15 @@ class Story implements ControllerProviderInterface
$controllers->post('/', function(Application $app, Request $request) { $controllers->post('/', function(Application $app, Request $request) {
/* @var $request \Symfony\Component\HttpFoundation\Request */ /* @var $request \Symfony\Component\HttpFoundation\Request */
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser(); $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
$collection = \collection::get_from_base_id($request->request->get('base_id'));
if (!$user->ACL()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) { if (!$user->ACL()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
throw new \Exception_Forbidden('You can not create a story on this collection'); throw new \Exception_Forbidden('You can not create a story on this collection');
} }
$Story = \record_adapter::createStory($collection); $Story = \record_adapter::createStory($app, $collection);
foreach (explode(';', $request->request->get('lst')) as $sbas_rec) { foreach (explode(';', $request->request->get('lst')) as $sbas_rec) {
$sbas_rec = explode('_', $sbas_rec); $sbas_rec = explode('_', $sbas_rec);
@@ -55,7 +53,7 @@ class Story implements ControllerProviderInterface
continue; continue;
} }
$record = new \record_adapter($sbas_rec[0], $sbas_rec[1]); $record = new \record_adapter($app, $sbas_rec[0], $sbas_rec[1]);
if (!$user->ACL()->has_access_to_base($record->get_base_id()) if (!$user->ACL()->has_access_to_base($record->get_base_id())
&& !$user->ACL()->has_hd_grant($record) && !$user->ACL()->has_hd_grant($record)
@@ -93,9 +91,9 @@ class Story implements ControllerProviderInterface
$StoryWZ->setUser($user); $StoryWZ->setUser($user);
$StoryWZ->setRecord($Story); $StoryWZ->setRecord($Story);
$em->persist($StoryWZ); $app['EM']->persist($StoryWZ);
$em->flush(); $app['EM']->flush();
if ($request->getRequestFormat() == 'json') { if ($request->getRequestFormat() == 'json') {
$data = array( $data = array(
@@ -115,7 +113,7 @@ class Story implements ControllerProviderInterface
}); });
$controllers->get('/{sbas_id}/{record_id}/', function(Application $app, $sbas_id, $record_id) { $controllers->get('/{sbas_id}/{record_id}/', function(Application $app, $sbas_id, $record_id) {
$Story = new \record_adapter($sbas_id, $record_id); $Story = new \record_adapter($app, $sbas_id, $record_id);
$html = $app['twig']->render('prod/WorkZone/Story.html.twig', array('Story' => $Story)); $html = $app['twig']->render('prod/WorkZone/Story.html.twig', array('Story' => $Story));
@@ -125,9 +123,9 @@ class Story implements ControllerProviderInterface
$controllers->post( $controllers->post(
'/{sbas_id}/{record_id}/addElements/' '/{sbas_id}/{record_id}/addElements/'
, function(Application $app, Request $request, $sbas_id, $record_id) { , function(Application $app, Request $request, $sbas_id, $record_id) {
$Story = new \record_adapter($sbas_id, $record_id); $Story = new \record_adapter($app, $sbas_id, $record_id);
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
if (!$user->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) if (!$user->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
throw new \Exception_Forbidden('You can not add document to this Story'); throw new \Exception_Forbidden('You can not add document to this Story');
@@ -142,7 +140,7 @@ class Story implements ControllerProviderInterface
if (count($sbas_rec) !== 2) if (count($sbas_rec) !== 2)
continue; continue;
$record = new \record_adapter($sbas_rec[0], $sbas_rec[1]); $record = new \record_adapter($app, $sbas_rec[0], $sbas_rec[1]);
if (!$user->ACL()->has_access_to_base($record->get_base_id()) if (!$user->ACL()->has_access_to_base($record->get_base_id())
&& !$user->ACL()->has_hd_grant($record) && !$user->ACL()->has_hd_grant($record)
@@ -173,11 +171,11 @@ class Story implements ControllerProviderInterface
$controllers->post( $controllers->post(
'/{sbas_id}/{record_id}/delete/{child_sbas_id}/{child_record_id}/' '/{sbas_id}/{record_id}/delete/{child_sbas_id}/{child_record_id}/'
, function(Application $app, Request $request, $sbas_id, $record_id, $child_sbas_id, $child_record_id) { , function(Application $app, Request $request, $sbas_id, $record_id, $child_sbas_id, $child_record_id) {
$Story = new \record_adapter($sbas_id, $record_id); $Story = new \record_adapter($app, $sbas_id, $record_id);
$record = new \record_adapter($child_sbas_id, $child_record_id); $record = new \record_adapter($app, $child_sbas_id, $child_record_id);
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
if (!$user->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) if (!$user->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
throw new \Exception_Forbidden('You can not add document to this Story'); throw new \Exception_Forbidden('You can not add document to this Story');
@@ -205,13 +203,8 @@ class Story implements ControllerProviderInterface
/** /**
* Get the Basket reorder form * Get the Basket reorder form
*/ */
$controllers->get( $controllers->get('/{sbas_id}/{record_id}/reorder/', function(Application $app, $sbas_id, $record_id) {
'/{sbas_id}/{record_id}/reorder/' $story = new \record_adapter($app, $sbas_id, $record_id);
, function(Application $app, $sbas_id, $record_id) {
/* @var $em \Doctrine\ORM\EntityManager */
$em = $app['phraseanet.core']->getEntityManager();
$story = new \record_adapter($sbas_id, $record_id);
if (!$story->is_grouping()) { if (!$story->is_grouping()) {
throw new \Exception('This is not a story'); throw new \Exception('This is not a story');
@@ -232,10 +225,10 @@ class Story implements ControllerProviderInterface
, function(Application $app, $sbas_id, $record_id) { , function(Application $app, $sbas_id, $record_id) {
$ret = array('success' => false, 'message' => _('An error occured')); $ret = array('success' => false, 'message' => _('An error occured'));
try { try {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
/* @var $user \User_Adapter */ /* @var $user \User_Adapter */
$story = new \record_adapter($sbas_id, $record_id); $story = new \record_adapter($app, $sbas_id, $record_id);
if (!$story->is_grouping()) { if (!$story->is_grouping()) {
throw new \Exception('This is not a story'); throw new \Exception('This is not a story');

View File

@@ -31,8 +31,8 @@ class TOU implements ControllerProviderInterface
$ret = array('success' => false, 'message' => ''); $ret = array('success' => false, 'message' => '');
try { try {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$session = \Session_Handler::getInstance($app['phraseanet.appbox']); $session = \Session_Handler::getInstance($app);
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);

View File

@@ -66,18 +66,22 @@ class Tools implements ControllerProviderInterface
}); });
$controllers->post('/rotate/', function(Application $app, Request $request) { $controllers->post('/rotate/', function(Application $app, Request $request) {
$return = array('success' => false, 'errorMessage' => ''); $return = array('success' => true, 'errorMessage' => '');
$records = RecordsRequest::fromRequest($app, $request, false); $records = RecordsRequest::fromRequest($app, $request, false);
$rotation = in_array($request->request->get('rotation'), array('-90', '90', '180')) ? $request->request->get('rotation', 90) : 90; $rotation = in_array($request->request->get('rotation'), array('-90', '90', '180')) ? $request->request->get('rotation', 90) : 90;
foreach ($records as $record) { foreach ($records as $record) {
foreach ($record->get_subdefs() as $name => $subdef) {
if ($name == 'document')
continue;
try { try {
$record->rotate_subdefs($rotation); $subdef->rotate($rotation, $app['media-alchemyst'], $app['mediavorus']);
$return['success'] = true;
} catch (\Exception $e) { } catch (\Exception $e) {
$return['errorMessage'] = $e->getMessage();
}
} }
} }
@@ -87,7 +91,7 @@ class Tools implements ControllerProviderInterface
$controllers->post('/image/', function(Application $app, Request $request) { $controllers->post('/image/', function(Application $app, Request $request) {
$return = array('success' => true); $return = array('success' => true);
$helper = new Helper\Record\Tools($app['phraseanet.core'], $request); $helper = new Helper\Record\Tools($app, $request);
$selection = $helper->get_elements(); $selection = $helper->get_elements();
@@ -130,13 +134,14 @@ class Tools implements ControllerProviderInterface
try { try {
$record = new \record_adapter( $record = new \record_adapter(
$app,
$request->request->get('sbas_id') $request->request->get('sbas_id')
, $request->request->get('record_id') , $request->request->get('record_id')
); );
$media = $app['phraseanet.core']['mediavorus']->guess($tempoFile); $media = $app['mediavorus']->guess($tempoFile);
$record->substitute_subdef('document', $media, $app['filesystem'], $app['phraseanet.core']['media-alchemyst'], $app['phraseanet.core']['mediavorus']); $record->substitute_subdef('document', $media, $app);
if ((int) $request->request->get('ccfilename') === 1) { if ((int) $request->request->get('ccfilename') === 1) {
$record->set_original_name($fileName); $record->set_original_name($fileName);
@@ -180,18 +185,19 @@ class Tools implements ControllerProviderInterface
if ($size && $fileName && $file->isValid()) { if ($size && $fileName && $file->isValid()) {
try { try {
$rootPath = $app['phraseanet.core']->getRegistry()->get('GV_RootPath'); $rootPath = $app['phraseanet.registry']->get('GV_RootPath');
$tmpFile = $rootPath . 'tmp/' . $fileName; $tmpFile = $rootPath . 'tmp/' . $fileName;
rename($file->getPathname(), $tmpFile); rename($file->getPathname(), $tmpFile);
$record = new \record_adapter( $record = new \record_adapter(
$app,
$request->request->get('sbas_id') $request->request->get('sbas_id')
, $request->request->get('record_id') , $request->request->get('record_id')
); );
$media = $app['phraseanet.core']['mediavorus']->guess($file); $media = $app['mediavorus']->guess($tmpFile);
$record->substitute_subdef('thumbnail', $media); $record->substitute_subdef('thumbnail', $media, $app);
$success = true; $success = true;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -217,7 +223,7 @@ class Tools implements ControllerProviderInterface
$template = 'prod/actions/Tools/confirm.html.twig'; $template = 'prod/actions/Tools/confirm.html.twig';
try { try {
$record = new \record_adapter($request->request->get('sbas_id'), $request->request->get('record_id')); $record = new \record_adapter($app, $request->request->get('sbas_id'), $request->request->get('record_id'));
$var = array( $var = array(
'video_title' => $record->get_title() 'video_title' => $record->get_title()
, 'image' => $request->request->get('image', '') , 'image' => $request->request->get('image', '')
@@ -235,11 +241,11 @@ class Tools implements ControllerProviderInterface
$return = array('success' => false, 'message' => ''); $return = array('success' => false, 'message' => '');
try { try {
$record = new \record_adapter($request->request->get('sbas_id'), $request->request->get('record_id')); $record = new \record_adapter($app, $request->request->get('sbas_id'), $request->request->get('record_id'));
$dataUri = DataURI\Parser::parse($request->request->get('image', '')); $dataUri = DataURI\Parser::parse($request->request->get('image', ''));
$path = $app['phraseanet.core']->getRegistry()->get('GV_RootPath') . 'tmp'; $path = $app['phraseanet.registry']->get('GV_RootPath') . 'tmp';
$name = sprintf('extractor_thumb_%s', $record->get_serialize_key()); $name = sprintf('extractor_thumb_%s', $record->get_serialize_key());
@@ -247,9 +253,9 @@ class Tools implements ControllerProviderInterface
file_put_contents($fileName, $dataUri->getData()); file_put_contents($fileName, $dataUri->getData());
$media = $app['phraseanet.core']['mediavorus']->guess(new \SplFileInfo($fileName)); $media = $app['mediavorus']->guess($fileName);
$record->substitute_subdef('thumbnail', $media); $record->substitute_subdef('thumbnail', $media, $app);
unset($media); unset($media);
$app['filesystem']->remove($fileName); $app['filesystem']->remove($fileName);

View File

@@ -65,24 +65,22 @@ class Tooltip implements ControllerProviderInterface
public function displayBasket(Application $app, $basket_id) public function displayBasket(Application $app, $basket_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], false);
$basket = $em->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), false);
return $app['twig']->render('prod/Tooltip/Basket.html.twig', array('basket' => $basket)); return $app['twig']->render('prod/Tooltip/Basket.html.twig', array('basket' => $basket));
} }
public function displayStory(Application $app, $sbas_id, $record_id) public function displayStory(Application $app, $sbas_id, $record_id)
{ {
$Story = new \record_adapter($sbas_id, $record_id); $Story = new \record_adapter($app, $sbas_id, $record_id);
return $app['twig']->render('prod/Tooltip/Story.html.twig', array('Story' => $Story)); return $app['twig']->render('prod/Tooltip/Story.html.twig', array('Story' => $Story));
} }
public function displayUserBadge(Application $app, $usr_id) public function displayUserBadge(Application $app, $usr_id)
{ {
$user = \User_Adapter::getInstance($usr_id, $app['phraseanet.appbox']); $user = \User_Adapter::getInstance($usr_id, $app);
return $app['twig']->render( return $app['twig']->render(
'prod/Tooltip/User.html.twig' 'prod/Tooltip/User.html.twig'
@@ -92,7 +90,7 @@ class Tooltip implements ControllerProviderInterface
public function displayPreview(Application $app, $sbas_id, $record_id) public function displayPreview(Application $app, $sbas_id, $record_id)
{ {
$record = new \record_adapter($sbas_id, $record_id); $record = new \record_adapter($app, $sbas_id, $record_id);
return $app['twig']->render( return $app['twig']->render(
'prod/Tooltip/Preview.html.twig' 'prod/Tooltip/Preview.html.twig'
@@ -103,13 +101,13 @@ class Tooltip implements ControllerProviderInterface
public function displayCaption(Application $app, $sbas_id, $record_id, $context) public function displayCaption(Application $app, $sbas_id, $record_id, $context)
{ {
$number = (int) $app['request']->request->get('number'); $number = (int) $app['request']->request->get('number');
$record = new \record_adapter($sbas_id, $record_id, $number); $record = new \record_adapter($app, $sbas_id, $record_id, $number);
$search_engine = null; $search_engine = null;
if ($context == 'answer') { if ($context == 'answer') {
if (($search_engine_options = unserialize($app['request']->request->get('options_serial'))) !== false) { if (($search_engine_options = unserialize($app['request']->request->get('options_serial'))) !== false) {
$search_engine = new \searchEngine_adapter($app['phraseanet.appbox']->get_registry()); $search_engine = new \searchEngine_adapter($app);
$search_engine->set_options($search_engine_options); $search_engine->set_options($search_engine_options);
} }
} }
@@ -127,7 +125,7 @@ class Tooltip implements ControllerProviderInterface
public function displayTechnicalDatas(Application $app, $sbas_id, $record_id) public function displayTechnicalDatas(Application $app, $sbas_id, $record_id)
{ {
$record = new \record_adapter($sbas_id, $record_id); $record = new \record_adapter($app, $sbas_id, $record_id);
return $app['twig']->render( return $app['twig']->render(
'prod/Tooltip/TechnicalDatas.html.twig' 'prod/Tooltip/TechnicalDatas.html.twig'
@@ -138,7 +136,7 @@ class Tooltip implements ControllerProviderInterface
public function displayFieldInfos(Application $app, $sbas_id, $field_id) public function displayFieldInfos(Application $app, $sbas_id, $field_id)
{ {
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$field = \databox_field::get_instance($databox, $field_id); $field = \databox_field::get_instance($app, $databox, $field_id);
return $app['twig']->render( return $app['twig']->render(
'prod/Tooltip/DataboxField.html.twig' 'prod/Tooltip/DataboxField.html.twig'
@@ -149,7 +147,7 @@ class Tooltip implements ControllerProviderInterface
public function displayDCESInfos(Application $app, $sbas_id, $field_id) public function displayDCESInfos(Application $app, $sbas_id, $field_id)
{ {
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$field = \databox_field::get_instance($databox, $field_id); $field = \databox_field::get_instance($app, $databox, $field_id);
return $app['twig']->render( return $app['twig']->render(
'prod/Tooltip/DCESFieldInfo.html.twig' 'prod/Tooltip/DCESFieldInfo.html.twig'
@@ -160,7 +158,7 @@ class Tooltip implements ControllerProviderInterface
public function displayMetaRestrictions(Application $app, $sbas_id, $field_id) public function displayMetaRestrictions(Application $app, $sbas_id, $field_id)
{ {
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$field = \databox_field::get_instance($databox, $field_id); $field = \databox_field::get_instance($app, $databox, $field_id);
return $app['twig']->render( return $app['twig']->render(
'prod/Tooltip/DataboxFieldRestrictions.html.twig' 'prod/Tooltip/DataboxFieldRestrictions.html.twig'

View File

@@ -108,7 +108,7 @@ class Upload implements ControllerProviderInterface
return $app['twig']->render( return $app['twig']->render(
'prod/upload/upload-flash.html.twig', array( 'prod/upload/upload-flash.html.twig', array(
'sessionId' => session_id(), 'sessionId' => session_id(),
'collections' => $this->getGrantedCollections($app['phraseanet.core']->getAuthenticatedUser()), 'collections' => $this->getGrantedCollections($app['phraseanet.user']),
'maxFileSize' => $maxFileSize, 'maxFileSize' => $maxFileSize,
'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize)
) )
@@ -129,7 +129,7 @@ class Upload implements ControllerProviderInterface
return $app['twig']->render( return $app['twig']->render(
'prod/upload/upload.html.twig', array( 'prod/upload/upload.html.twig', array(
'collections' => $this->getGrantedCollections($app['phraseanet.core']->getAuthenticatedUser()), 'collections' => $this->getGrantedCollections($app['phraseanet.user']),
'maxFileSize' => $maxFileSize, 'maxFileSize' => $maxFileSize,
'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize)
) )
@@ -169,7 +169,7 @@ class Upload implements ControllerProviderInterface
throw new \Exception_BadRequest('Missing base_id parameter'); throw new \Exception_BadRequest('Missing base_id parameter');
} }
if ( ! $app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right_on_base($base_id, 'canaddrecord')) { if ( ! $app['phraseanet.user']->ACL()->has_right_on_base($base_id, 'canaddrecord')) {
throw new \Exception_Forbidden('User is not allowed to add record on this collection'); throw new \Exception_Forbidden('User is not allowed to add record on this collection');
} }
@@ -184,22 +184,15 @@ class Upload implements ControllerProviderInterface
$uploadedFilename = $file->getRealPath(); $uploadedFilename = $file->getRealPath();
$renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); $renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
$originalname = $file->getClientOriginalName();
$clientMimeType = $file->getClientMimeType();
$size = $file->getSize();
$error = $file->getError();
$app['filesystem']->rename($uploadedFilename, $renamedFilename); $app['filesystem']->rename($uploadedFilename, $renamedFilename);
$file = new UploadedFile($renamedFilename, $originalname, $clientMimeType, $size, $error); $media = $app['mediavorus']->guess($renamedFilename);
$collection = \collection::get_from_base_id($app, $base_id);
$media = $app['phraseanet.core']['mediavorus']->guess($file);
$collection = \collection::get_from_base_id($base_id);
$lazaretSession = new LazaretSession(); $lazaretSession = new LazaretSession();
$lazaretSession->setUsrId($app['phraseanet.core']->getAuthenticatedUser()->get_id()); $lazaretSession->setUsrId($app['phraseanet.user']->get_id());
$app['phraseanet.core']['EM']->persist($lazaretSession); $app['EM']->persist($lazaretSession);
$packageFile = new File($media, $collection, $file->getClientOriginalName()); $packageFile = new File($media, $collection, $file->getClientOriginalName());
@@ -212,7 +205,7 @@ class Upload implements ControllerProviderInterface
foreach (range(0, 63) as $i) { foreach (range(0, 63) as $i) {
$status .= isset($postStatus[$i]) ? ($postStatus[$i] ? '1' : '0') : '0'; $status .= isset($postStatus[$i]) ? ($postStatus[$i] ? '1' : '0') : '0';
} }
$packageFile->addAttribute(new Status(strrev($status))); $packageFile->addAttribute(new Status($app, strrev($status)));
} }
$forceBehavior = $request->request->get('forceAction'); $forceBehavior = $request->request->get('forceAction');
@@ -230,7 +223,7 @@ class Upload implements ControllerProviderInterface
$elementCreated = $element; $elementCreated = $element;
}; };
$code = $app['phraseanet.core']['border-manager']->process( $code = $app['border-manager']->process(
$lazaretSession, $packageFile, $callback, $forceBehavior $lazaretSession, $packageFile, $callback, $forceBehavior
); );
@@ -249,7 +242,7 @@ class Upload implements ControllerProviderInterface
$appbox = $app['phraseanet.appbox']; $appbox = $app['phraseanet.appbox'];
$eventsManager = $app['phraseanet.core']['events-manager']; $eventsManager = $app['events-manager'];
$eventsManager->trigger('__UPLOAD_QUARANTINE__', $params); $eventsManager->trigger('__UPLOAD_QUARANTINE__', $params);
$id = $elementCreated->getId(); $id = $elementCreated->getId();

View File

@@ -37,7 +37,7 @@ class UserPreferences implements ControllerProviderInterface
$ret = array('success' => false, 'message' => _('Error while saving preference')); $ret = array('success' => false, 'message' => _('Error while saving preference'));
try { try {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$ret = $user->setPrefs($request->request->get('prop'), $request->request->get('value')); $ret = $user->setPrefs($request->request->get('prop'), $request->request->get('value'));

View File

@@ -103,11 +103,9 @@ class UsrLists implements ControllerProviderInterface
$lists = new ArrayCollection(); $lists = new ArrayCollection();
try { try {
$em = $app['phraseanet.core']->getEntityManager(); $repository = $app['EM']->getRepository('\Entities\UsrList');
$repository = $em->getRepository('\Entities\UsrList'); $lists = $repository->findUserLists($app['phraseanet.user']);
$lists = $repository->findUserLists($app['phraseanet.core']->getAuthenticatedUser());
$result = array(); $result = array();
@@ -116,24 +114,24 @@ class UsrLists implements ControllerProviderInterface
foreach ($list->getOwners() as $owner) { foreach ($list->getOwners() as $owner) {
$owners[] = array( $owners[] = array(
'usr_id' => $owner->getUser()->get_id(), 'usr_id' => $owner->getUser($app)->get_id(),
'display_name' => $owner->getUser()->get_display_name(), 'display_name' => $owner->getUser($app)->get_display_name(),
'position' => $owner->getUser()->get_position(), 'position' => $owner->getUser($app)->get_position(),
'job' => $owner->getUser()->get_job(), 'job' => $owner->getUser($app)->get_job(),
'company' => $owner->getUser()->get_company(), 'company' => $owner->getUser($app)->get_company(),
'email' => $owner->getUser()->get_email(), 'email' => $owner->getUser($app)->get_email(),
'role' => $owner->getRole() 'role' => $owner->getRole()
); );
} }
foreach ($list->getEntries() as $entry) { foreach ($list->getEntries() as $entry) {
$entries[] = array( $entries[] = array(
'usr_id' => $owner->getUser()->get_id(), 'usr_id' => $owner->getUser($app)->get_id(),
'display_name' => $owner->getUser()->get_display_name(), 'display_name' => $owner->getUser($app)->get_display_name(),
'position' => $owner->getUser()->get_position(), 'position' => $owner->getUser($app)->get_position(),
'job' => $owner->getUser()->get_job(), 'job' => $owner->getUser($app)->get_job(),
'company' => $owner->getUser()->get_company(), 'company' => $owner->getUser($app)->get_company(),
'email' => $owner->getUser()->get_email(), 'email' => $owner->getUser($app)->get_email(),
); );
} }
@@ -185,21 +183,19 @@ class UsrLists implements ControllerProviderInterface
throw new ControllerException(_('List name is required')); throw new ControllerException(_('List name is required'));
} }
$em = $app['phraseanet.core']->getEntityManager();
$List = new UsrList(); $List = new UsrList();
$Owner = new UsrListOwner(); $Owner = new UsrListOwner();
$Owner->setRole(UsrListOwner::ROLE_ADMIN); $Owner->setRole(UsrListOwner::ROLE_ADMIN);
$Owner->setUser($app['phraseanet.core']->getAuthenticatedUser()); $Owner->setUser($app['phraseanet.user']);
$Owner->setList($List); $Owner->setList($List);
$List->setName($list_name); $List->setName($list_name);
$List->addUsrListOwner($Owner); $List->addUsrListOwner($Owner);
$em->persist($Owner); $app['EM']->persist($Owner);
$em->persist($List); $app['EM']->persist($List);
$em->flush(); $app['EM']->flush();
$datas = array( $datas = array(
'success' => true 'success' => true
@@ -220,36 +216,35 @@ class UsrLists implements ControllerProviderInterface
public function displayList(Application $app, Request $request, $list_id) public function displayList(Application $app, Request $request, $list_id)
{ {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$em = $app['phraseanet.core']->getEntityManager();
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
$entries = new ArrayCollection(); $entries = new ArrayCollection();
$owners = new ArrayCollection(); $owners = new ArrayCollection();
foreach ($list->getOwners() as $owner) { foreach ($list->getOwners() as $owner) {
$owners[] = array( $owners[] = array(
'usr_id' => $owner->getUser()->get_id(), 'usr_id' => $owner->getUser($app)->get_id(),
'display_name' => $owner->getUser()->get_display_name(), 'display_name' => $owner->getUser($app)->get_display_name(),
'position' => $owner->getUser()->get_position(), 'position' => $owner->getUser($app)->get_position(),
'job' => $owner->getUser()->get_job(), 'job' => $owner->getUser($app)->get_job(),
'company' => $owner->getUser()->get_company(), 'company' => $owner->getUser($app)->get_company(),
'email' => $owner->getUser()->get_email(), 'email' => $owner->getUser($app)->get_email(),
'role' => $owner->getRole() 'role' => $owner->getRole($app)
); );
} }
foreach ($list->getEntries() as $entry) { foreach ($list->getEntries() as $entry) {
$entries[] = array( $entries[] = array(
'usr_id' => $entry->getUser()->get_id(), 'usr_id' => $entry->getUser($app)->get_id(),
'display_name' => $entry->getUser()->get_display_name(), 'display_name' => $entry->getUser($app)->get_display_name(),
'position' => $entry->getUser()->get_position(), 'position' => $entry->getUser($app)->get_position(),
'job' => $entry->getUser()->get_job(), 'job' => $entry->getUser($app)->get_job(),
'company' => $entry->getUser()->get_company(), 'company' => $entry->getUser($app)->get_company(),
'email' => $entry->getUser()->get_email(), 'email' => $entry->getUser($app)->get_email(),
); );
} }
@@ -281,20 +276,19 @@ class UsrLists implements ControllerProviderInterface
throw new ControllerException(_('List name is required')); throw new ControllerException(_('List name is required'));
} }
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$em = $app['phraseanet.core']->getEntityManager();
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_EDITOR) { if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_EDITOR) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
$list->setName($list_name); $list->setName($list_name);
$em->flush(); $app['EM']->flush();
$datas = array( $datas = array(
'success' => true 'success' => true
@@ -314,21 +308,19 @@ class UsrLists implements ControllerProviderInterface
public function removeList(Application $app, $list_id) public function removeList(Application $app, $list_id)
{ {
$em = $app['phraseanet.core']->getEntityManager();
try { try {
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_ADMIN) { if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_ADMIN) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
$em->remove($list); $app['EM']->remove($list);
$em->flush(); $app['EM']->flush();
$datas = array( $datas = array(
'success' => true 'success' => true
@@ -352,26 +344,24 @@ class UsrLists implements ControllerProviderInterface
public function removeUser(Application $app, $list_id, $usr_id) public function removeUser(Application $app, $list_id, $usr_id)
{ {
$em = $app['phraseanet.core']->getEntityManager();
try { try {
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_EDITOR) { if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_EDITOR) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
$entry_repository = $em->getRepository('\Entities\UsrListEntry'); $entry_repository = $app['EM']->getRepository('\Entities\UsrListEntry');
$user_entry = $entry_repository->findEntryByListAndUsrId($list, $usr_id); $user_entry = $entry_repository->findEntryByListAndUsrId($list, $usr_id);
$em->remove($user_entry); $app['EM']->remove($user_entry);
$em->flush(); $app['EM']->flush();
$datas = array( $datas = array(
'success' => true 'success' => true
@@ -395,29 +385,28 @@ class UsrLists implements ControllerProviderInterface
public function addUsers(Application $app, Request $request, $list_id) public function addUsers(Application $app, Request $request, $list_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
try { try {
if ( ! is_array($request->request->get('usr_ids'))) { if ( ! is_array($request->request->get('usr_ids'))) {
throw new ControllerException('Invalid or missing parameter usr_ids'); throw new ControllerException('Invalid or missing parameter usr_ids');
} }
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_EDITOR) { if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_EDITOR) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
$inserted_usr_ids = array(); $inserted_usr_ids = array();
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['phraseanet.appbox']); $user_entry = \User_Adapter::getInstance($usr_id, $app);
if ($list->has($user_entry)) if ($list->has($user_entry, $app))
continue; continue;
$entry = new UsrListEntry(); $entry = new UsrListEntry();
@@ -426,12 +415,12 @@ class UsrLists implements ControllerProviderInterface
$list->addUsrListEntry($entry); $list->addUsrListEntry($entry);
$em->persist($entry); $app['EM']->persist($entry);
$inserted_usr_ids[] = $user_entry->get_id(); $inserted_usr_ids[] = $user_entry->get_id();
} }
$em->flush(); $app['EM']->flush();
if (count($inserted_usr_ids) > 1) { if (count($inserted_usr_ids) > 1) {
$datas = array( $datas = array(
@@ -464,18 +453,17 @@ class UsrLists implements ControllerProviderInterface
public function displayShares(Application $app, Request $request, $list_id) public function displayShares(Application $app, Request $request, $list_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
$list = null; $list = null;
try { try {
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_ADMIN) { if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_ADMIN) {
$list = null; $list = null;
throw new \Exception(_('You are not authorized to do this')); throw new \Exception(_('You are not authorized to do this'));
} }
@@ -488,8 +476,7 @@ class UsrLists implements ControllerProviderInterface
public function shareWithUser(Application $app, $list_id, $usr_id) public function shareWithUser(Application $app, $list_id, $usr_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
$availableRoles = array( $availableRoles = array(
UsrListOwner::ROLE_USER, UsrListOwner::ROLE_USER,
@@ -503,23 +490,23 @@ class UsrLists implements ControllerProviderInterface
throw new \Exception_BadRequest('Role is invalid'); throw new \Exception_BadRequest('Role is invalid');
try { try {
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_EDITOR) { if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_EDITOR) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
$new_owner = \User_Adapter::getInstance($usr_id, $app['phraseanet.appbox']); $new_owner = \User_Adapter::getInstance($usr_id, $app);
if ($list->hasAccess($new_owner)) { if ($list->hasAccess($new_owner, $app)) {
if ($new_owner->get_id() == $user->get_id()) { if ($new_owner->get_id() == $user->get_id()) {
throw new ControllerException('You can not downgrade your Admin right'); throw new ControllerException('You can not downgrade your Admin right');
} }
$owner = $list->getOwner($new_owner); $owner = $list->getOwner($new_owner, $app);
} else { } else {
$owner = new UsrListOwner(); $owner = new UsrListOwner();
$owner->setList($list); $owner->setList($list);
@@ -527,14 +514,14 @@ class UsrLists implements ControllerProviderInterface
$list->addUsrListOwner($owner); $list->addUsrListOwner($owner);
$em->persist($owner); $app['EM']->persist($owner);
} }
$role = $app['request']->request->get('role'); $role = $app['request']->request->get('role');
$owner->setRole($role); $owner->setRole($role);
$em->flush(); $app['EM']->flush();
$datas = array( $datas = array(
'success' => true 'success' => true
@@ -558,25 +545,24 @@ class UsrLists implements ControllerProviderInterface
public function unshareWithUser(Application $app, $list_id, $usr_id) public function unshareWithUser(Application $app, $list_id, $usr_id)
{ {
$em = $app['phraseanet.core']->getEntityManager(); $user = $app['phraseanet.user'];
$user = $app['phraseanet.core']->getAuthenticatedUser();
try { try {
$repository = $em->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($app, $user, $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($user)->getRole() < UsrListOwner::ROLE_ADMIN) { if ($list->getOwner($user, $app)->getRole() < UsrListOwner::ROLE_ADMIN) {
throw new \Exception(_('You are not authorized to do this')); throw new \Exception(_('You are not authorized to do this'));
} }
$owners_repository = $em->getRepository('\Entities\UsrListOwner'); $owners_repository = $app['EM']->getRepository('\Entities\UsrListOwner');
$owner = $owners_repository->findByListAndUsrId($list, $usr_id); $owner = $owners_repository->findByListAndUsrId($list, $usr_id);
$em->remove($owner); $app['EM']->remove($owner);
$em->flush(); $app['EM']->flush();
$datas = array( $datas = array(
'success' => true 'success' => true

View File

@@ -50,7 +50,7 @@ class WorkZone implements ControllerProviderInterface
public function displayWorkzone(Application $app) public function displayWorkzone(Application $app)
{ {
$params = array( $params = array(
'WorkZone' => new WorkzoneHelper($app['phraseanet.core'], $app['request']) 'WorkZone' => new WorkzoneHelper($app, $app['request'])
, 'selected_type' => $app['request']->query->get('type') , 'selected_type' => $app['request']->query->get('type')
, 'selected_id' => $app['request']->query->get('id') , 'selected_id' => $app['request']->query->get('id')
, 'srt' => $app['request']->query->get('sort') , 'srt' => $app['request']->query->get('sort')
@@ -66,14 +66,11 @@ class WorkZone implements ControllerProviderInterface
public function browserSearch(Application $app) public function browserSearch(Application $app)
{ {
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$request = $app['request']; $request = $app['request'];
$em = $app['phraseanet.core']->getEntityManager(); $BasketRepo = $app['EM']->getRepository('\Entities\Basket');
/* @var $em \Doctrine\ORM\EntityManager */
$BasketRepo = $em->getRepository('\Entities\Basket');
$Page = (int) $request->query->get('Page', 0); $Page = (int) $request->query->get('Page', 0);
@@ -107,10 +104,9 @@ class WorkZone implements ControllerProviderInterface
public function browseBasket(Application $app, Request $request, $basket_id) public function browseBasket(Application $app, Request $request, $basket_id)
{ {
$basket = $app['phraseanet.core'] $basket = $app['EM']
->getEntityManager()
->getRepository('\Entities\Basket') ->getRepository('\Entities\Basket')
->findUserBasket($basket_id, $app['phraseanet.core']->getAuthenticatedUser(), false); ->findUserBasket($app, $basket_id, $app['phraseanet.user'], false);
return $app['twig']->render('prod/WorkZone/Browser/Basket.html.twig', array('Basket' => $basket)); return $app['twig']->render('prod/WorkZone/Browser/Basket.html.twig', array('Basket' => $basket));
} }
@@ -121,12 +117,9 @@ class WorkZone implements ControllerProviderInterface
throw new \Exception_BadRequest(); throw new \Exception_BadRequest();
} }
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$em = $app['phraseanet.core']->getEntityManager(); $StoryWZRepo = $app['EM']->getRepository('\Entities\StoryWZ');
/* @var $em \Doctrine\ORM\EntityManager */
$StoryWZRepo = $em->getRepository('\Entities\StoryWZ');
$alreadyFixed = $done = 0; $alreadyFixed = $done = 0;
@@ -134,7 +127,7 @@ class WorkZone implements ControllerProviderInterface
foreach ($stories as $element) { foreach ($stories as $element) {
$element = explode('_', $element); $element = explode('_', $element);
$Story = new \record_adapter($element[0], $element[1]); $Story = new \record_adapter($app, $element[0], $element[1]);
if ( ! $Story->is_grouping()) { if ( ! $Story->is_grouping()) {
throw new \Exception('You can only attach stories'); throw new \Exception('You can only attach stories');
@@ -144,7 +137,7 @@ class WorkZone implements ControllerProviderInterface
throw new \Exception_Forbidden('You do not have access to this Story'); throw new \Exception_Forbidden('You do not have access to this Story');
} }
if ($StoryWZRepo->findUserStory($user, $Story)) { if ($StoryWZRepo->findUserStory($app, $user, $Story)) {
$alreadyFixed ++; $alreadyFixed ++;
continue; continue;
} }
@@ -153,11 +146,11 @@ class WorkZone implements ControllerProviderInterface
$StoryWZ->setUser($user); $StoryWZ->setUser($user);
$StoryWZ->setRecord($Story); $StoryWZ->setRecord($Story);
$em->persist($StoryWZ); $app['EM']->persist($StoryWZ);
$done ++; $done ++;
} }
$em->flush(); $app['EM']->flush();
if ($alreadyFixed === 0) { if ($alreadyFixed === 0) {
if ($done <= 1) { if ($done <= 1) {
@@ -199,23 +192,21 @@ class WorkZone implements ControllerProviderInterface
public function detachStory(Application $app, Request $request, $sbas_id, $record_id) public function detachStory(Application $app, Request $request, $sbas_id, $record_id)
{ {
$Story = new \record_adapter($sbas_id, $record_id); $Story = new \record_adapter($app, $sbas_id, $record_id);
$user = $app['phraseanet.core']->getAuthenticatedUser(); $user = $app['phraseanet.user'];
$em = $app['phraseanet.core']->getEntityManager(); $repository = $app['EM']->getRepository('\Entities\StoryWZ');
$repository = $em->getRepository('\Entities\StoryWZ');
/* @var $repository \Repositories\StoryWZRepository */ /* @var $repository \Repositories\StoryWZRepository */
$StoryWZ = $repository->findUserStory($user, $Story); $StoryWZ = $repository->findUserStory($app, $user, $Story);
if ( ! $StoryWZ) { if ( ! $StoryWZ) {
throw new \Exception_NotFound('Story not found'); throw new \Exception_NotFound('Story not found');
} }
$em->remove($StoryWZ); $app['EM']->remove($StoryWZ);
$em->flush(); $app['EM']->flush();
if ($request->getRequestFormat() == 'json') { if ($request->getRequestFormat() == 'json') {
return $app->json(array( return $app->json(array(