diff --git a/lib/Alchemy/Phrasea/Application/Admin.php b/lib/Alchemy/Phrasea/Application/Admin.php deleted file mode 100644 index c606137027..0000000000 --- a/lib/Alchemy/Phrasea/Application/Admin.php +++ /dev/null @@ -1,58 +0,0 @@ -mount('/', new Root()); - $controllers->mount('/dashboard', new Dashboard()); - $controllers->mount('/collection', new Collection()); - $controllers->mount('/databox', new Databox()); - $controllers->mount('/databoxes', new Databoxes()); - $controllers->mount('/setup', new Setup()); - $controllers->mount('/sphinx', new Sphinx()); - $controllers->mount('/connected-users', new ConnectedUsers()); - $controllers->mount('/publications', new Publications()); - $controllers->mount('/users', new Users()); - $controllers->mount('/fields', new Fields()); - $controllers->mount('/subdefs', new Subdefs()); - $controllers->mount('/description', new Description()); - $controllers->mount('/tests/connection', new ConnectionTest()); - $controllers->mount('/tests/pathurl', new PathFileTest()); - - return $controllers; - } -} diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index c079aabb02..ac318b5751 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -11,741 +11,695 @@ namespace Alchemy\Phrasea\Application; -use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\BaseApplication; use Silex\Application as SilexApplication; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ return call_user_func(function($environment = 'prod') { - $app = new PhraseaApplication($environment); + $app = new BaseApplication($environment); + /** + * disable session + */ + $app['session.test'] = true; - /** - * @var API_OAuth2_Token - */ - $app['token'] = null; + /** + * @var API_OAuth2_Token + */ + $app['token'] = null; - /** - * Api Service - * @var Closure - */ - $app['api'] = function () use ($app) { - return new \API_V1_adapter($app); - }; + /** + * Api Service + * @var Closure + */ + $app['api'] = function () use ($app) { + return new \API_V1_adapter($app); + }; - /** - * oAuth token verification process - * - Check if oauth_token exists && is valid - * - Check if request comes from phraseanet Navigator && phraseanet Navigator - * is enbale on current instance - * - restore user session - * - * @ throws \API_V1_exception_unauthorized - * @ throws \API_V1_exception_forbidden - */ - $app->before(function($request) use ($app) { - $registry = $app['phraseanet.registry']; - $oauth2_adapter = new \API_OAuth2_Adapter($app); - $oauth2_adapter->verifyAccessToken(); + /** + * oAuth token verification process + * - Check if oauth_token exists && is valid + * - Check if request comes from phraseanet Navigator && phraseanet Navigator + * is enbale on current instance + * - restore user session + * + * @ throws \API_V1_exception_unauthorized + * @ throws \API_V1_exception_forbidden + */ + $app->before(function($request) use ($app) { + $oauth2_adapter = new \API_OAuth2_Adapter($app); + $oauth2_adapter->verifyAccessToken(); - $app['token'] = \API_OAuth2_Token::load_by_oauth_token($app, $oauth2_adapter->getToken()); + $app['token'] = \API_OAuth2_Token::load_by_oauth_token($app, $oauth2_adapter->getToken()); - $oAuth2App = $app['token']->get_account()->get_application(); - /* @var $oAuth2App \API_OAuth2_Application */ + $oAuth2App = $app['token']->get_account()->get_application(); + /* @var $oAuth2App \API_OAuth2_Application */ - if ($oAuth2App->get_client_id() == \API_OAuth2_Application_Navigator::CLIENT_ID - && !$registry->get('GV_client_navigator')) { - throw new \API_V1_exception_forbidden(_('The use of phraseanet Navigator is not allowed')); - } + if ($oAuth2App->get_client_id() == \API_OAuth2_Application_Navigator::CLIENT_ID + && !$app['phraseanet.registry']->get('GV_client_navigator')) { + throw new \API_V1_exception_forbidden(_('The use of phraseanet Navigator is not allowed')); + } - if ($app->isAuthenticated()) { - return; - } + if ($app->isAuthenticated()) { + return; + } - $user = \User_Adapter::getInstance($oauth2_adapter->get_usr_id(), $app); - $auth = new \Session_Authentication_None($user); + $user = \User_Adapter::getInstance($oauth2_adapter->get_usr_id(), $app); + $auth = new \Session_Authentication_None($user); - $app->openAccount($auth, $oauth2_adapter->get_ses_id()); + $app->openAccount($auth, $oauth2_adapter->get_ses_id()); + $oauth2_adapter->remember_this_ses_id($app['session']->get('phrasea_session_id')); - /** - * TODO Neutron => remove - */ - $oauth2_adapter->remember_this_ses_id($app['session']->get('phrasea_session_id')); + return; + }); - return; - }); + /** + * OAuth log process + * + * Parse the requested route to fetch + * - the ressource (databox, basket, record etc ..) + * - general action (list, add, search) + * - the action (setstatus, setname etc..) + * - the aspect (collections, related, content etc..) + * + * @return array + */ + $parseRoute = function ($route, Response $response) { + $ressource = $general = $aspect = $action = null; + $exploded_route = explode('/', \p4string::delFirstSlash(\p4string::delEndSlash($route))); + if (sizeof($exploded_route) > 0 && $response->isOk()) { + $ressource = $exploded_route[0]; - /** - * OAuth log process - * - * Parse the requested route to fetch - * - the ressource (databox, basket, record etc ..) - * - general action (list, add, search) - * - the action (setstatus, setname etc..) - * - the aspect (collections, related, content etc..) - * - * @return array - */ - $parseRoute = function ($route, Response $response) { - $ressource = $general = $aspect = $action = null; - $exploded_route = explode('/', \p4string::delFirstSlash(\p4string::delEndSlash($route))); - if (sizeof($exploded_route) > 0 && $response->isOk()) { - $ressource = $exploded_route[0]; - - if (sizeof($exploded_route) == 2 && (int) $exploded_route[1] == 0) { - $general = $exploded_route[1]; - } else { - switch ($ressource) { - case \API_V1_Log::DATABOXES_RESSOURCE : - if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3) - $aspect = $exploded_route[2]; - break; - case \API_V1_Log::RECORDS_RESSOURCE : - if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 4) { - if (!isset($exploded_route[3])) - $aspect = "record"; - elseif (preg_match("/^set/", $exploded_route[3])) - $action = $exploded_route[3]; - else - $aspect = $exploded_route[3]; - } - break; - case \API_V1_Log::BASKETS_RESSOURCE : - if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3) { - if (preg_match("/^set/", $exploded_route[2]) || preg_match("/^delete/", $exploded_route[2])) - $action = $exploded_route[2]; - else - $aspect = $exploded_route[2]; - } - break; - case \API_V1_Log::FEEDS_RESSOURCE : - if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3) - $aspect = $exploded_route[2]; - break; - } + if (sizeof($exploded_route) == 2 && (int) $exploded_route[1] == 0) { + $general = $exploded_route[1]; + } else { + switch ($ressource) { + case \API_V1_Log::DATABOXES_RESSOURCE : + if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3) + $aspect = $exploded_route[2]; + break; + case \API_V1_Log::RECORDS_RESSOURCE : + if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 4) { + if (!isset($exploded_route[3])) + $aspect = "record"; + elseif (preg_match("/^set/", $exploded_route[3])) + $action = $exploded_route[3]; + else + $aspect = $exploded_route[3]; } - } - - return array('ressource' => $ressource, 'general' => $general, 'aspect' => $aspect, 'action' => $action); - }; - - /** - * Log occurs in after filter - */ - $app->after(function (Request $request, Response $response) use ($app, $parseRoute) { - $account = $app['token']->get_account(); - $pathInfo = $request->getPathInfo(); - $route = $parseRoute($pathInfo, $response); - \API_V1_Log::create( - $app - , $account - , $request->getMethod() . " " . $pathInfo - , $response->getStatusCode() - , $response->headers->get('content-type') - , $route['ressource'] - , $route['general'] - , $route['aspect'] - , $route['action'] - ); - }); - - /** - * Method Not Allowed Closure - */ - $bad_request_exception = function() { - throw new \API_V1_exception_badrequest(); - }; - - /** - * Check wether the current user is Admin or not - */ - $mustBeAdmin = function (Request $request) use ($app) { - /* @var $user \User_Adapter */ - $user = $app['token']->get_account()->get_user(); - if (!$user->ACL()->is_admin()) { - throw new \API_V1_exception_unauthorized('You are not authorized'); - } - }; - - /** - * Get scheduler informations - * - * Route : /monitor/scheduler/ - * - * Method : GET - * - * Parameters : - * - */ - $route = '/monitor/scheduler/'; - $app->get( - $route, function(SilexApplication $app, Request $request) { - return $app['api']->get_scheduler($app)->get_response(); + break; + case \API_V1_Log::BASKETS_RESSOURCE : + if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3) { + if (preg_match("/^set/", $exploded_route[2]) || preg_match("/^delete/", $exploded_route[2])) + $action = $exploded_route[2]; + else + $aspect = $exploded_route[2]; + } + break; + case \API_V1_Log::FEEDS_RESSOURCE : + if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3) + $aspect = $exploded_route[2]; + break; } - )->before($mustBeAdmin); + } + } - /** - * Get all tasks information - * - * Route : /monitor/tasks/ - * - * Method : GET - * - * Parameters : - * - */ - $app->get('/monitor/tasks/', function(SilexApplication $app, Request $request) { - return $app['api']->get_task_list($app)->get_response(); - } - )->before($mustBeAdmin); + return array('ressource' => $ressource, 'general' => $general, 'aspect' => $aspect, 'action' => $action); + }; - /** - * Get task informations - * - * Route : /monitor/task/{task_id}/ - * - * Method : GET - * - * Parameters : - * - */ - $app->get('/monitor/task/{task_id}/', function(SilexApplication $app, Request $request, $task_id) { - return $app['api']->get_task($app, $task_id)->get_response(); - } - )->before($mustBeAdmin)->assert('task_id', '\d+'); + /** + * Log occurs in after filter + */ + $app->after(function (Request $request, Response $response) use ($app, $parseRoute) { + $account = $app['token']->get_account(); + $pathInfo = $request->getPathInfo(); + $route = $parseRoute($pathInfo, $response); + \API_V1_Log::create( + $app + , $account + , $request->getMethod() . " " . $pathInfo + , $response->getStatusCode() + , $response->headers->get('content-type') + , $route['ressource'] + , $route['general'] + , $route['aspect'] + , $route['action'] + ); + }); - /** - * Start task - * - * Route : /monitor/task/{task_id}/ - * - * Method : POST - * - * Parameters : - * - name (string) change the name of the task - * - autostart (boolean) start task when scheduler starts - */ - $app->post('/monitor/task/{task_id}/', function(SilexApplication $app, Request $request, $task_id) { - return $app['api']->set_task_property($app, $task_id)->get_response(); - } - )->before($mustBeAdmin)->assert('task_id', '\d+'); + /** + * Method Not Allowed Closure + */ + $bad_request_exception = function() { + throw new \API_V1_exception_badrequest(); + }; - /** - * Start task - * - * Route : /monitor/task/{task_id}/start/ - * - * Method : POST - * - * Parameters : - * - */ - $app->post('/monitor/task/{task_id}/start/', function(SilexApplication $app, Request $request, $task_id) { - return $app['api']->start_task($app, $task_id)->get_response(); - } - )->before($mustBeAdmin); + /** + * Check wether the current user is Admin or not + */ + $mustBeAdmin = function (Request $request) use ($app) { + /* @var $user \User_Adapter */ + $user = $app['token']->get_account()->get_user(); + if (!$user->ACL()->is_admin()) { + throw new \API_V1_exception_unauthorized('You are not authorized'); + } + }; - /** - * Stop task - * - * Route : /monitor/task/{task_id}/stop/ - * - * Method : POST - * - * Parameters : - * - */ - $app->post('/monitor/task/{task_id}/stop/', function(SilexApplication $app, Request $request, $task_id) { - return $app['api']->stop_task($app, $task_id)->get_response(); - } - )->before($mustBeAdmin); + /** + * Get scheduler informations + * + * Route : /monitor/scheduler/ + * + * Method : GET + * + * Parameters : + * + */ + $app->get('/monitor/scheduler/', function(SilexApplication $app, Request $request) { + return $app['api']->get_scheduler($app)->get_response(); + })->before($mustBeAdmin); - /** - * Get some information about phraseanet - * - * Route : /monitor/phraseanet/ - * - * Method : GET - * - * Parameters : - * - */ - $app->get('/monitor/phraseanet/', function(SilexApplication $app, Request $request) { - return $app['api']->get_phraseanet_monitor($app)->get_response(); - } - )->before($mustBeAdmin); + /** + * Get all tasks information + * + * Route : /monitor/tasks/ + * + * Method : GET + * + * Parameters : + * + */ + $app->get('/monitor/tasks/', function(SilexApplication $app, Request $request) { + return $app['api']->get_task_list($app)->get_response(); + })->before($mustBeAdmin); - /** - * Route : /databoxes/list/ - * - * Method : GET - * - * Parameters : - * - */ - $app->get('/databoxes/list/', function(SilexApplication $app, Request $request) { - return $app['api']->get_databoxes($request)->get_response(); - } - ); + /** + * Get task informations + * + * Route : /monitor/task/{task_id}/ + * + * Method : GET + * + * Parameters : + * + */ + $app->get('/monitor/task/{task_id}/', function(SilexApplication $app, Request $request, $task_id) { + return $app['api']->get_task($app, $task_id)->get_response(); + })->before($mustBeAdmin)->assert('task_id', '\d+'); - /** - * Route /databoxes/DATABOX_ID/collections/ - * - * Method : GET - * - * Parameters ; - * DATABOX_ID : required INT - */ - $app->get('/databoxes/{databox_id}/collections/', function(SilexApplication $app, $databox_id) { - return $app['api'] - ->get_databox_collections($app['request'], $databox_id) - ->get_response(); - } - )->assert('databox_id', '\d+'); + /** + * Start task + * + * Route : /monitor/task/{task_id}/ + * + * Method : POST + * + * Parameters : + * - name (string) change the name of the task + * - autostart (boolean) start task when scheduler starts + */ + $app->post('/monitor/task/{task_id}/', function(SilexApplication $app, Request $request, $task_id) { + return $app['api']->set_task_property($app, $task_id)->get_response(); + })->before($mustBeAdmin)->assert('task_id', '\d+'); - $app->get('/databoxes/{any_id}/collections/', $bad_request_exception); + /** + * Start task + * + * Route : /monitor/task/{task_id}/start/ + * + * Method : POST + * + * Parameters : + * + */ + $app->post('/monitor/task/{task_id}/start/', function(SilexApplication $app, Request $request, $task_id) { + return $app['api']->start_task($app, $task_id)->get_response(); + })->before($mustBeAdmin); - /** - * Route /databoxes/DATABOX_ID/status/ - * - * Method : GET - * - * Parameters ; - * DATABOX_ID : required INT - * - */ - $app->get('/databoxes/{databox_id}/status/', function(SilexApplication $app, $databox_id) { - return $app['api'] - ->get_databox_status($app['request'], $databox_id) - ->get_response(); - } - )->assert('databox_id', '\d+'); + /** + * Stop task + * + * Route : /monitor/task/{task_id}/stop/ + * + * Method : POST + * + * Parameters : + * + */ + $app->post('/monitor/task/{task_id}/stop/', function(SilexApplication $app, Request $request, $task_id) { + return $app['api']->stop_task($app, $task_id)->get_response(); + })->before($mustBeAdmin); - $app->get('/databoxes/{any_id}/status/', $bad_request_exception); + /** + * Get some information about phraseanet + * + * Route : /monitor/phraseanet/ + * + * Method : GET + * + * Parameters : + * + */ + $app->get('/monitor/phraseanet/', function(SilexApplication $app, Request $request) { + return $app['api']->get_phraseanet_monitor($app)->get_response(); + })->before($mustBeAdmin); - /** - * Route /databoxes/DATABOX_ID/metadatas/ - * - * Method : GET - * - * Parameters ; - * DATABOX_ID : required INT - */ - $app->get('/databoxes/{databox_id}/metadatas/', function(SilexApplication $app, $databox_id) { - return $app['api'] - ->get_databox_metadatas($app['request'], $databox_id) - ->get_response(); - } - )->assert('databox_id', '\d+'); + /** + * Route : /databoxes/list/ + * + * Method : GET + * + * Parameters : + * + */ + $app->get('/databoxes/list/', function(SilexApplication $app, Request $request) { + return $app['api']->get_databoxes($request)->get_response(); + }); - $app->get('/databoxes/{any_id}/metadatas/', $bad_request_exception); + /** + * Route /databoxes/DATABOX_ID/collections/ + * + * Method : GET + * + * Parameters ; + * DATABOX_ID : required INT + */ + $app->get('/databoxes/{databox_id}/collections/', function(SilexApplication $app, $databox_id) { + return $app['api'] + ->get_databox_collections($app['request'], $databox_id) + ->get_response(); + })->assert('databox_id', '\d+'); - /** - * Route /databoxes/DATABOX_ID/termsOfUse/ - * - * Method : GET - * - * Parameters ; - * DATABOX_ID : required INT - */ - $app->get('/databoxes/{databox_id}/termsOfUse/', function(SilexApplication $app, $databox_id) { - return $app['api'] - ->get_databox_terms($app['request'], $databox_id) - ->get_response(); - } - )->assert('databox_id', '\d+'); + $app->get('/databoxes/{any_id}/collections/', $bad_request_exception); - $app->get('/databoxes/{any_id}/termsOfUse/', $bad_request_exception); + /** + * Route /databoxes/DATABOX_ID/status/ + * + * Method : GET + * + * Parameters ; + * DATABOX_ID : required INT + * + */ + $app->get('/databoxes/{databox_id}/status/', function(SilexApplication $app, $databox_id) { + return $app['api'] + ->get_databox_status($app['request'], $databox_id) + ->get_response(); + })->assert('databox_id', '\d+'); - $app->get('/quarantine/list/', function(SilexApplication $app, Request $request) { - return $app['api']->list_quarantine($app, $request)->get_response(); - } - ); + $app->get('/databoxes/{any_id}/status/', $bad_request_exception); - $app->get('/quarantine/item/{lazaret_id}/', function($lazaret_id, SilexApplication $app, Request $request) { - return $app['api']->list_quarantine_item($lazaret_id, $app, $request)->get_response(); - } - ); + /** + * Route /databoxes/DATABOX_ID/metadatas/ + * + * Method : GET + * + * Parameters ; + * DATABOX_ID : required INT + */ + $app->get('/databoxes/{databox_id}/metadatas/', function(SilexApplication $app, $databox_id) { + return $app['api'] + ->get_databox_metadatas($app['request'], $databox_id) + ->get_response(); + })->assert('databox_id', '\d+'); - /** - * Route : /records/add/ - * - * Method : POST - * - * Parameters : - * - */ - $app->post('/records/add/', function(SilexApplication $app, Request $request) { - return $app['api']->add_record($app, $request)->get_response(); - } - ); + $app->get('/databoxes/{any_id}/metadatas/', $bad_request_exception); - /** - * Route : /records/search/ - * - * Method : GET or POST - * - * Parameters : - * bases[] : array - * status[] : array - * fields[] : array - * record_type : boolean - * media_type : string - * - * Response : - * Array of record objects - * - */ - $app->match('/records/search/', function(SilexApplication $app) { - return $app['api']->search_records($app['request'])->get_response(); - } - ); + /** + * Route /databoxes/DATABOX_ID/termsOfUse/ + * + * Method : GET + * + * Parameters ; + * DATABOX_ID : required INT + */ + $app->get('/databoxes/{databox_id}/termsOfUse/', function(SilexApplication $app, $databox_id) { + return $app['api'] + ->get_databox_terms($app['request'], $databox_id) + ->get_response(); + })->assert('databox_id', '\d+'); - $app->get('/records/{databox_id}/{record_id}/caption/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->caption_records($app['request'], $databox_id, $record_id) - ->get_response(); - } - )->assert('databox_id', '\d+')->assert('record_id', '\d+'); + $app->get('/databoxes/{any_id}/termsOfUse/', $bad_request_exception); - $app->get('/records/{any_id}/{anyother_id}/caption/', $bad_request_exception); + $app->get('/quarantine/list/', function(SilexApplication $app, Request $request) { + return $app['api']->list_quarantine($app, $request)->get_response(); + }); - /** - * Route : /records/DATABOX_ID/RECORD_ID/metadatas/ - * - * Method : GET - * - * Parameters : - * DATABOX_ID : required INT - * RECORD_ID : required INT - * - */ - $app->get('/records/{databox_id}/{record_id}/metadatas/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->get_record_metadatas($app['request'], $databox_id, $record_id) - ->get_response(); - } - )->assert('databox_id', '\d+')->assert('record_id', '\d+'); + $app->get('/quarantine/item/{lazaret_id}/', function($lazaret_id, SilexApplication $app, Request $request) { + return $app['api']->list_quarantine_item($lazaret_id, $app, $request)->get_response(); + }); - $app->get('/records/{any_id}/{anyother_id}/metadatas/', $bad_request_exception); + /** + * Route : /records/add/ + * + * Method : POST + * + * Parameters : + * + */ + $app->post('/records/add/', function(SilexApplication $app, Request $request) { + return $app['api']->add_record($app, $request)->get_response(); + }); - /** - * Route : /records/DATABOX_ID/RECORD_ID/status/ - * - * Method : GET - * - * Parameters : - * DATABOX_ID : required INT - * RECORD_ID : required INT - * - */ - $app->get('/records/{databox_id}/{record_id}/status/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->get_record_status($app['request'], $databox_id, $record_id) - ->get_response(); - } - )->assert('databox_id', '\d+')->assert('record_id', '\d+'); + /** + * Route : /records/search/ + * + * Method : GET or POST + * + * Parameters : + * bases[] : array + * status[] : array + * fields[] : array + * record_type : boolean + * media_type : string + * + * Response : + * Array of record objects + * + */ + $app->match('/records/search/', function(SilexApplication $app) { + return $app['api']->search_records($app['request'])->get_response(); + }); - $app->get('/records/{any_id}/{anyother_id}/status/', $bad_request_exception); + $app->get('/records/{databox_id}/{record_id}/caption/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->caption_records($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - /** - * Route : /records/DATABOX_ID/RECORD_ID/related/ - * - * Method : GET - * - * Parameters : - * DATABOX_ID : required INT - * RECORD_ID : required INT - * - */ - $app->get('/records/{databox_id}/{record_id}/related/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->get_record_related($app['request'], $databox_id, $record_id) - ->get_response(); - } - )->assert('databox_id', '\d+')->assert('record_id', '\d+'); + $app->get('/records/{any_id}/{anyother_id}/caption/', $bad_request_exception); - $app->get('/records/{any_id}/{anyother_id}/related/', $bad_request_exception); + /** + * Route : /records/DATABOX_ID/RECORD_ID/metadatas/ + * + * Method : GET + * + * Parameters : + * DATABOX_ID : required INT + * RECORD_ID : required INT + * + */ + $app->get('/records/{databox_id}/{record_id}/metadatas/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->get_record_metadatas($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - /** - * Route : /records/DATABOX_ID/RECORD_ID/embed/ - * - * Method : GET - * - * Parameters : - * DATABOX_ID : required INT - * RECORD_ID : required INT - * - */ - $app->get('/records/{databox_id}/{record_id}/embed/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->get_record_embed($app['request'], $databox_id, $record_id) - ->get_response(); - } - )->assert('databox_id', '\d+')->assert('record_id', '\d+'); + $app->get('/records/{any_id}/{anyother_id}/metadatas/', $bad_request_exception); - $app->get('/records/{any_id}/{anyother_id}/embed/', $bad_request_exception); + /** + * Route : /records/DATABOX_ID/RECORD_ID/status/ + * + * Method : GET + * + * Parameters : + * DATABOX_ID : required INT + * RECORD_ID : required INT + * + */ + $app->get('/records/{databox_id}/{record_id}/status/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->get_record_status($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - /** - * Route : /records/DATABOX_ID/RECORD_ID/setmetadatas/ - * - * Method : POST - * - * Parameters : - * DATABOX_ID : required INT - * RECORD_ID : required INT - * - */ - $app->post('/records/{databox_id}/{record_id}/setmetadatas/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->set_record_metadatas($app['request'], $databox_id, $record_id) - ->get_response(); - } - )->assert('databox_id', '\d+')->assert('record_id', '\d+'); + $app->get('/records/{any_id}/{anyother_id}/status/', $bad_request_exception); - $app->post('/records/{any_id}/{anyother_id}/setmetadatas/', $bad_request_exception); + /** + * Route : /records/DATABOX_ID/RECORD_ID/related/ + * + * Method : GET + * + * Parameters : + * DATABOX_ID : required INT + * RECORD_ID : required INT + * + */ + $app->get('/records/{databox_id}/{record_id}/related/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->get_record_related($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - /** - * Route : /records/DATABOX_ID/RECORD_ID/setstatus/ - * - * Method : POST - * - * Parameters : - * DATABOX_ID : required INT - * RECORD_ID : required INT - * - */ - $app->post('/records/{databox_id}/{record_id}/setstatus/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->set_record_status($app['request'], $databox_id, $record_id) - ->get_response(); - } - )->assert('databox_id', '\d+')->assert('record_id', '\d+'); + $app->get('/records/{any_id}/{anyother_id}/related/', $bad_request_exception); - $app->post('/records/{any_id}/{anyother_id}/setstatus/', $bad_request_exception); + /** + * Route : /records/DATABOX_ID/RECORD_ID/embed/ + * + * Method : GET + * + * Parameters : + * DATABOX_ID : required INT + * RECORD_ID : required INT + * + */ + $app->get('/records/{databox_id}/{record_id}/embed/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->get_record_embed($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - /** - * Route : /records/DATABOX_ID/RECORD_ID/setcollection/ - * - * Method : POST - * - * Parameters : - * DATABOX_ID : required INT - * RECORD_ID : required INT - * - */ - $app->post('/records/{databox_id}/{record_id}/setcollection/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->set_record_collection($app['request'], $databox_id, $record_id) - ->get_response(); - } - )->assert('databox_id', '\d+')->assert('record_id', '\d+'); + $app->get('/records/{any_id}/{anyother_id}/embed/', $bad_request_exception); - $app->post('/records/{wrong_databox_id}/{wrong_record_id}/setcollection/', $bad_request_exception); + /** + * Route : /records/DATABOX_ID/RECORD_ID/setmetadatas/ + * + * Method : POST + * + * Parameters : + * DATABOX_ID : required INT + * RECORD_ID : required INT + * + */ + $app->post('/records/{databox_id}/{record_id}/setmetadatas/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->set_record_metadatas($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - $app->get('/records/{databox_id}/{record_id}/', function(SilexApplication $app, $databox_id, $record_id) { - return $app['api'] - ->get_record($app['request'], $databox_id, $record_id) - ->get_response(); - })->assert('databox_id', '\d+')->assert('record_id', '\d+'); + $app->post('/records/{any_id}/{anyother_id}/setmetadatas/', $bad_request_exception); - $app->get('/records/{any_id}/{anyother_id}/', $bad_request_exception); + /** + * Route : /records/DATABOX_ID/RECORD_ID/setstatus/ + * + * Method : POST + * + * Parameters : + * DATABOX_ID : required INT + * RECORD_ID : required INT + * + */ + $app->post('/records/{databox_id}/{record_id}/setstatus/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->set_record_status($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - /** - * Route : /baskets/list/ - * - * Method : POST - * - * Parameters : - * - */ - $app->get('/baskets/list/', function(SilexApplication $app) { - return $app['api']->search_baskets($app['request'])->get_response(); - } - ); + $app->post('/records/{any_id}/{anyother_id}/setstatus/', $bad_request_exception); - /** - * Route : /baskets/add/ - * - * Method : POST - * - * Parameters : - * - */ - $app->post('/baskets/add/', function(SilexApplication $app) { - return $app['api']->create_basket($app['request'])->get_response(); - } - ); + /** + * Route : /records/DATABOX_ID/RECORD_ID/setcollection/ + * + * Method : POST + * + * Parameters : + * DATABOX_ID : required INT + * RECORD_ID : required INT + * + */ + $app->post('/records/{databox_id}/{record_id}/setcollection/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->set_record_collection($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - /** - * Route : /baskets/BASKET_ID/content/ - * - * Method : GET - * - * Parameters : - * BASKET_ID : required INT - * - */ - $app->get('/baskets/{basket_id}/content/', function(SilexApplication $app, $basket_id) { - return $app['api']->get_basket($app['request'], $basket_id)->get_response(); - } - )->assert('basket_id', '\d+'); + $app->post('/records/{wrong_databox_id}/{wrong_record_id}/setcollection/', $bad_request_exception); - $app->get('/baskets/{wrong_basket_id}/content/', $bad_request_exception); + $app->get('/records/{databox_id}/{record_id}/', function(SilexApplication $app, $databox_id, $record_id) { + return $app['api'] + ->get_record($app['request'], $databox_id, $record_id) + ->get_response(); + })->assert('databox_id', '\d+')->assert('record_id', '\d+'); - /** - * Route : /baskets/BASKET_ID/settitle/ - * - * Method : GET - * - * Parameters : - * BASKET_ID : required INT - * - */ - $app->post('/baskets/{basket_id}/setname/', function(SilexApplication $app, $basket_id) { - return $app['api'] - ->set_basket_title($app['request'], $basket_id) - ->get_response(); - } - )->assert('basket_id', '\d+'); + $app->get('/records/{any_id}/{anyother_id}/', $bad_request_exception); - $app->post('/baskets/{wrong_basket_id}/setname/', $bad_request_exception); + /** + * Route : /baskets/list/ + * + * Method : POST + * + * Parameters : + * + */ + $app->get('/baskets/list/', function(SilexApplication $app) { + return $app['api']->search_baskets($app['request'])->get_response(); + }); - /** - * Route : /baskets/BASKET_ID/setdescription/ - * - * Method : POST - * - * Parameters : - * BASKET_ID : required INT - * - */ - $app->post('/baskets/{basket_id}/setdescription/', function(SilexApplication $app, $basket_id) { - return $app['api'] - ->set_basket_description($app['request'], $basket_id) - ->get_response(); - } - )->assert('basket_id', '\d+'); + /** + * Route : /baskets/add/ + * + * Method : POST + * + * Parameters : + * + */ + $app->post('/baskets/add/', function(SilexApplication $app) { + return $app['api']->create_basket($app['request'])->get_response(); + }); - $app->post('/baskets/{wrong_basket_id}/setdescription/', $bad_request_exception); + /** + * Route : /baskets/BASKET_ID/content/ + * + * Method : GET + * + * Parameters : + * BASKET_ID : required INT + * + */ + $app->get('/baskets/{basket_id}/content/', function(SilexApplication $app, $basket_id) { + return $app['api']->get_basket($app['request'], $basket_id)->get_response(); + })->assert('basket_id', '\d+'); - /** - * Route : /baskets/BASKET_ID/delete/ - * - * Method : POST - * - * Parameters : - * BASKET_ID : required INT - * - */ - $app->post('/baskets/{basket_id}/delete/', function(SilexApplication $app, $basket_id) { - return $app['api']->delete_basket($app['request'], $basket_id)->get_response(); - } - )->assert('basket_id', '\d+'); + $app->get('/baskets/{wrong_basket_id}/content/', $bad_request_exception); - $app->post('/baskets/{wrong_basket_id}/delete/', $bad_request_exception); + /** + * Route : /baskets/BASKET_ID/settitle/ + * + * Method : GET + * + * Parameters : + * BASKET_ID : required INT + * + */ + $app->post('/baskets/{basket_id}/setname/', function(SilexApplication $app, $basket_id) { + return $app['api'] + ->set_basket_title($app['request'], $basket_id) + ->get_response(); + })->assert('basket_id', '\d+'); - /** - * Route : /feeds/list/ - * - * Method : POST - * - * Parameters : - * - */ - $app->get('/feeds/list/', function(SilexApplication $app) { - return $app['api'] - ->search_publications($app['request'], $app['phraseanet.user']) - ->get_response(); - } - ); + $app->post('/baskets/{wrong_basket_id}/setname/', $bad_request_exception); - $app->get('/feeds/content/', function(SilexApplication $app) { - return $app['api'] - ->get_publications($app['request'], $app['phraseanet.user']) - ->get_response(); - } - ); + /** + * Route : /baskets/BASKET_ID/setdescription/ + * + * Method : POST + * + * Parameters : + * BASKET_ID : required INT + * + */ + $app->post('/baskets/{basket_id}/setdescription/', function(SilexApplication $app, $basket_id) { + return $app['api'] + ->set_basket_description($app['request'], $basket_id) + ->get_response(); + })->assert('basket_id', '\d+'); - $app->get('/feeds/entry/{entry_id}/', function(SilexApplication $app, $entry_id) { - return $app['api'] - ->get_feed_entry($app['request'], $entry_id, $app['phraseanet.user']) - ->get_response(); - } - )->assert('entry_id', '\d+'); + $app->post('/baskets/{wrong_basket_id}/setdescription/', $bad_request_exception); - $app->get('/feeds/entry/{entry_id}/', $bad_request_exception); + /** + * Route : /baskets/BASKET_ID/delete/ + * + * Method : POST + * + * Parameters : + * BASKET_ID : required INT + * + */ + $app->post('/baskets/{basket_id}/delete/', function(SilexApplication $app, $basket_id) { + return $app['api']->delete_basket($app['request'], $basket_id)->get_response(); + })->assert('basket_id', '\d+'); - /** - * Route : /feeds/PUBLICATION_ID/content/ - * - * Method : GET - * - * Parameters : - * PUBLICATION_ID : required INT - * - */ - $app->get('/feeds/{feed_id}/content/', function(SilexApplication $app, $feed_id) { - return $app['api'] - ->get_publication($app['request'], $feed_id, $app['phraseanet.user']) - ->get_response(); - } - )->assert('feed_id', '\d+'); + $app->post('/baskets/{wrong_basket_id}/delete/', $bad_request_exception); - $app->get('/feeds/{wrong_feed_id}/content/', $bad_request_exception); + /** + * Route : /feeds/list/ + * + * Method : POST + * + * Parameters : + * + */ + $app->get('/feeds/list/', function(SilexApplication $app) { + return $app['api'] + ->search_publications($app['request'], $app['phraseanet.user']) + ->get_response(); + }); - /** - * Route Errors - */ - $app->error(function (\Exception $e) use ($app) { + $app->get('/feeds/content/', function(SilexApplication $app) { + return $app['api'] + ->get_publications($app['request'], $app['phraseanet.user']) + ->get_response(); + }); - $headers = array(); + $app->get('/feeds/entry/{entry_id}/', function(SilexApplication $app, $entry_id) { + return $app['api'] + ->get_feed_entry($app['request'], $entry_id, $app['phraseanet.user']) + ->get_response(); + })->assert('entry_id', '\d+'); - if ($e instanceof \API_V1_exception_methodnotallowed) { - $code = \API_V1_result::ERROR_METHODNOTALLOWED; - } elseif ($e instanceof MethodNotAllowedHttpException) { - $code = \API_V1_result::ERROR_METHODNOTALLOWED; - } elseif ($e instanceof \API_V1_exception_badrequest) { - $code = \API_V1_result::ERROR_BAD_REQUEST; - } elseif ($e instanceof \API_V1_exception_forbidden) { - $code = \API_V1_result::ERROR_FORBIDDEN; - } elseif ($e instanceof \API_V1_exception_unauthorized) { - $code = \API_V1_result::ERROR_UNAUTHORIZED; - } elseif ($e instanceof \API_V1_exception_internalservererror) { - $code = \API_V1_result::ERROR_INTERNALSERVERERROR; - } elseif ($e instanceof \Exception_NotFound) { - $code = \API_V1_result::ERROR_NOTFOUND; - } elseif ($e instanceof NotFoundHttpException) { - $code = \API_V1_result::ERROR_NOTFOUND; - } else { - $code = \API_V1_result::ERROR_INTERNALSERVERERROR; - } + $app->get('/feeds/entry/{entry_id}/', $bad_request_exception); - if ($e instanceof HttpException) { - $headers = $e->getHeaders(); - } + /** + * Route : /feeds/PUBLICATION_ID/content/ + * + * Method : GET + * + * Parameters : + * PUBLICATION_ID : required INT + * + */ + $app->get('/feeds/{feed_id}/content/', function(SilexApplication $app, $feed_id) { + return $app['api'] + ->get_publication($app['request'], $feed_id, $app['phraseanet.user']) + ->get_response(); + })->assert('feed_id', '\d+'); - $result = $app['api']->get_error_message($app['request'], $code, $e->getMessage()); - $response = $result->get_response(); + $app->get('/feeds/{wrong_feed_id}/content/', $bad_request_exception); - foreach ($headers as $key => $value) { - $response->headers->set($key, $value); - } + /** + * Route Errors + */ + $app->error(function (\Exception $e) use ($app) { - return $response; - }); + $headers = array(); + if ($e instanceof \API_V1_exception_methodnotallowed) { + $code = \API_V1_result::ERROR_METHODNOTALLOWED; + } elseif ($e instanceof MethodNotAllowedHttpException) { + $code = \API_V1_result::ERROR_METHODNOTALLOWED; + } elseif ($e instanceof \API_V1_exception_badrequest) { + $code = \API_V1_result::ERROR_BAD_REQUEST; + } elseif ($e instanceof \API_V1_exception_forbidden) { + $code = \API_V1_result::ERROR_FORBIDDEN; + } elseif ($e instanceof \API_V1_exception_unauthorized) { + $code = \API_V1_result::ERROR_UNAUTHORIZED; + } elseif ($e instanceof \API_V1_exception_internalservererror) { + $code = \API_V1_result::ERROR_INTERNALSERVERERROR; + } elseif ($e instanceof \Exception_NotFound) { + $code = \API_V1_result::ERROR_NOTFOUND; + } elseif ($e instanceof NotFoundHttpException) { + $code = \API_V1_result::ERROR_NOTFOUND; + } else { + $code = \API_V1_result::ERROR_INTERNALSERVERERROR; + } - return $app; - }, $environment ? : null -); + if ($e instanceof HttpException) { + $headers = $e->getHeaders(); + } + + $result = $app['api']->get_error_message($app['request'], $code, $e->getMessage()); + $response = $result->get_response(); + + foreach ($headers as $key => $value) { + $response->headers->set($key, $value); + } + + return $response; + }); + + return $app; +}, isset($environment) ? $environment : null); diff --git a/lib/Alchemy/Phrasea/Application/ApiVersion.php b/lib/Alchemy/Phrasea/Application/ApiVersion.php index 79513fb4bd..71f99fee1d 100644 --- a/lib/Alchemy/Phrasea/Application/ApiVersion.php +++ b/lib/Alchemy/Phrasea/Application/ApiVersion.php @@ -15,45 +15,35 @@ use Silex\Application as SilexApplication; use Alchemy\Phrasea\Application as PhraseaApplication; use Symfony\Component\HttpFoundation\Request; -/** - * - * @package APIv1 - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -return call_user_func(function() { - $app = new PhraseaApplication(); +return call_user_func(function($environment = 'prod') { - $app->get('/', function(Request $request, SilexApplication $app) { - $registry = $app['phraseanet.registry']; + $app = new PhraseaApplication($environment); - $apiAdapter = new \API_V1_adapter($app); + $app->get('/', function(Request $request, SilexApplication $app) { + $apiAdapter = new \API_V1_adapter($app); - $result = new \API_V1_result($request, $apiAdapter); + $result = new \API_V1_result($request, $apiAdapter); - return $result->set_datas( - array( - 'name' => $registry->get('GV_homeTitle'), - 'type' => 'phraseanet', - 'description' => $registry->get('GV_metaDescription'), - 'documentation' => 'https://docs.phraseanet.com/Devel', - 'versions' => array( - '1' => array( - 'number' => $apiAdapter->get_version(), - 'uri' => '/api/v1/', - 'authenticationProtocol' => 'OAuth2', - 'authenticationVersion' => 'draft#v9', - 'authenticationEndPoints' => array( - 'authorization_token' => '/api/oauthv2/authorize', - 'access_token' => '/api/oauthv2/token' - ) - ) - ) - ) - )->get_response(); - }); + return $result->set_datas(array( + 'name' => $app['phraseanet.registry']->get('GV_homeTitle'), + 'type' => 'phraseanet', + 'description' => $app['phraseanet.registry']->get('GV_metaDescription'), + 'documentation' => 'https://docs.phraseanet.com/Devel', + 'versions' => array( + '1' => array( + 'number' => $apiAdapter->get_version(), + 'uri' => '/api/v1/', + 'authenticationProtocol' => 'OAuth2', + 'authenticationVersion' => 'draft#v9', + 'authenticationEndPoints' => array( + 'authorization_token' => '/api/oauthv2/authorize', + 'access_token' => '/api/oauthv2/token' + ) + ) + ) + ))->get_response(); + }); - return $app; - } -); + return $app; +}, isset($environment) ? $environment : null); diff --git a/lib/Alchemy/Phrasea/Application/Lightbox.php b/lib/Alchemy/Phrasea/Application/Lightbox.php index b1d69165d4..6aaa885ae0 100644 --- a/lib/Alchemy/Phrasea/Application/Lightbox.php +++ b/lib/Alchemy/Phrasea/Application/Lightbox.php @@ -18,451 +18,436 @@ use Symfony\Component\HttpFoundation\Response; class Lightbox implements ControllerProviderInterface { - public function connect(SilexApplication $app) { $controllers = $app['controllers_factory']; - $controllers->get('/', function (SilexApplication $app) { - \User_Adapter::updateClientInfos($app, 6); + \User_Adapter::updateClientInfos($app, 6); - $repository = $app['EM']->getRepository('\Entities\Basket'); + $repository = $app['EM']->getRepository('\Entities\Basket'); - $current_user = $app['phraseanet.user']; + /* @var $repository \Repositories\BasketRepository */ - /* @var $repository \Repositories\BasketRepository */ + $basket_collection = array_merge( + $repository->findActiveByUser($app['phraseanet.user']) + , $repository->findActiveValidationByUser($app['phraseanet.user']) + ); - $basket_collection = array_merge( - $repository->findActiveByUser($app['phraseanet.user']) - , $repository->findActiveValidationByUser($current_user) - ); - - $template = 'lightbox/index.html.twig'; - if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { - $template = 'lightbox/IE6/index.html.twig'; - } - - return new Response($app['twig']->render($template, array( - 'baskets_collection' => $basket_collection, - 'module_name' => 'Lightbox', - 'module' => 'lightbox' - ) - )); + $template = 'lightbox/index.html.twig'; + if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { + $template = 'lightbox/IE6/index.html.twig'; } - ); + + return new Response($app['twig']->render($template, array( + 'baskets_collection' => $basket_collection, + 'module_name' => 'Lightbox', + 'module' => 'lightbox' + ) + )); + }); $controllers->get('/ajax/NOTE_FORM/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) { - if (!$app['browser']->isMobile()) { - return new Response(''); - } - - $basketElement = $app['EM'] - ->getRepository('\Entities\BasketElement') - ->findUserElement($sselcont_id, $app['phraseanet.user']); - - $parameters = array( - 'basket_element' => $basketElement, - 'module_name' => '', - ); - - return $app['twig']->render('lightbox/note_form.html.twig', $parameters); + if (!$app['browser']->isMobile()) { + return new Response(''); } - )->assert('sselcont_id', '\d+'); + + $basketElement = $app['EM'] + ->getRepository('\Entities\BasketElement') + ->findUserElement($sselcont_id, $app['phraseanet.user']); + + $parameters = array( + 'basket_element' => $basketElement, + 'module_name' => '', + ); + + return $app['twig']->render('lightbox/note_form.html.twig', $parameters); + })->assert('sselcont_id', '\d+'); $controllers->get('/ajax/LOAD_BASKET_ELEMENT/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) { - /* @var $repository \Repositories\BasketElementRepository */ - $repository = $app['EM']->getRepository('\Entities\BasketElement'); + /* @var $repository \Repositories\BasketElementRepository */ + $repository = $app['EM']->getRepository('\Entities\BasketElement'); - $BasketElement = $repository->findUserElement($sselcont_id, $app['phraseanet.user']); + $BasketElement = $repository->findUserElement($sselcont_id, $app['phraseanet.user']); - if ($app['browser']->isMobile()) { - $output = $app['twig']->render('lightbox/basket_element.html.twig', array( - 'basket_element' => $BasketElement, - 'module_name' => $BasketElement->getRecord($app)->get_title() - ) - ); - - return new Response($output); - } else { - $template_options = 'lightbox/sc_options_box.html.twig'; - $template_agreement = 'lightbox/agreement_box.html.twig'; - $template_selector = 'lightbox/selector_box.html.twig'; - $template_note = 'lightbox/sc_note.html.twig'; - $template_preview = 'common/preview.html.twig'; - $template_caption = 'common/caption.html.twig'; - - if (!$app['browser']->isNewGeneration()) { - $template_options = 'lightbox/IE6/sc_options_box.html.twig'; - $template_agreement = 'lightbox/IE6/agreement_box.html.twig'; - } - - $Basket = $BasketElement->getBasket(); - - $ret = array(); - $ret['number'] = $BasketElement->getRecord($app)->get_number(); - $ret['title'] = $BasketElement->getRecord($app)->get_title(); - - $ret['preview'] = $app['twig']->render($template_preview, array('record' => $BasketElement->getRecord($app), 'not_wrapped' => true)); - $ret['options_html'] = $app['twig']->render($template_options, array('basket_element' => $BasketElement)); - $ret['agreement_html'] = $app['twig']->render($template_agreement, array('basket' => $Basket, 'basket_element' => $BasketElement)); - $ret['selector_html'] = $app['twig']->render($template_selector, array('basket_element' => $BasketElement)); - $ret['note_html'] = $app['twig']->render($template_note, array('basket_element' => $BasketElement)); - $ret['caption'] = $app['twig']->render($template_caption, array('view' => 'preview', 'record' => $BasketElement->getRecord($app))); - - return $app->json($ret); - } - } - )->assert('sselcont_id', '\d+'); - - $controllers->get('/ajax/LOAD_FEED_ITEM/{entry_id}/{item_id}/', function(SilexApplication $app, $entry_id, $item_id) { - - $entry = \Feed_Entry_Adapter::load_from_id($app, $entry_id); - $item = new \Feed_Entry_Item($app['phraseanet.appbox'], $entry, $item_id); - - if ($app['browser']->isMobile()) { - $output = $app['twig']->render('lightbox/feed_element.html.twig', array( - 'feed_element' => $item, - 'module_name' => $item->get_record()->get_title() - ) - ); - - return new Response($output); - } else { - $template_options = 'lightbox/feed_options_box.html.twig'; - $template_preview = 'common/preview.html.twig'; - $template_caption = 'common/caption.html.twig'; - - if (!$app['browser']->isNewGeneration()) { - $template_options = 'lightbox/IE6/feed_options_box.html.twig'; - } - - $ret = array(); - $ret['number'] = $item->get_record()->get_number(); - $ret['title'] = $item->get_record()->get_title(); - - $ret['preview'] = $app['twig']->render($template_preview, array('record' => $item->get_record(), 'not_wrapped' => true)); - $ret['options_html'] = $app['twig']->render($template_options, array('feed_element' => $item)); - $ret['caption'] = $app['twig']->render($template_caption, array('view' => 'preview', 'record' => $item->get_record())); - - $ret['agreement_html'] = $ret['selector_html'] = $ret['note_html'] = ''; - - return $app->json($ret); - } - } - )->assert('entry_id', '\d+')->assert('item_id', '\d+'); - - $controllers->get('/validate/{ssel_id}/', function (SilexApplication $app, $ssel_id) { - - \User_Adapter::updateClientInfos($app, 6); - - $repository = $app['EM']->getRepository('\Entities\Basket'); - - /* @var $repository \Repositories\BasketRepository */ - $basket_collection = $repository->findActiveValidationAndBasketByUser( - $app['phraseanet.user'] - ); - - $basket = $repository->findUserBasket( - $app, $ssel_id - , $app['phraseanet.user'] - , false - ); - - if ($basket->getIsRead() === false) { - $basket = $app['EM']->merge($basket); - $basket->setIsRead(true); - $app['EM']->flush(); - } - - if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->getIsAware() === false) { - $basket = $app['EM']->merge($basket); - $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true); - $app['EM']->flush(); - } - - $template = 'lightbox/validate.html.twig'; - - if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { - $template = 'lightbox/IE6/validate.html.twig'; - } - - $response = new Response($app['twig']->render($template, array( - 'baskets_collection' => $basket_collection, - 'basket' => $basket, - 'local_title' => strip_tags($basket->getName()), - 'module' => 'lightbox', - 'module_name' => _('admin::monitor: module validation') - ) - )); - $response->setCharset('UTF-8'); - - return $response; - } - )->assert('ssel_id', '\d+'); - - $controllers->get('/compare/{ssel_id}/', function (SilexApplication $app, $ssel_id) { - - \User_Adapter::updateClientInfos($app, 6); - - $repository = $app['EM']->getRepository('\Entities\Basket'); - - /* @var $repository \Repositories\BasketRepository */ - $basket_collection = $repository->findActiveValidationAndBasketByUser( - $app['phraseanet.user'] - ); - - $basket = $repository->findUserBasket( - $app, $ssel_id - , $app['phraseanet.user'] - , false - ); - - if ($basket->getIsRead() === false) { - $basket = $app['EM']->merge($basket); - $basket->setIsRead(true); - $app['EM']->flush(); - } - - if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['phraseanet.user'])->getIsAware() === false) { - $basket = $app['EM']->merge($basket); - $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true); - $app['EM']->flush(); - } - - $template = 'lightbox/validate.html.twig'; - - if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { - $template = 'lightbox/IE6/validate.html.twig'; - } - - $response = new Response($app['twig']->render($template, array( - 'baskets_collection' => $basket_collection, - 'basket' => $basket, - 'local_title' => strip_tags($basket->getName()), - 'module' => 'lightbox', - 'module_name' => _('admin::monitor: module validation') - ) - )); - $response->setCharset('UTF-8'); - - return $response; - } - )->assert('ssel_id', '\d+'); - - $controllers->get('/feeds/entry/{entry_id}/', function (SilexApplication $app, $entry_id) { - - \User_Adapter::updateClientInfos($app, 6); - - $feed_entry = \Feed_Entry_Adapter::load_from_id($app, $entry_id); - - $template = 'lightbox/feed.html.twig'; - - if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { - $template = 'lightbox/IE6/feed.html.twig'; - } - - $content = $feed_entry->get_content(); - - $output = $app['twig']->render($template, array( - 'feed_entry' => $feed_entry, - 'first_item' => array_shift($content), - 'local_title' => $feed_entry->get_title(), - 'module' => 'lightbox', - 'module_name' => _('admin::monitor: module validation') + if ($app['browser']->isMobile()) { + $output = $app['twig']->render('lightbox/basket_element.html.twig', array( + 'basket_element' => $BasketElement, + 'module_name' => $BasketElement->getRecord($app)->get_title() ) ); - $response = new Response($output, 200); - $response->setCharset('UTF-8'); - return $response; - } - )->assert('entry_id', '\d+'); + return new Response($output); + } else { + $template_options = 'lightbox/sc_options_box.html.twig'; + $template_agreement = 'lightbox/agreement_box.html.twig'; + $template_selector = 'lightbox/selector_box.html.twig'; + $template_note = 'lightbox/sc_note.html.twig'; + $template_preview = 'common/preview.html.twig'; + $template_caption = 'common/caption.html.twig'; - $controllers->get('/ajax/LOAD_REPORT/{ssel_id}/', function(SilexApplication $app, $ssel_id) { - - $template = 'lightbox/basket_content_report.html.twig'; - - $repository = $app['EM']->getRepository('\Entities\Basket'); - - /* @var $repository \Repositories\BasketRepository */ - $basket = $repository->findUserBasket( - $app, $ssel_id - , $app['phraseanet.user'] - , false - ); - - $response = new Response($app['twig']->render($template, array('basket' => $basket))); - $response->setCharset('UTF-8'); - - return $response; - } - )->assert('ssel_id', '\d+'); - - $controllers->post('/ajax/SET_NOTE/{sselcont_id}/', function (SilexApplication $app, $sselcont_id) { - $output = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees')); - - $request = $app['request']; - $note = $request->request->get('note'); - - if (is_null($note)) { - Return new Response('You must provide a note value', 400); + if (!$app['browser']->isNewGeneration()) { + $template_options = 'lightbox/IE6/sc_options_box.html.twig'; + $template_agreement = 'lightbox/IE6/agreement_box.html.twig'; } - /* @var $repository \Repositories\BasketElementRepository */ - $repository = $app['EM']->getRepository('\Entities\BasketElement'); + $Basket = $BasketElement->getBasket(); - $basket_element = $repository->findUserElement($sselcont_id, $app['phraseanet.user']); + $ret = array(); + $ret['number'] = $BasketElement->getRecord($app)->get_number(); + $ret['title'] = $BasketElement->getRecord($app)->get_title(); - $validationDatas = $basket_element->getUserValidationDatas($app['phraseanet.user'], $app); - - $validationDatas->setNote($note); - - $app['EM']->merge($validationDatas); - - $app['EM']->flush(); - - if ($app['browser']->isMobile()) { - $datas = $app['twig']->render('lightbox/sc_note.html.twig', array('basket_element' => $basket_element)); - - $output = array('error' => false, 'datas' => $datas); - } else { - $template = 'lightbox/sc_note.html.twig'; - - $datas = $app['twig']->render($template, array('basket_element' => $basket_element)); - - $output = array('error' => false, 'datas' => $datas); - } - - return $app->json($output); - } - )->assert('sselcont_id', '\d+'); - - $controllers->post('/ajax/SET_ELEMENT_AGREEMENT/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) { - $request = $app['request']; - $agreement = $request->request->get('agreement'); - - if (is_null($agreement)) { - Return new Response('You must provide an agreement value', 400); - } - - $agreement = $agreement > 0; - - $releasable = false; - try { - $ret = array( - 'error' => true, - 'releasable' => false, - 'datas' => _('Erreur lors de la mise a jour des donnes ') - ); - - $user = $app['phraseanet.user']; - $repository = $app['EM']->getRepository('\Entities\BasketElement'); - - /* @var $repository \Repositories\BasketElementRepository */ - $basket_element = $repository->findUserElement( - $sselcont_id - , $user - ); - /* @var $basket_element \Entities\BasketElement */ - $validationDatas = $basket_element->getUserValidationDatas($user, $app); - - if (!$basket_element->getBasket() - ->getValidation() - ->getParticipant($user, $app)->getCanAgree()) { - throw new ControllerException('You can not agree on this'); - } - - $validationDatas->setAgreement($agreement); - - $participant = $basket_element->getBasket() - ->getValidation() - ->getParticipant($user, $app); - - $app['EM']->merge($basket_element); - - $app['EM']->flush(); - - $releasable = false; - if ($participant->isReleasable() === true) { - $releasable = _('Do you want to send your report ?'); - } - - $ret = array( - 'error' => false - , 'datas' => '' - , 'releasable' => $releasable - ); - } catch (ControllerException $e) { - $ret['datas'] = $e->getMessage(); - } + $ret['preview'] = $app['twig']->render($template_preview, array('record' => $BasketElement->getRecord($app), 'not_wrapped' => true)); + $ret['options_html'] = $app['twig']->render($template_options, array('basket_element' => $BasketElement)); + $ret['agreement_html'] = $app['twig']->render($template_agreement, array('basket' => $Basket, 'basket_element' => $BasketElement)); + $ret['selector_html'] = $app['twig']->render($template_selector, array('basket_element' => $BasketElement)); + $ret['note_html'] = $app['twig']->render($template_note, array('basket_element' => $BasketElement)); + $ret['caption'] = $app['twig']->render($template_caption, array('view' => 'preview', 'record' => $BasketElement->getRecord($app))); return $app->json($ret); } - )->assert('sselcont_id', '\d+'); + })->assert('sselcont_id', '\d+'); + + $controllers->get('/ajax/LOAD_FEED_ITEM/{entry_id}/{item_id}/', function(SilexApplication $app, $entry_id, $item_id) { + + $entry = \Feed_Entry_Adapter::load_from_id($app, $entry_id); + $item = new \Feed_Entry_Item($app['phraseanet.appbox'], $entry, $item_id); + + if ($app['browser']->isMobile()) { + $output = $app['twig']->render('lightbox/feed_element.html.twig', array( + 'feed_element' => $item, + 'module_name' => $item->get_record()->get_title() + ) + ); + + return new Response($output); + } else { + $template_options = 'lightbox/feed_options_box.html.twig'; + $template_preview = 'common/preview.html.twig'; + $template_caption = 'common/caption.html.twig'; + + if (!$app['browser']->isNewGeneration()) { + $template_options = 'lightbox/IE6/feed_options_box.html.twig'; + } + + $ret = array(); + $ret['number'] = $item->get_record()->get_number(); + $ret['title'] = $item->get_record()->get_title(); + + $ret['preview'] = $app['twig']->render($template_preview, array('record' => $item->get_record(), 'not_wrapped' => true)); + $ret['options_html'] = $app['twig']->render($template_options, array('feed_element' => $item)); + $ret['caption'] = $app['twig']->render($template_caption, array('view' => 'preview', 'record' => $item->get_record())); + + $ret['agreement_html'] = $ret['selector_html'] = $ret['note_html'] = ''; + + return $app->json($ret); + } + })->assert('entry_id', '\d+')->assert('item_id', '\d+'); + + $controllers->get('/validate/{ssel_id}/', function (SilexApplication $app, $ssel_id) { + + \User_Adapter::updateClientInfos($app, 6); + + $repository = $app['EM']->getRepository('\Entities\Basket'); + + /* @var $repository \Repositories\BasketRepository */ + $basket_collection = $repository->findActiveValidationAndBasketByUser( + $app['phraseanet.user'] + ); + + $basket = $repository->findUserBasket( + $app, $ssel_id + , $app['phraseanet.user'] + , false + ); + + if ($basket->getIsRead() === false) { + $basket = $app['EM']->merge($basket); + $basket->setIsRead(true); + $app['EM']->flush(); + } + + if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->getIsAware() === false) { + $basket = $app['EM']->merge($basket); + $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true); + $app['EM']->flush(); + } + + $template = 'lightbox/validate.html.twig'; + + if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { + $template = 'lightbox/IE6/validate.html.twig'; + } + + $response = new Response($app['twig']->render($template, array( + 'baskets_collection' => $basket_collection, + 'basket' => $basket, + 'local_title' => strip_tags($basket->getName()), + 'module' => 'lightbox', + 'module_name' => _('admin::monitor: module validation') + ) + )); + $response->setCharset('UTF-8'); + + return $response; + })->assert('ssel_id', '\d+'); + + $controllers->get('/compare/{ssel_id}/', function (SilexApplication $app, $ssel_id) { + + \User_Adapter::updateClientInfos($app, 6); + + $repository = $app['EM']->getRepository('\Entities\Basket'); + + /* @var $repository \Repositories\BasketRepository */ + $basket_collection = $repository->findActiveValidationAndBasketByUser( + $app['phraseanet.user'] + ); + + $basket = $repository->findUserBasket( + $app, $ssel_id + , $app['phraseanet.user'] + , false + ); + + if ($basket->getIsRead() === false) { + $basket = $app['EM']->merge($basket); + $basket->setIsRead(true); + $app['EM']->flush(); + } + + if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['phraseanet.user'])->getIsAware() === false) { + $basket = $app['EM']->merge($basket); + $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true); + $app['EM']->flush(); + } + + $template = 'lightbox/validate.html.twig'; + + if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { + $template = 'lightbox/IE6/validate.html.twig'; + } + + $response = new Response($app['twig']->render($template, array( + 'baskets_collection' => $basket_collection, + 'basket' => $basket, + 'local_title' => strip_tags($basket->getName()), + 'module' => 'lightbox', + 'module_name' => _('admin::monitor: module validation') + ) + )); + $response->setCharset('UTF-8'); + + return $response; + })->assert('ssel_id', '\d+'); + + $controllers->get('/feeds/entry/{entry_id}/', function (SilexApplication $app, $entry_id) { + + \User_Adapter::updateClientInfos($app, 6); + + $feed_entry = \Feed_Entry_Adapter::load_from_id($app, $entry_id); + + $template = 'lightbox/feed.html.twig'; + + if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { + $template = 'lightbox/IE6/feed.html.twig'; + } + + $content = $feed_entry->get_content(); + + $output = $app['twig']->render($template, array( + 'feed_entry' => $feed_entry, + 'first_item' => array_shift($content), + 'local_title' => $feed_entry->get_title(), + 'module' => 'lightbox', + 'module_name' => _('admin::monitor: module validation') + ) + ); + $response = new Response($output, 200); + $response->setCharset('UTF-8'); + + return $response; + })->assert('entry_id', '\d+'); + + $controllers->get('/ajax/LOAD_REPORT/{ssel_id}/', function(SilexApplication $app, $ssel_id) { + + $template = 'lightbox/basket_content_report.html.twig'; + + $repository = $app['EM']->getRepository('\Entities\Basket'); + + /* @var $repository \Repositories\BasketRepository */ + $basket = $repository->findUserBasket( + $app, $ssel_id + , $app['phraseanet.user'] + , false + ); + + $response = new Response($app['twig']->render($template, array('basket' => $basket))); + $response->setCharset('UTF-8'); + + return $response; + })->assert('ssel_id', '\d+'); + + $controllers->post('/ajax/SET_NOTE/{sselcont_id}/', function (SilexApplication $app, $sselcont_id) { + $output = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees')); + + $request = $app['request']; + $note = $request->request->get('note'); + + if (is_null($note)) { + Return new Response('You must provide a note value', 400); + } + + /* @var $repository \Repositories\BasketElementRepository */ + $repository = $app['EM']->getRepository('\Entities\BasketElement'); + + $basket_element = $repository->findUserElement($sselcont_id, $app['phraseanet.user']); + + $validationDatas = $basket_element->getUserValidationDatas($app['phraseanet.user'], $app); + + $validationDatas->setNote($note); + + $app['EM']->merge($validationDatas); + + $app['EM']->flush(); + + if ($app['browser']->isMobile()) { + $datas = $app['twig']->render('lightbox/sc_note.html.twig', array('basket_element' => $basket_element)); + + $output = array('error' => false, 'datas' => $datas); + } else { + $template = 'lightbox/sc_note.html.twig'; + + $datas = $app['twig']->render($template, array('basket_element' => $basket_element)); + + $output = array('error' => false, 'datas' => $datas); + } + + return $app->json($output); + })->assert('sselcont_id', '\d+'); + + $controllers->post('/ajax/SET_ELEMENT_AGREEMENT/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) { + $request = $app['request']; + $agreement = $request->request->get('agreement'); + + if (is_null($agreement)) { + Return new Response('You must provide an agreement value', 400); + } + + $agreement = $agreement > 0; + + $releasable = false; + try { + $ret = array( + 'error' => true, + 'releasable' => false, + 'datas' => _('Erreur lors de la mise a jour des donnes ') + ); + + $user = $app['phraseanet.user']; + $repository = $app['EM']->getRepository('\Entities\BasketElement'); + + /* @var $repository \Repositories\BasketElementRepository */ + $basket_element = $repository->findUserElement( + $sselcont_id + , $user + ); + /* @var $basket_element \Entities\BasketElement */ + $validationDatas = $basket_element->getUserValidationDatas($user, $app); + + if (!$basket_element->getBasket() + ->getValidation() + ->getParticipant($user, $app)->getCanAgree()) { + throw new ControllerException('You can not agree on this'); + } + + $validationDatas->setAgreement($agreement); + + $participant = $basket_element->getBasket() + ->getValidation() + ->getParticipant($user, $app); + + $app['EM']->merge($basket_element); + + $app['EM']->flush(); + + $releasable = false; + if ($participant->isReleasable() === true) { + $releasable = _('Do you want to send your report ?'); + } + + $ret = array( + 'error' => false + , 'datas' => '' + , 'releasable' => $releasable + ); + } catch (ControllerException $e) { + $ret['datas'] = $e->getMessage(); + } + + return $app->json($ret); + })->assert('sselcont_id', '\d+'); $controllers->post('/ajax/SET_RELEASE/{ssel_id}/', function(SilexApplication $app, $ssel_id) { - $user = $app['phraseanet.user']; + $user = $app['phraseanet.user']; - $repository = $app['EM']->getRepository('\Entities\Basket'); + $repository = $app['EM']->getRepository('\Entities\Basket'); - $datas = array('error' => true, 'datas' => ''); + $datas = array('error' => true, 'datas' => ''); - try { - /* @var $repository \Repositories\BasketRepository */ - $basket = $repository->findUserBasket( - $app, $ssel_id - , $user - , false - ); + try { + /* @var $repository \Repositories\BasketRepository */ + $basket = $repository->findUserBasket( + $app, $ssel_id + , $user + , false + ); - if (!$basket->getValidation()) { - throw new ControllerException('There is no validation session attached to this basket'); - } - - if (!$basket->getValidation()->getParticipant($user, $app)->getCanAgree()) { - throw new ControllerException('You have not right to agree'); - } - - /* @var $basket \Entities\Basket */ - $participant = $basket->getValidation()->getParticipant($user, $app); - - $evt_mngr = $app['events-manager']; - - $expires = new \DateTime('+10 days'); - $url = $app['phraseanet.appbox']->get_registry()->get('GV_ServerName') - . 'lightbox/index.php?LOG=' . \random::getUrlToken( - $app, \random::TYPE_VALIDATE - , $basket->getValidation()->getInitiator($app)->get_id() - , $expires - , $basket->getId() - ); - - $to = $basket->getValidation()->getInitiator($app)->get_id(); - $params = array( - 'ssel_id' => $basket->getId(), - 'from' => $app['phraseanet.user']->get_id(), - 'url' => $url, - 'to' => $to - ); - - $evt_mngr->trigger('__VALIDATION_DONE__', $params); - - $participant->setIsConfirmed(true); - - $app['EM']->merge($participant); - $app['EM']->flush(); - - $datas = array('error' => false, 'datas' => _('Envoie avec succes')); - } catch (ControllerException $e) { - $datas = array('error' => true, 'datas' => $e->getMessage()); + if (!$basket->getValidation()) { + throw new ControllerException('There is no validation session attached to this basket'); } - return $app->json($datas); + if (!$basket->getValidation()->getParticipant($user, $app)->getCanAgree()) { + throw new ControllerException('You have not right to agree'); + } + + /* @var $basket \Entities\Basket */ + $participant = $basket->getValidation()->getParticipant($user, $app); + + $evt_mngr = $app['events-manager']; + + $expires = new \DateTime('+10 days'); + $url = $app['phraseanet.appbox']->get_registry()->get('GV_ServerName') + . 'lightbox/index.php?LOG=' . \random::getUrlToken( + $app, \random::TYPE_VALIDATE + , $basket->getValidation()->getInitiator($app)->get_id() + , $expires + , $basket->getId() + ); + + $to = $basket->getValidation()->getInitiator($app)->get_id(); + $params = array( + 'ssel_id' => $basket->getId(), + 'from' => $app['phraseanet.user']->get_id(), + 'url' => $url, + 'to' => $to + ); + + $evt_mngr->trigger('__VALIDATION_DONE__', $params); + + $participant->setIsConfirmed(true); + + $app['EM']->merge($participant); + $app['EM']->flush(); + + $datas = array('error' => false, 'datas' => _('Envoie avec succes')); + } catch (ControllerException $e) { + $datas = array('error' => true, 'datas' => $e->getMessage()); } - )->assert('ssel_id', '\d+'); + + return $app->json($datas); + })->assert('ssel_id', '\d+'); return $controllers; } diff --git a/lib/Alchemy/Phrasea/Application/OAuth2.php b/lib/Alchemy/Phrasea/Application/OAuth2.php index 780a8b48c1..bcce9bb95f 100644 --- a/lib/Alchemy/Phrasea/Application/OAuth2.php +++ b/lib/Alchemy/Phrasea/Application/OAuth2.php @@ -18,7 +18,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\Request; /** - * * * @package OAuth2 Connector * @@ -30,145 +29,144 @@ use Symfony\Component\HttpFoundation\Request; */ return call_user_func(function($environment = 'prod') { - $app = new PhraseaApplication($environment); + $app = new PhraseaApplication($environment); - $app['oauth'] = function($app) { - return new \API_OAuth2_Adapter($app); - }; + $app['oauth'] = function($app) { + return new \API_OAuth2_Adapter($app); + }; - /** - * AUTHORIZE ENDPOINT - * - * Authorization endpoint - used to obtain authorization from the - * resource owner via user-agent redirection. - */ - $authorize_func = function() use ($app) { - $request = $app['request']; - $oauth2_adapter = $app['oauth']; + /** + * AUTHORIZE ENDPOINT + * + * Authorization endpoint - used to obtain authorization from the + * resource owner via user-agent redirection. + */ + $authorize_func = function() use ($app) { + $request = $app['request']; + $oauth2_adapter = $app['oauth']; - //Check for auth params, send error or redirect if not valid - $params = $oauth2_adapter->getAuthorizationRequestParameters($request); + //Check for auth params, send error or redirect if not valid + $params = $oauth2_adapter->getAuthorizationRequestParameters($request); - $app_authorized = false; - $errorMessage = false; + $app_authorized = false; + $errorMessage = false; - $client = \API_OAuth2_Application::load_from_client_id($app, $params['client_id']); + $client = \API_OAuth2_Application::load_from_client_id($app, $params['client_id']); - $oauth2_adapter->setClient($client); + $oauth2_adapter->setClient($client); - $action_accept = $request->get("action_accept"); - $action_login = $request->get("action_login"); + $action_accept = $request->get("action_accept"); + $action_login = $request->get("action_login"); - $template = "api/auth/end_user_authorization.html.twig"; + $template = "api/auth/end_user_authorization.html.twig"; - $custom_template = sprintf( - "%sconfig/templates/web/api/auth/end_user_authorization/%s.html.twig" - , $app['phraseanet.appbox']->get_registry()->get('GV_RootPath') - , $client->get_id() + $custom_template = sprintf( + "%sconfig/templates/web/api/auth/end_user_authorization/%s.html.twig" + , $app['phraseanet.appbox']->get_registry()->get('GV_RootPath') + , $client->get_id() + ); + + if (file_exists($custom_template)) { + $template = sprintf( + 'api/auth/end_user_authorization/%s.html.twig' + , $client->get_id() + ); + } + + if (!$app->isAuthenticated()) { + if ($action_login !== null) { + try { + $auth = new \Session_Authentication_Native( + $app, $request->get("login"), $request->get("password") ); - if (file_exists($custom_template)) { - $template = sprintf( - 'api/auth/end_user_authorization/%s.html.twig' - , $client->get_id() - ); - } + $app->openAccount($auth); + } catch (\Exception $e) { - if (!$app->isAuthenticated()) { - if ($action_login !== null) { - try { - $auth = new \Session_Authentication_Native( - $app, $request->get("login"), $request->get("password") - ); + return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter))); + } + } else { + return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter))); + } + } - $app->openAccount($auth); - } catch (\Exception $e) { + //check if current client is already authorized by current user + $user_auth_clients = \API_OAuth2_Application::load_authorized_app_by_user( + $app + , $app['phraseanet.user'] + ); - return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter))); - } - } else { - return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter))); - } - } + foreach ($user_auth_clients as $auth_client) { + if ($client->get_client_id() == $auth_client->get_client_id()) { + $app_authorized = true; + } + } - //check if current client is already authorized by current user - $user_auth_clients = \API_OAuth2_Application::load_authorized_app_by_user( - $app - , $app['phraseanet.user'] - ); + $account = $oauth2_adapter->updateAccount($app['phraseanet.user']->get_id()); - foreach ($user_auth_clients as $auth_client) { - if ($client->get_client_id() == $auth_client->get_client_id()) { - $app_authorized = true; - } - } + $params['account_id'] = $account->get_id(); - $account = $oauth2_adapter->updateAccount($app['phraseanet.user']->get_id()); + if (!$app_authorized && $action_accept === null) { + $params = array( + "auth" => $oauth2_adapter, + "errorMessage" => $errorMessage, + ); - $params['account_id'] = $account->get_id(); + return new Response($app['twig']->render($template, $params)); + } elseif (!$app_authorized && $action_accept !== null) { + $app_authorized = (Boolean) $action_accept; + $account->set_revoked(!$app_authorized); + } - if (!$app_authorized && $action_accept === null) { - $params = array( - "auth" => $oauth2_adapter, - "errorMessage" => $errorMessage, - ); + //if native app show template + if ($oauth2_adapter->isNativeApp($params['redirect_uri'])) { + $params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params); - return new Response($app['twig']->render($template, $params)); - } elseif (!$app_authorized && $action_accept !== null) { - $app_authorized = (Boolean) $action_accept; - $account->set_revoked(!$app_authorized); - } + return new Response($app['twig']->render("api/auth/native_app_access_token.html.twig", $params)); + } else { + $oauth2_adapter->finishClientAuthorization($app_authorized, $params); + } + }; - //if native app show template - if ($oauth2_adapter->isNativeApp($params['redirect_uri'])) { - $params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params); + $app->match('/authorize', $authorize_func)->method('GET|POST'); - return new Response($app['twig']->render("api/auth/native_app_access_token.html.twig", $params)); - } else { - $oauth2_adapter->finishClientAuthorization($app_authorized, $params); - } - }; + /** + * TOKEN ENDPOINT + * Token endpoint - used to exchange an authorization grant for an access token. + */ + $app->post('/token', function(\Silex\Application $app, Request $request) { - $app->match('/authorize', $authorize_func)->method('GET|POST'); + $app['oauth']->grantAccessToken(); + ob_flush(); + flush(); - /** - * TOKEN ENDPOINT - * Token endpoint - used to exchange an authorization grant for an access token. - */ - $app->post('/token', function(\Silex\Application $app, Request $request) { + return; + })->requireHttps(); - $app['oauth']->grantAccessToken(); - ob_flush(); - flush(); + /** + * Error Handler + */ + $app->error(function (\Exception $e) use ($app) { + if ($e instanceof NotFoundHttpException || $e instanceof \Exception_NotFound) { + return new Response('The requested page could not be found.', 404, array('X-Status-Code' => 404)); + } - return; - })->requireHttps(); + $code = 500; + $msg = 'We are sorry, but something went wrong'; + $headers = array(); - /** - * Error Handler - */ - $app->error(function (\Exception $e) use ($app) { - if ($e instanceof NotFoundHttpException || $e instanceof \Exception_NotFound) { - return new Response('The requested page could not be found.', 404, array('X-Status-Code' => 404)); - } + if ($e instanceof HttpExceptionInterface) { + $headers = $e->getHeaders(); + $msg = $e->getMessage(); + $code = $e->getStatusCode(); - $code = 500; - $msg = 'We are sorry, but something went wrong'; - $headers = array(); + if (isset($headers['content-type']) && $headers['content-type'] == 'application/json') { + $msg = json_encode(array('msg' => $msg, 'code' => $code)); + } + } - if ($e instanceof HttpExceptionInterface) { - $headers = $e->getHeaders(); - $msg = $e->getMessage(); - $code = $e->getStatusCode(); + return new Response($msg, $code, $headers); + }); - if (isset($headers['content-type']) && $headers['content-type'] == 'application/json') { - $msg = json_encode(array('msg' => $msg, 'code' => $code)); - } - } - - return new Response($msg, $code, $headers); - }); - - return $app; - }, $environment ? : null -); + return $app; +}, isset($environment) ? $environment : null); diff --git a/lib/Alchemy/Phrasea/Application/Prod.php b/lib/Alchemy/Phrasea/Application/Prod.php deleted file mode 100644 index 7b07d4acf0..0000000000 --- a/lib/Alchemy/Phrasea/Application/Prod.php +++ /dev/null @@ -1,96 +0,0 @@ -mount('/UserPreferences/', new UserPreferences()); - $app->mount('/query/', new Query()); - $app->mount('/order/', new Order()); - $app->mount('/baskets', new Basket()); - $app->mount('/story', new Story()); - $app->mount('/WorkZone', new WorkZone()); - $app->mount('/lists', new UsrLists()); - $app->mount('/MustacheLoader', new MustacheLoader()); - $app->mount('/records/edit', new Edit()); - $app->mount('/records/movecollection', new MoveCollection()); - $app->mount('/bridge/', new Bridge()); - $app->mount('/push/', new Push()); - $app->mount('/printer/', new Printer()); - $app->mount('/TOU/', new TOU()); - $app->mount('/feeds', new Feed()); - $app->mount('/tooltip', new Tooltip()); - $app->mount('/language', new Language()); - $app->mount('/tools/', new Tools()); - $app->mount('/lazaret/', new Lazaret()); - $app->mount('/upload/', new Upload()); - $app->mount('/', new Root()); - - $app->error(function (\Exception $e, $code) use ($app) { - /* @var $request \Symfony\Component\HttpFoundation\Request */ - $request = $app['request']; - - if ($request->getRequestFormat() == 'json') { - $datas = array( - 'success' => false - , 'message' => $e->getMessage() - ); - - return $app->json($datas, 200, array('X-Status-Code' => 200)); - } - if ($e instanceof \Exception_BadRequest) { - return new Response('Bad Request', 400, array('X-Status-Code' => 400)); - } - if ($e instanceof \Exception_NotFound) { - return new Response('Not Found', 404, array('X-Status-Code' => 404)); - } - if ($e instanceof \Exception_Forbidden) { - return new Response('Not Found', 403, array('X-Status-Code' => 403)); - } - }); - - return $app; - } -); diff --git a/lib/Alchemy/Phrasea/Application/Root.php b/lib/Alchemy/Phrasea/Application/Root.php index 4df653fff0..0eb393792e 100644 --- a/lib/Alchemy/Phrasea/Application/Root.php +++ b/lib/Alchemy/Phrasea/Application/Root.php @@ -55,174 +55,155 @@ use Alchemy\Phrasea\Controller\Prod\UsrLists; use Alchemy\Phrasea\Controller\Prod\WorkZone; use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest; -use Silex\ControllerProviderInterface; -use Alchemy\Phrasea\Controller\Login\Authenticate as AuthenticateController; use Silex\Application as SilexApp; use Symfony\Component\HttpFoundation\Response; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ return call_user_func(function($environment = null) { - $app = new PhraseaApplication($environment); -// $app->enableEvents(); + $app = new PhraseaApplication($environment); - $app->before(function () use ($app) { - return $app['firewall']->requireSetup($app); - }); + $app->before(function () use ($app) { + return $app['firewall']->requireSetup($app); + }); - $app->get('/', function(SilexApp $app) { - if ($app['browser']->isMobile()) { - return $app->redirect("/login/?redirect=lightbox"); - } elseif ($app['browser']->isNewGeneration()) { - return $app->redirect("/login/?redirect=prod"); - } else { - return $app->redirect("/login/?redirect=client"); - } - }); + $app->get('/', function(SilexApp $app) { + if ($app['browser']->isMobile()) { + return $app->redirect("/login/?redirect=lightbox"); + } elseif ($app['browser']->isNewGeneration()) { + return $app->redirect("/login/?redirect=prod"); + } else { + return $app->redirect("/login/?redirect=client"); + } + }); - $app->get('/robots.txt', function(SilexApp $app) { + $app->get('/robots.txt', function(SilexApp $app) { - if ($app['phraseanet.registry']->get('GV_allow_search_engine') === true) { - $buffer = "User-Agent: *\n" . "Allow: /\n"; - } else { - $buffer = "User-Agent: *\n" . "Disallow: /\n"; - } + if ($app['phraseanet.registry']->get('GV_allow_search_engine') === true) { + $buffer = "User-Agent: *\n" . "Allow: /\n"; + } else { + $buffer = "User-Agent: *\n" . "Disallow: /\n"; + } - return new Response($buffer, 200, array('Content-Type' => 'text/plain')); - })->bind('robots'); + return new Response($buffer, 200, array('Content-Type' => 'text/plain')); + })->bind('robots'); - $app->mount('/feeds/', new RSSFeeds()); - $app->mount('/account/', new Account()); - $app->mount('/login/', new Login()); - $app->mount('/developers/', new Developers()); - $app->mount('/lightbox/', new Lightbox()); + $app->mount('/feeds/', new RSSFeeds()); + $app->mount('/account/', new Account()); + $app->mount('/login/', new Login()); + $app->mount('/developers/', new Developers()); + $app->mount('/lightbox/', new Lightbox()); + $app->mount('/datafiles/', new Datafiles()); + $app->mount('/permalink/', new Permalink()); - $app->mount('/datafiles/', new Datafiles()); - $app->mount('/permalink/', new Permalink()); + $app->mount('/admin/', new Root()); + $app->mount('/admin/dashboard', new Dashboard()); + $app->mount('/admin/collection', new Collection()); + $app->mount('/admin/databox', new Databox()); + $app->mount('/admin/databoxes', new Databoxes()); + $app->mount('/admin/setup', new Setup()); + $app->mount('/admin/sphinx', new Sphinx()); + $app->mount('/admin/connected-users', new ConnectedUsers()); + $app->mount('/admin/publications', new Publications()); + $app->mount('/admin/users', new Users()); + $app->mount('/admin/fields', new Fields()); + $app->mount('/admin/task-manager', new TaskManager()); + $app->mount('/admin/subdefs', new Subdefs()); + $app->mount('/admin/description', new Description()); + $app->mount('/admin/tests/connection', new ConnectionTest()); + $app->mount('/admin/tests/pathurl', new PathFileTest()); - $app->mount('/admin/', new Root()); - $app->mount('/admin/dashboard', new Dashboard()); - $app->mount('/admin/collection', new Collection()); - $app->mount('/admin/databox', new Databox()); - $app->mount('/admin/databoxes', new Databoxes()); - $app->mount('/admin/setup', new Setup()); - $app->mount('/admin/sphinx', new Sphinx()); - $app->mount('/admin/connected-users', new ConnectedUsers()); - $app->mount('/admin/publications', new Publications()); - $app->mount('/admin/users', new Users()); - $app->mount('/admin/fields', new Fields()); - $app->mount('/admin/task-manager', new TaskManager()); - $app->mount('/admin/subdefs', new Subdefs()); - $app->mount('/admin/description', new Description()); - $app->mount('/admin/tests/connection', new ConnectionTest()); - $app->mount('/admin/tests/pathurl', new PathFileTest()); + $app->mount('/prod/UserPreferences/', new UserPreferences()); + $app->mount('/prod/query/', new Query()); + $app->mount('/prod/order/', new Order()); + $app->mount('/prod/baskets', new Basket()); + $app->mount('/prod/story', new Story()); + $app->mount('/prod/WorkZone', new WorkZone()); + $app->mount('/prod/lists', new UsrLists()); + $app->mount('/prod/MustacheLoader', new MustacheLoader()); + $app->mount('/prod/records/edit', new Edit()); + $app->mount('/prod/records/movecollection', new MoveCollection()); + $app->mount('/prod/bridge/', new Bridge()); + $app->mount('/prod/push/', new Push()); + $app->mount('/prod/printer/', new Printer()); + $app->mount('/prod/TOU/', new TOU()); + $app->mount('/prod/feeds', new Feed()); + $app->mount('/prod/tooltip', new Tooltip()); + $app->mount('/prod/language', new Language()); + $app->mount('/prod/tools/', new Tools()); + $app->mount('/prod/lazaret/', new Lazaret()); + $app->mount('/prod/upload/', new Upload()); + $app->mount('/prod/', new Prod()); + $app->error(function(\Exception $e) use ($app) { + $request = $app['request']; - $app->mount('/prod/UserPreferences/', new UserPreferences()); - $app->mount('/prod/query/', new Query()); - $app->mount('/prod/order/', new Order()); - $app->mount('/prod/baskets', new Basket()); - $app->mount('/prod/story', new Story()); - $app->mount('/prod/WorkZone', new WorkZone()); - $app->mount('/prod/lists', new UsrLists()); - $app->mount('/prod/MustacheLoader', new MustacheLoader()); - $app->mount('/prod/records/edit', new Edit()); - $app->mount('/prod/records/movecollection', new MoveCollection()); - $app->mount('/prod/bridge/', new Bridge()); - $app->mount('/prod/push/', new Push()); - $app->mount('/prod/printer/', new Printer()); - $app->mount('/prod/TOU/', new TOU()); - $app->mount('/prod/feeds', new Feed()); - $app->mount('/prod/tooltip', new Tooltip()); - $app->mount('/prod/language', new Language()); - $app->mount('/prod/tools/', new Tools()); - $app->mount('/prod/lazaret/', new Lazaret()); - $app->mount('/prod/upload/', new Upload()); - $app->mount('/prod/', new Prod()); + 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()) + ); - $app->error(function(\Exception $e) use ($app) { + 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, array('X-Status-Code' => 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, array('X-Status-Code' => 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, array('X-Status-Code' => 200)); + } elseif ($e instanceof \Bridge_Exception_ApiDisabled) { + $params = array_merge($params, array('api' => $e->get_api())); - $request = $app['request']; + $response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200, array('X-Status-Code' => 200)); + } else { + $response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, array('X-Status-Code' => 200)); + } - if ($e instanceof \Bridge_Exception) { + $response->headers->set('Phrasea-StatusCode', 200); - $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()) - ); + return $response; + } - if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) { - $params = array_merge($params, array('account' => $app['current_account'])); + if ($request->getRequestFormat() == 'json') { + $datas = array( + 'success' => false + , 'message' => $e->getMessage() + ); - $response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200, array('X-Status-Code' => 200)); - } elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) { - $params = array_merge($params, array('account' => $app['current_account'])); + return $app->json($datas, 200, array('X-Status-Code' => 200)); + } - $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200)); - } elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) { - $params = array_merge($params, array('account' => $app['current_account'])); + if ($e instanceof \Exception_BadRequest) { + return new Response('Bad Request', 400, array('X-Status-Code' => 400)); + } + if ($e instanceof \Exception_Forbidden) { + return new Response('Forbidden', 403, array('X-Status-Code' => 403)); + } - $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200)); - } elseif ($e instanceof \Bridge_Exception_ApiDisabled) { - $params = array_merge($params, array('api' => $e->get_api())); + if ($e instanceof \Exception_Session_NotAuthenticated) { + $code = 403; + $message = 'Forbidden'; + } elseif ($e instanceof \Exception_NotAllowed) { + $code = 403; + $message = 'Forbidden'; + } elseif ($e instanceof \Exception_NotFound) { + $code = 404; + $message = 'Not Found'; + } else { + throw $e; + } - $response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200, array('X-Status-Code' => 200)); - } else { - $response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, array('X-Status-Code' => 200)); - } + return new Response($message, $code, array('X-Status-Code' => $code)); + }); - $response->headers->set('Phrasea-StatusCode', 200); - - return $response; - } - - - $request = $app['request']; - - if ($request->getRequestFormat() == 'json') { - $datas = array( - 'success' => false - , 'message' => $e->getMessage() - ); - - return $app->json($datas, 200, array('X-Status-Code' => 200)); - } - if ($e instanceof \Exception_BadRequest) { - return new Response('Bad Request', 400, array('X-Status-Code' => 400)); - } - if ($e instanceof \Exception_Forbidden) { - return new Response('Forbidden', 403, array('X-Status-Code' => 403)); - } - - - if ($e instanceof \Exception_Session_NotAuthenticated) { - $code = 403; - $message = 'Forbidden'; - } elseif ($e instanceof \Exception_NotAllowed) { - $code = 403; - $message = 'Forbidden'; - } elseif ($e instanceof \Exception_NotFound) { - $code = 404; - $message = 'Not Found'; - } else { - throw $e; - } - - return new Response($message, $code, array('X-Status-Code' => $code)); - }); - - return $app; - }, isset($environment) ? $environment : null -); + return $app; +}, isset($environment) ? $environment : null); diff --git a/lib/Alchemy/Phrasea/Application/Setup.php b/lib/Alchemy/Phrasea/Application/Setup.php index 83e359f52d..aa30cd42de 100644 --- a/lib/Alchemy/Phrasea/Application/Setup.php +++ b/lib/Alchemy/Phrasea/Application/Setup.php @@ -13,74 +13,66 @@ namespace Alchemy\Phrasea\Application; use Alchemy\Phrasea\Core\Configuration; use Alchemy\Phrasea\Application as PhraseaApplication; -use Symfony\Component\HttpFoundation\Response; use Alchemy\Phrasea\Controller\Setup\Installer; use Alchemy\Phrasea\Controller\Setup\Upgrader; use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -return call_user_func(function() { +return call_user_func(function($environment = null) { - $app = new PhraseaApplication(); + $app = new PhraseaApplication(); - $app['install'] = false; - $app['upgrade'] = false; + $app['install'] = false; + $app['upgrade'] = false; - $app->before(function($a) use ($app) { - if (\setup::is_installed()) { - if ( ! $app['phraseanet.appbox']->need_major_upgrade()) { - throw new \Exception_Setup_PhraseaAlreadyInstalled(); - } + $app->before(function($a) use ($app) { + if (\setup::is_installed()) { + if (!$app['phraseanet.appbox']->need_major_upgrade()) { + throw new \Exception_Setup_PhraseaAlreadyInstalled(); + } - $app['upgrade'] = true; - } elseif (\setup::needUpgradeConfigurationFile()) { + $app['upgrade'] = true; + } elseif (\setup::needUpgradeConfigurationFile()) { - if (\setup::requireGVUpgrade()) { - setup::upgradeGV($app['phraseanet.core']['Registry']); - } + if (\setup::requireGVUpgrade()) { + setup::upgradeGV($app['phraseanet.core']['Registry']); + } - $connexionInc = new \SplFileInfo(__DIR__ . '/../../../../config/connexion.inc'); - $configInc = new \SplFileInfo(__DIR__ . '/../../../../config/config.inc'); + $connexionInc = new \SplFileInfo(__DIR__ . '/../../../../config/connexion.inc'); + $configInc = new \SplFileInfo(__DIR__ . '/../../../../config/config.inc'); - echo " config at ".__FILE__."\n"; - $configuration = Configuration::build(); - $configuration->upgradeFromOldConf($configInc, $connexionInc); + $configuration = Configuration::build(); + $configuration->upgradeFromOldConf($configInc, $connexionInc); - $app['install'] = true; - } else { - $app['install'] = true; - } + $app['install'] = true; + } else { + $app['install'] = true; + } - return; - }); + return; + }); - $app->get('/', function() use ($app) { - if ($app['install'] === true) { - return $app->redirect('/setup/installer/'); - }if ($app['upgrade'] === true) { - return $app->redirect('/setup/upgrader/'); - } - }); + $app->get('/', function() use ($app) { + if ($app['install'] === true) { + return $app->redirect('/setup/installer/'); + }if ($app['upgrade'] === true) { + return $app->redirect('/setup/upgrader/'); + } + }); - $app->mount('/installer/', new Installer()); - $app->mount('/upgrader/', new Upgrader()); - $app->mount('/test', new PathFileTest()); - $app->mount('/connection_test', new ConnectionTest()); + $app->mount('/installer/', new Installer()); + $app->mount('/upgrader/', new Upgrader()); + $app->mount('/test', new PathFileTest()); + $app->mount('/connection_test', new ConnectionTest()); - $app->error(function($e) use ($app) { - if ($e instanceof \Exception_Setup_PhraseaAlreadyInstalled) { - return $app->redirect('/login/'); - } + $app->error(function($e) use ($app) { + if ($e instanceof \Exception_Setup_PhraseaAlreadyInstalled) { + return $app->redirect('/login/'); + } - throw $e; -// return new Response('Internal Server Error', 500); - }); + return new Response('Internal Server Error', 500, array('X-Status-Code' => 500)); + }); - return $app; - } + return $app; + }, isset($environment) ? $environment : null );