From db40a0bf7cf8a03040a712df9be08ed735481849 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Mon, 27 Aug 2012 15:26:20 +0200 Subject: [PATCH] fix some bugs --- config/nginx.rewrite.rules | 2 +- lib/Alchemy/Phrasea/Application.php | 7 +- lib/Alchemy/Phrasea/Application/Admin.php | 12 +- .../Phrasea/Controller/Admin/Collection.php | 302 +++++++++------- .../Controller/Admin/ConnectedUsers.php | 9 +- .../Phrasea/Controller/Admin/Dashboard.php | 21 +- .../Phrasea/Controller/Admin/Databox.php | 332 +++++++++++------- .../Phrasea/Controller/Admin/Databoxes.php | 42 +-- .../Phrasea/Controller/Admin/Description.php | 4 +- .../Phrasea/Controller/Admin/Fields.php | 2 +- .../Phrasea/Controller/Admin/Publications.php | 2 +- lib/Alchemy/Phrasea/Controller/Admin/Root.php | 22 +- .../Phrasea/Controller/Admin/Setup.php | 6 +- .../Phrasea/Controller/Admin/Sphinx.php | 15 +- .../Phrasea/Controller/Admin/Subdefs.php | 4 +- .../Phrasea/Controller/Admin/Users.php | 32 +- .../Phrasea/Controller/Setup/Installer.php | 6 +- lib/classes/appbox.class.php | 46 ++- lib/classes/databox/status.class.php | 5 +- .../web/admin/collection/collection.html.twig | 186 ++++++---- .../web/admin/collection/reorder.html.twig | 2 +- .../collection/suggested_value.html.twig | 20 +- templates/web/admin/databases.html.twig | 33 +- templates/web/admin/databox/cgus.html.twig | 9 +- templates/web/admin/databox/databox.html.twig | 128 +++++-- templates/web/admin/databox/details.html.twig | 4 +- templates/web/admin/index.html.twig | 114 +++--- templates/web/admin/statusbit.html.twig | 9 +- templates/web/admin/statusbit/edit.html.twig | 81 ++++- templates/web/admin/structure.html.twig | 2 +- templates/web/admin/user/demand.html.twig | 2 +- .../web/admin/user/import/file.html.twig | 50 ++- templates/web/admin/users.html.twig | 2 +- .../Controller/Admin/AdminCollectionTest.php | 108 ++++-- .../Phrasea/Controller/Admin/DataboxTest.php | 71 ++-- www/.htaccess | 2 +- 36 files changed, 1024 insertions(+), 670 deletions(-) diff --git a/config/nginx.rewrite.rules b/config/nginx.rewrite.rules index 0bbf605be9..9f4e8e1851 100644 --- a/config/nginx.rewrite.rules +++ b/config/nginx.rewrite.rules @@ -4,7 +4,7 @@ rewrite ^/(download)/([a-zA-Z0-9]*)\/get$ /include/download_prepare.php?type rewrite ^/(mail-export)/([a-zA-Z0-9]*)\/?$ /include/download_anonymous.php?type=$1&token=$2 last; rewrite ^/(mail-export)/([a-zA-Z0-9]*)\/get$ /include/download_anonymous.php?type=$1&token=$2&get=1 last; -rewrite ^/admin/$ /admin/router.php last; +rewrite ^/admin/.*$ /admin/router.php last; rewrite ^/admin/databox/.*$ /admin/router.php last; rewrite ^/admin/sphinx/.*$ /admin/router.php last; rewrite ^/admin/structure/.*$ /admin/router.php last; diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 9d4d9e524c..7f8df04eda 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -5,9 +5,9 @@ namespace Alchemy\Phrasea; use Alchemy\Phrasea\PhraseanetServiceProvider; use Alchemy\Phrasea\Core\Provider\BrowserServiceProvider; use Silex\Application as SilexApplication; +use Silex\Provider\TwigServiceProvider; use Silex\Provider\UrlGeneratorServiceProvider; use Silex\Provider\ValidatorServiceProvider; -use Silex\Provider\TwigServiceProvider; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -74,7 +74,6 @@ class Application extends SilexApplication } $twig->addGlobal('session', $app['phraseanet.appbox']->get_session()); - $twig->addGlobal('appbox', $app['phraseanet.appbox']); $twig->addGlobal('version_number', $app['phraseanet.core']->getVersion()->getNumber()); $twig->addGlobal('version_name', $app['phraseanet.core']->getVersion()->getName()); $twig->addGlobal('core', $app['phraseanet.core']); @@ -138,6 +137,10 @@ class Application extends SilexApplication $app = $this; $this->error(function($e) use ($app) { + + var_dump($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); + exit; + if ($app['debug']) { return new Response($e->getMessage(), 500); } else { diff --git a/lib/Alchemy/Phrasea/Application/Admin.php b/lib/Alchemy/Phrasea/Application/Admin.php index e87c2a2f81..8bb1b4dbbf 100644 --- a/lib/Alchemy/Phrasea/Application/Admin.php +++ b/lib/Alchemy/Phrasea/Application/Admin.php @@ -12,19 +12,19 @@ namespace Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\Admin\Collection; use Alchemy\Phrasea\Controller\Admin\ConnectedUsers; +use Alchemy\Phrasea\Controller\Admin\Dashboard; +use Alchemy\Phrasea\Controller\Admin\Databox; +use Alchemy\Phrasea\Controller\Admin\Databoxes; use Alchemy\Phrasea\Controller\Admin\Description; use Alchemy\Phrasea\Controller\Admin\Fields; use Alchemy\Phrasea\Controller\Admin\Publications; use Alchemy\Phrasea\Controller\Admin\Root; -use Alchemy\Phrasea\Controller\Admin\Subdefs; -use Alchemy\Phrasea\Controller\Admin\Users; -use Alchemy\Phrasea\Controller\Admin\Dashboard; -use Alchemy\Phrasea\Controller\Admin\Collection; -use Alchemy\Phrasea\Controller\Admin\Databoxes; -use Alchemy\Phrasea\Controller\Admin\Databox; use Alchemy\Phrasea\Controller\Admin\Setup; use Alchemy\Phrasea\Controller\Admin\Sphinx; +use Alchemy\Phrasea\Controller\Admin\Subdefs; +use Alchemy\Phrasea\Controller\Admin\Users; use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest; diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php index e49debeee4..5ac84940c1 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php @@ -11,21 +11,18 @@ namespace Alchemy\Phrasea\Controller\Admin; +use Silex\Application; +use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + /** * * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Response; -use Silex\Application; -use Silex\ControllerProviderInterface; - -/** - * - */ class Collection implements ControllerProviderInterface { @@ -38,7 +35,7 @@ class Collection implements ControllerProviderInterface return $response; } - if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->get('bas_id'), 'canadmin')) { + if ( ! $app['phraseanet.core']->getAUthenticatedUser()->ACL()->has_right_on_base($app['request']->attributes->get('bas_id'), 'canadmin')) { $app->abort(403); } }); @@ -399,6 +396,7 @@ class Collection implements ControllerProviderInterface $collection = \collection::get_from_base_id($bas_id); $admins = array(); + if ($app['phraseanet.core']->getAuthenticatedUser()->ACL()->has_right_on_base($bas_id, 'manage')) { $query = new \User_Query($app['phraseanet.appbox']); $admins = $query->on_base_ids(array($bas_id)) @@ -407,9 +405,26 @@ class Collection implements ControllerProviderInterface ->get_results(); } + switch ($errorMsg = $request->query->get('error')) { + case 'file-error': + $errorMsg = _('forms::erreur lors de l\'envoi du fichier'); + break; + case 'file-invalid': + $errorMsg = _('Invalid file format'); + break; + case 'file-file-too-big': + $errorMsg = _('The file is too big'); + break; + case 'collection-not-empty': + $errorMsg = _('admin::base:collection: vider la collection avant de la supprimer'); + break; + } + return new Response($app['twig']->render('admin/collection/collection.html.twig', array( 'collection' => $collection, 'admins' => $admins, + 'errorMsg' => $errorMsg, + 'reloadTree' => $request->query->get('reload-tree') === '1' ))); } @@ -423,7 +438,7 @@ class Collection implements ControllerProviderInterface */ public function setOrderAdmins(Application $app, Request $request, $bas_id) { - if (count($admins = $request->get('admins', array())) > 0) { + if (count($admins = $request->request->get('admins', array())) > 0) { $new_admins = array(); foreach ($admins as $admin) { @@ -435,7 +450,7 @@ class Collection implements ControllerProviderInterface } } - return $app->redirect('/admin/collection/' . $bas_id . '/?operation=ok'); + return $app->redirect('/admin/collection/' . $bas_id . '/'); } /** @@ -448,23 +463,19 @@ class Collection implements ControllerProviderInterface */ public function emptyCollection(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $message = _('An error occurred'); + $msg = _('An error occurred'); try { $collection = \collection::get_from_base_id($bas_id); if ($collection->get_record_amount() <= 500) { $collection->empty_collection(500); - $message = _('Collection empty successful'); + $msg = _('Collection empty successful'); } else { $settings = '' . $collection->get_base_id() . ''; \task_abstract::create($app['phraseanet.appbox'], 'task_period_emptyColl', $settings); - $message = _('A task has been creted, please run it to complete empty collection'); + $msg = _('A task has been creted, please run it to complete empty collection'); } $success = true; @@ -472,7 +483,16 @@ class Collection implements ControllerProviderInterface } - return $app->json(array('success' => $success, 'msg' => $message)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $msg, + 'bas_id' => $collection->get_base_id() + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -485,12 +505,7 @@ class Collection implements ControllerProviderInterface */ public function deleteBanner(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); @@ -500,7 +515,16 @@ class Collection implements ControllerProviderInterface } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'bas_id' => $collection->get_base_id() + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -513,12 +537,7 @@ class Collection implements ControllerProviderInterface */ public function deleteStamp(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); @@ -528,7 +547,16 @@ class Collection implements ControllerProviderInterface } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'bas_id' => $collection->get_base_id() + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -541,12 +569,7 @@ class Collection implements ControllerProviderInterface */ public function deleteWatermark(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); @@ -556,7 +579,16 @@ class Collection implements ControllerProviderInterface } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'bas_id' => $collection->get_base_id() + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -569,23 +601,27 @@ class Collection implements ControllerProviderInterface */ public function deleteLogo(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); $collection->update_logo(null); - $app['phraseanet.appbox']->write_collection_pic($collection, null, \collection::PIC_WM); + $app['phraseanet.appbox']->write_collection_pic($collection, null, \collection::PIC_LOGO); $success = true; } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'bas_id' => $collection->get_base_id() + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -604,12 +640,12 @@ class Collection implements ControllerProviderInterface if ($file->getClientSize() > 1024 * 1024) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=too-big'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-too-big'); } if ( ! $file->isValid()) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=unknow-error'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-invalid'); } try { @@ -620,10 +656,10 @@ class Collection implements ControllerProviderInterface $app['phraseanet.core']['file-system']->remove($file->getPathname()); } catch (\Exception $e) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=unknow-error'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-error'); } - return $app->redirect('/admin/collection/' . $bas_id . '/?operation=ok'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=1'); } /** @@ -642,12 +678,12 @@ class Collection implements ControllerProviderInterface if ($file->getClientSize() > 1024 * 1024) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=too-big'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-too-big'); } if ( ! $file->isValid()) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=unknow-error'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-invalid'); } try { @@ -658,10 +694,10 @@ class Collection implements ControllerProviderInterface $app['phraseanet.core']['file-system']->remove($file->getPathname()); } catch (\Exception $e) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=unknow-error'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-error'); } - return $app->redirect('/admin/collection/' . $bas_id . '/?operation=ok'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=1'); } /** @@ -680,12 +716,12 @@ class Collection implements ControllerProviderInterface if ($file->getClientSize() > 65535) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=too-big'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-too-big'); } if ( ! $file->isValid()) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=unknow-error'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-invalid'); } try { @@ -696,10 +732,10 @@ class Collection implements ControllerProviderInterface $app['phraseanet.core']['file-system']->remove($file->getPathname()); } catch (\Exception $e) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=unknow-error'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-error'); } - return $app->redirect('/admin/collection/' . $bas_id . '/?operation=ok'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=1'); } /** @@ -718,12 +754,12 @@ class Collection implements ControllerProviderInterface if ($file->getClientSize() > 65535) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=too-big'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-too-big'); } if ( ! $file->isValid()) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=unknow-error'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-invalid'); } try { @@ -734,10 +770,10 @@ class Collection implements ControllerProviderInterface $app['phraseanet.core']['file-system']->remove($file->getPathname()); } catch (\Exception $e) { - return $app->redirect('/admin/collection/' . $bas_id . '/?upload-error=unknow-error'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=0&error=file-error'); } - return $app->redirect('/admin/collection/' . $bas_id . '/?operation=ok'); + return $app->redirect('/admin/collection/' . $bas_id . '/?success=1'); } /** @@ -750,10 +786,6 @@ class Collection implements ControllerProviderInterface */ public function delete(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; $msg = _('An error occured'); @@ -762,6 +794,7 @@ class Collection implements ControllerProviderInterface if ($collection->get_record_amount() > 0) { $msg = _('admin::base:collection: vider la collection avant de la supprimer'); + } else { $collection->unmount_collection($app['phraseanet.appbox']); $collection->delete(); @@ -772,7 +805,25 @@ class Collection implements ControllerProviderInterface } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $msg + )); + } + + if($collection->get_record_amount() > 0) { + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=0&error=collection-not-empty'); + } + + if ($success) { + + return $app->redirect('/admin/databox/' . $collection->get_sbas_id() . '/?success=1&reload-tree=1'); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=0'); } /** @@ -785,23 +836,25 @@ class Collection implements ControllerProviderInterface */ public function unmount(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); $collection->unmount_collection($app['phraseanet.appbox']); $success = true; - $msg = _('forms::operation effectuee OK'); } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured') + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -814,27 +867,29 @@ class Collection implements ControllerProviderInterface */ public function rename(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - - if (null === $name = $request->get('name')) { - $app->abort(400, _('Missing name format')); + if (trim($name = $request->request->get('name')) === '') { + $app->abort(400, _('Missing name parameter')); } $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); $collection->set_name($name); $success = true; - $msg = _('forms::operation effectuee OK'); } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured') + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success . '&reload-tree=1'); } /** @@ -847,27 +902,29 @@ class Collection implements ControllerProviderInterface */ public function setPublicationDisplay(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - - if (null === $watermark = $request->get('pub_wm')) { + if (null === $watermark = $request->request->get('pub_wm')) { $app->abort(400, _('Missing pub_wm format')); } $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); $collection->set_public_presentation($watermark); $success = true; - $msg = _('forms::operation effectuee OK'); } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured') + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -880,23 +937,25 @@ class Collection implements ControllerProviderInterface */ public function enable(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); $collection->enable($app['phraseanet.appbox']); $success = true; - $msg = _('forms::operation effectuee OK'); } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured') + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -909,23 +968,25 @@ class Collection implements ControllerProviderInterface */ public function disabled(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); $collection->disable($app['phraseanet.appbox']); $success = true; - $msg = _('forms::operation effectuee OK'); } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured') + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success); } /** @@ -978,21 +1039,12 @@ class Collection implements ControllerProviderInterface } } - if ($updateMsg = $request->get('update')) { - switch ($updateMsg) { - case 'ok'; - $updateMsg = _('forms::operation effectuee OK'); - break; - } - } - return new Response($app['twig']->render('admin/collection/suggested_value.html.twig', array( 'collection' => $collection, 'databox' => $databox, 'suggestedValues' => $suggestedValues, 'structFields' => $structFields, 'basePrefs' => $basePrefs, - 'updateMsg' => $updateMsg, ))); } @@ -1006,29 +1058,29 @@ class Collection implements ControllerProviderInterface */ public function submitSuggestedValues(Application $app, Request $request, $bas_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $collection = \collection::get_from_base_id($bas_id); - if ($mdesc = \DOMDocument::loadXML($request->get('str'))) { + if ($mdesc = \DOMDocument::loadXML($request->request->get('str'))) { $collection->set_prefs($mdesc); - $msg = _('forms::operation effectuee OK'); $success = true; - } else { - $msg = _('Coult not load XML'); - $success = false; } } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'bas_id' => $collection->get_base_id() + )); + } + + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/suggested-values/?success=' . (int) $success); } /** diff --git a/lib/Alchemy/Phrasea/Controller/Admin/ConnectedUsers.php b/lib/Alchemy/Phrasea/Controller/Admin/ConnectedUsers.php index 72be388eff..431461e805 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/ConnectedUsers.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/ConnectedUsers.php @@ -11,15 +11,10 @@ namespace Alchemy\Phrasea\Controller\Admin; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Dashboard.php b/lib/Alchemy/Phrasea/Controller/Admin/Dashboard.php index 69ecced050..bc67d95973 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Dashboard.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Dashboard.php @@ -11,15 +11,10 @@ namespace Alchemy\Phrasea\Controller\Admin; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * @@ -129,11 +124,7 @@ class Dashboard implements ControllerProviderInterface */ public function slash(Application $app, Request $request) { - if ((false !== $cacheFlushed = $request->get('flush_cache', false)) && $cacheFlushed === 'ok') { - $cacheFlushed = true; - } - - switch ($emailStatus = $request->get('email')) { + switch ($emailStatus = $request->query->get('email')) { case 'sent'; $emailStatus = _('Mail sent'); break; @@ -150,7 +141,7 @@ class Dashboard implements ControllerProviderInterface } $parameters = array( - 'cache_flushed' => $cacheFlushed, + 'cache_flushed' => $request->query->get('flush_cache') === 'ok', 'admins' => \User_Adapter::get_sys_admins(), 'email_status' => $emailStatus, 'search_engine_status' => $searchEngineStatus, @@ -193,7 +184,7 @@ class Dashboard implements ControllerProviderInterface */ public function sendMail(Application $app, Request $request) { - if (null === $mail = $request->get('email')) { + if (null === $mail = $request->request->get('email')) { $app->abort(400, 'Bad request missing email parameter'); }; @@ -230,7 +221,7 @@ class Dashboard implements ControllerProviderInterface { $user = $app['phraseanet.core']->getAuthenticatedUser(); - if (count($admins = $request->get('admins', array())) > 0) { + if (count($admins = $request->request->get('admins', array())) > 0) { if ( ! in_array($user->get_id(), $admins)) { $admins[] = $user->get_id(); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Databox.php b/lib/Alchemy/Phrasea/Controller/Admin/Databox.php index 62ebf32b8e..091a734fd9 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Databox.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Databox.php @@ -11,17 +11,12 @@ namespace Alchemy\Phrasea\Controller\Admin; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -use Alchemy\Phrasea\Core\Configuration; use Alchemy\Phrasea\Core; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; +use Alchemy\Phrasea\Core\Configuration; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * @@ -409,25 +404,23 @@ class Databox implements ControllerProviderInterface { $databox = $app['phraseanet.appbox']->get_databox($databox_id); - switch ($uploadErrorLogoMsg = $request->get('upload-logo')) { - case 'error': - $uploadErrorLogoMsg = _('forms::erreur lors de l\'envoi du fichier'); + switch ($errorMsg = $request->query->get('error')) { + case 'file-error': + $errorMsg = _('forms::erreur lors de l\'envoi du fichier'); break; - case 'error-send': - $uploadErrorLogoMsg = _('forms::erreur lors de l\'envoi du fichier'); + case 'file-invalid': + $errorMsg = _('Invalid file format'); break; - case 'error-invalid': - $uploadErrorLogoMsg = _('Invalid file format'); - break; - case 'too-big': - $uploadErrorLogoMsg = _('The file is too big'); + case 'file-too-big': + $errorMsg = _('The file is too big'); break; } return new Response($app['twig']->render('admin/databox/databox.html.twig', array( - 'databox' => $databox, - 'showDetail' => (int) $request->get("sta") < 1, - 'uploadErrorLogoMsg' => $uploadErrorLogoMsg + 'databox' => $databox, + 'showDetail' => (int) $request->query->get("sta") < 1, + 'errorMsg' => $errorMsg, + 'reloadTree' => $request->query->get('reload-tree') === '1' ))); } @@ -463,29 +456,34 @@ class Databox implements ControllerProviderInterface */ public function deleteBase(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - - $ret = array('sbas_id' => null, 'success' => false, 'msg' => null); - + $success = false; + $msg = _('An error occured'); try { $databox = $app['phraseanet.appbox']->get_databox($databox_id); - if ($databox->get_record_amount() == 0) { + + if ($databox->get_record_amount() > 0) { + $msg = _('admin::base: vider la base avant de la supprimer'); + } else { $databox->unmount_databox($app['phraseanet.appbox']); $app['phraseanet.appbox']->write_databox_pic($databox, null, \databox::PIC_PDF); $databox->delete(); - $ret['sbas_id'] = $databox_id; - $ret['success'] = true; - $ret['msg'] = _('forms::operation effectuee OK'); - } else { - $ret['msg'] = _('admin::base: vider la base avant de la supprimer'); + $success = true; + $msg = _('forms::operation effectuee OK'); } } catch (\Exception $e) { - $ret['msg'] = _('An error occured'); + } - return $app->json($ret); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $msg, + 'sbas_id' => $databox->get_sbas_id() + )); + } + + return $app->redirect('/admin/databox/' . $databox->get_sbas_id() . '/?success=' . (int) $success . ($databox->get_record_amount() > 0 ? '&error=databox-not-empty' : '')); } /** @@ -498,13 +496,25 @@ class Databox implements ControllerProviderInterface */ public function reindex(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); + $success = false; + + try { + $app['phraseanet.appbox']->get_databox($databox_id)->reindex(); + $success = true; + } catch (\Exception $e) { + } - $app['phraseanet.appbox']->get_databox($databox_id)->reindex(); + if ('json' === $app['request']->getRequestFormat()) { - return $app->json(array('sbas_id' => $databox_id)); + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'sbas_id' => $databox_id + )); + } + + return $app->redirect('/admin/databox/' . $databox_id . '/?success=' . (int) $success); } /** @@ -517,13 +527,25 @@ class Databox implements ControllerProviderInterface */ public function setIndexable(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); + $success = false; + + try { + $app['phraseanet.appbox']->set_databox_indexable($app['phraseanet.appbox']->get_databox($databox_id), ! ! $request->request->get('indexable', false)); + $success = true; + } catch (\Exception $e) { + } - $app['phraseanet.appbox']->set_databox_indexable($app['phraseanet.appbox']->get_databox($databox_id), ! ! $request->get('indexable', false)); + if ('json' === $app['request']->getRequestFormat()) { - return $app->json(array('sbas_id' => $databox_id)); + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'sbas_id' => $databox_id + )); + } + + return $app->redirect('/admin/databox/' . $databox_id . '/?success=' . (int) $success); } /** @@ -542,11 +564,16 @@ class Databox implements ControllerProviderInterface $databox = $app['phraseanet.appbox']->get_databox($databox_id); - foreach ($request->get('TOU', array()) as $loc => $terms) { - $databox->update_cgus($loc, $terms, ! ! $request->get('valid', false)); + try { + foreach ($request->request->get('TOU', array()) as $loc => $terms) { + $databox->update_cgus($loc, $terms, ! ! $request->request->get('valid', false)); + } + } catch (\Exception $e) { + + return $app->redirect('/admin/databox/' . $databox_id . '/cgus/?success=0'); } - return $app->redirect('/admin/databox/' . $databox_id . '/cgus/'); + return $app->redirect('/admin/databox/' . $databox_id . '/cgus/?success=1'); } /** @@ -559,19 +586,19 @@ class Databox implements ControllerProviderInterface */ public function createDatabase(Application $app, Request $request) { - if ('' === $dbName = $request->get('new_dbname', '')) { + if ('' === $dbName = $request->request->get('new_dbname', '')) { - return $app->redirect('/admin/databases/?error=no-empty'); + return $app->redirect('/admin/databoxes/?error=no-empty'); } if (\p4string::hasAccent($dbName)) { - return $app->redirect('/admin/databases/?error=special-chars'); + return $app->redirect('/admin/databoxes/?error=special-chars'); } $registry = $app['phraseanet.core']['Registry']; - if ((null === $request->get('new_settings')) && (null !== $dataTemplate = $request->get('new_data_template'))) { + if ((null === $request->request->get('new_settings')) && (null !== $dataTemplate = $request->request->get('new_data_template'))) { $configuration = Configuration::build(); $choosenConnexion = $configuration->getPhraseanet()->get('database'); @@ -588,27 +615,28 @@ class Databox implements ControllerProviderInterface $connbas = new \connection_pdo('databox_creation', $hostname, $port, $user, $password, $dbName, array(), $registry); } catch (\PDOException $e) { - return $app->redirect('/admin/databases/?error=database-failed'); + return $app->redirect('/admin/databoxes/?success=0&error=database-failed'); } try { $base = \databox::create($app['phraseanet.appbox'], $connbas, $dataTemplate, $registry); $base->registerAdmin($app['phraseanet.core']->getAuthenticatedUser()); + $app['phraseanet.core']->getAuthenticatedUser()->ACL()->delete_data_from_cache(); - return $app->redirect('/admin/databases/?success=base-ok&sbas-id=' . $base->get_sbas_id()); + return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1'); } catch (\Exception $e) { - return $app->redirect('/admin/databases/?error=base-failed'); + return $app->redirect('/admin/databoxes/?success=0&error=base-failed'); } } if ( - null !== $request->get('new_settings') - && (null !== $hostname = $request->get('new_hostname')) - && (null !== $port = $request->get('new_port')) - && (null !== $userDb = $request->get('new_user')) - && (null !== $passwordDb = $request->get('new_password')) - && (null !== $dataTemplate = $request->get('new_data_template'))) { + null !== $request->request->get('new_settings') + && (null !== $hostname = $request->request->get('new_hostname')) + && (null !== $port = $request->request->get('new_port')) + && (null !== $userDb = $request->request->get('new_user')) + && (null !== $passwordDb = $request->request->get('new_password')) + && (null !== $dataTemplate = $request->request->get('new_data_template'))) { try { $data_template = new \SplFileInfo($registry->get('GV_RootPath') . 'lib/conf.d/data_templates/' . $dataTemplate . '.xml'); @@ -617,14 +645,14 @@ class Databox implements ControllerProviderInterface $base = \databox::create($app['phraseanet.appbox'], $connbas, $data_template, $registry); $base->registerAdmin($app['phraseanet.core']->getAuthenticatedUser()); - return $app->redirect('/admin/databases/?success=base-ok&sbas-id=' . $base->get_sbas_id()); + return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1'); } catch (\Exception $e) { - return $app->redirect('/admin/databases/?error=base-failed'); + return $app->redirect('/admin/databoxes/?success=0&error=base-failed'); } } catch (\Exception $e) { - return $app->redirect('/admin/databases/?error=database-failed'); + return $app->redirect('/admin/databoxes/?success=0&error=database-failed'); } } } @@ -638,20 +666,20 @@ class Databox implements ControllerProviderInterface */ public function databaseMount(Application $app, Request $request) { - if ('' === $dbName = trim($request->get('new_dbname', ''))) { + if ('' === $dbName = trim($request->request->get('new_dbname', ''))) { - return $app->redirect('/admin/databases/?error=no-empty'); + return $app->redirect('/admin/databoxes/?success=0&error=no-empty'); } if (\p4string::hasAccent($dbName)) { - return $app->redirect('/admin/databases/?error=special-chars'); + return $app->redirect('/admin/databoxes/?success=0&error=special-chars'); } $appbox = $app['phraseanet.appbox']; $registry = $app['phraseanet.core']['Registry']; - if ((null === $request->get('new_settings'))) { + if ((null === $request->request->get('new_settings'))) { try { $configuration = Configuration::build(); $connexion = $configuration->getConnexion(); @@ -666,20 +694,21 @@ class Databox implements ControllerProviderInterface $base->registerAdmin($app['phraseanet.core']->getAuthenticatedUser()); $appbox->get_connection()->commit(); - return $app->redirect('/admin/databases/?success=mount-ok&sbas-id=' . $base->get_sbas_id()); + return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1'); } catch (\Exception $e) { $appbox->get_connection()->rollBack(); - - return $app->redirect('/admin/databases/?error=mount-failed'); + var_dump($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); + exit; + return $app->redirect('/admin/databoxes/?success=0&error=mount-failed'); } } if ( - null !== $request->get('new_settings') - && (null !== $hostname = $request->get('new_hostname')) - && (null !== $port = $request->get('new_port')) - && (null !== $userDb = $request->get('new_user')) - && (null !== $passwordDb = $request->get('new_password'))) { + null !== $request->request->get('new_settings') + && (null !== $hostname = $request->request->get('new_hostname')) + && (null !== $port = $request->request->get('new_port')) + && (null !== $userDb = $request->request->get('new_user')) + && (null !== $passwordDb = $request->request->get('new_password'))) { try { $appbox->get_connection()->beginTransaction(); @@ -687,11 +716,11 @@ class Databox implements ControllerProviderInterface $base->registerAdmin($app['phraseanet.core']->getAuthenticatedUser()); $appbox->get_connection()->commit(); - return $app->redirect('/admin/databases/?success=mount-ok&sbas-id=' . $base->get_sbas_id()); + return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1'); } catch (\Exception $e) { $appbox->get_connection()->rollBack(); - return $app->redirect('/admin/databases/?error=mount-failed'); + return $app->redirect('/admin/databoxes/?success=0&error=mount-failed'); } } } @@ -717,7 +746,7 @@ class Databox implements ControllerProviderInterface try { $baseId = \collection::mount_collection($databox_id, $collection_id, $user); - if (null == $othCollSel = $request->get("othcollsel")) { + if (null == $othCollSel = $request->request->get("othcollsel")) { $app->abort(400); } @@ -762,21 +791,18 @@ class Databox implements ControllerProviderInterface $app['phraseanet.appbox']->write_databox_pic($databox, $file, \databox::PIC_PDF); unlink($file->getPathname()); - return $app->redirect('/admin/databox/' . $databox_id . '/'); + return $app->redirect('/admin/databox/' . $databox_id . '/?success=1'); } else { - return $app->redirect('/admin/databox/' . $databox_id . '/?upload-logo=too-big'); + return $app->redirect('/admin/databox/' . $databox_id . '/?success=0&error=file-too-big'); } } else { - return $app->redirect('/admin/databox/' . $databox_id . '/?upload-logo=error-send'); + return $app->redirect('/admin/databox/' . $databox_id . '/?success=0&error=file-invalid'); } - } catch (\InvalidArgumentException $e) { - - return $app->redirect('/admin/databox/' . $databox_id . '/?upload-logo=error-invalid'); } catch (\Exception $e) { - return $app->redirect('/admin/databox/' . $databox_id . '/?upload-logo=error'); + return $app->redirect('/admin/databox/' . $databox_id . '/??success=0&error=file-error'); } } @@ -790,22 +816,25 @@ class Databox implements ControllerProviderInterface */ public function deleteLogoPdf(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = ('An error occured'); try { $app['phraseanet.appbox']->write_databox_pic($app['phraseanet.appbox']->get_databox($databox_id), null, \databox::PIC_PDF); $success = true; - $msg = _('forms::operation effectuee OK'); } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg, 'sbas_id' => $databox_id)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'sbas_id' => $databox_id + )); + } + + return $app->redirect('/admin/databox/' . $databox_id . '/?success=' . (int) $success); } /** @@ -818,13 +847,25 @@ class Databox implements ControllerProviderInterface */ public function clearLogs(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); + $success = false; + + try { + $app['phraseanet.appbox']->get_databox($databox_id)->clear_logs(); + $success = true; + } catch (\Exception $e) { + } - $app['phraseanet.appbox']->get_databox($databox_id)->clear_logs(); + if ('json' === $app['request']->getRequestFormat()) { - return $app->json(array('sbas_id' => $databox_id)); + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'sbas_id' => $databox_id + )); + } + + return $app->redirect('/admin/databox/' . $databox_id . '/?success=' . (int) $success); } /** @@ -837,17 +878,29 @@ class Databox implements ControllerProviderInterface */ public function changeViewName(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - - if (null === $viewName = $request->get('viewname')) { + if (null === $viewName = $request->request->get('viewname')) { $app->abort(400, _('Missing view name parameter')); } - $app['phraseanet.appbox']->set_databox_viewname($app['phraseanet.appbox']->get_databox($databox_id), $viewName); + $success = false; - return $app->json(array('sbas_id' => $databox_id)); + try { + $app['phraseanet.appbox']->set_databox_viewname($app['phraseanet.appbox']->get_databox($databox_id), $viewName); + $success = true; + } catch (\Exception $e) { + + } + + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'sbas_id' => $databox_id + )); + } + + return $app->redirect('/admin/databox/' . $databox_id . '/?success=' . (int) $success); } /** @@ -860,24 +913,27 @@ class Databox implements ControllerProviderInterface */ public function unmountDatabase(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - $success = false; - $msg = _('An error occured'); try { $databox = $app['phraseanet.appbox']->get_databox($databox_id); $databox->unmount_databox($app['phraseanet.appbox']); $success = true; - $msg = _('forms::operation effectuee OK'); } catch (\Exception $e) { } - return $app->json(array('success' => $success, 'msg' => $msg, 'sbas_id' => $databox_id)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'sbas_id' => $databox_id + )); + } + + return $app->redirect('/admin/databox/' . $databox_id . '/?success=' . (int) $success . '&reload-tree=1'); } /** @@ -890,11 +946,7 @@ class Databox implements ControllerProviderInterface */ public function emptyDatabase(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); - } - - $message = _('An error occurred'); + $msg = _('An error occurred'); $success = false; try { @@ -903,11 +955,11 @@ class Databox implements ControllerProviderInterface foreach ($databox->get_collections() as $collection) { if ($collection->get_record_amount() <= 500) { $collection->empty_collection(500); - $message = _('Base empty successful'); + $msg = _('Base empty successful'); } else { $settings = "" . $collection->get_base_id() . ""; \task_abstract::create($app['phraseanet.appbox'], 'task_period_emptyColl', $settings); - $message = _('A task has been creted, please run it to complete empty collection'); + $msg = _('A task has been creted, please run it to complete empty collection'); } } @@ -916,7 +968,16 @@ class Databox implements ControllerProviderInterface } - return $app->json(array('success' => $success, 'msg' => $message)); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $msg, + 'sbas_id' => $databox_id + )); + } + + return $app->redirect('/admin/databox/' . $databox_id . '/?success=' . (int) $success); } /** @@ -929,7 +990,7 @@ class Databox implements ControllerProviderInterface */ public function progressBarInfos(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { + if ( ! $app['request']->isXmlHttpRequest() || 'json' !== $app['request']->getRequestFormat()) { $app->abort(400, _('Bad request format, only JSON is allowed')); } @@ -959,7 +1020,7 @@ class Databox implements ControllerProviderInterface $ret['thesaurus_indexed'] = $datas['thesaurus_indexed']; if ($app['phraseanet.core']['file-system']->exists($app['phraseanet.core']['Registry']->get('GV_RootPath') . 'config/minilogos/logopdf_' . $databox_id . '.jpg')) { - $ret['printLogoURL'] = '/print/' . $databox_id; + $ret['printLogoURL'] = '/custom/minilogos/logopdf_' . $databox_id . '.jpg'; } $ret['success'] = true; @@ -996,17 +1057,30 @@ class Databox implements ControllerProviderInterface */ public function setReorder(Application $app, Request $request, $databox_id) { - if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { - $app->abort(400, _('Bad request format, only JSON is allowed')); + $success = false; + + try { + foreach ($request->request->get('order', array()) as $order => $baseId) { + $collection = \collection::get_from_base_id($baseId); + $app['phraseanet.appbox']->set_collection_order($collection, $order); + unset($collection); + } + + $success = true; + } catch (\Exception $e) { + } - foreach ($request->get('order', array()) as $order => $baseId) { - $collection = \collection::get_from_base_id($baseId); - $app['phraseanet.appbox']->set_collection_order($collection, $order); - unset($collection); + if ('json' === $app['request']->getRequestFormat()) { + + return $app->json(array( + 'success' => $success, + 'msg' => $success ? _('forms::operation effectuee OK') : _('An error occured'), + 'sbas_id' => $databox_id + )); } - return $app->json(array('sbas_id' => $databox_id)); + return $app->redirect('/admin/databox/' . $databox_id . '/collections/order?success=' . (int) $success); } /** @@ -1032,7 +1106,7 @@ class Databox implements ControllerProviderInterface */ public function createCollection(Application $app, Request $request, $databox_id) { - if ($name = trim($request->request->get('cnm', '')) === '') { + if (($name = trim($request->request->get('name', ''))) === '') { return $app->redirect('/admin/databox/' . $databox_id . '/collection/error=name'); } @@ -1055,7 +1129,7 @@ class Databox implements ControllerProviderInterface } } - return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/'); + return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=1&reload-tree=1'); } catch (\Exception $e) { return $app->redirect('/admin/databox/' . $databox_id . '/collection/error=error'); @@ -1076,7 +1150,7 @@ class Databox implements ControllerProviderInterface $out = array('total' => array('totobj' => 0, 'totsiz' => 0, 'mega' => '0', 'giga' => '0'), 'result' => array()); - foreach ($databox->get_record_details($request->get('sort')) as $vgrp) { + foreach ($databox->get_record_details($request->query->get('sort')) as $vgrp) { $last_k1 = $last_k2 = null; $outRow = array('midobj' => 0, 'midsiz' => 0); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php b/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php index b3c8f8d125..43daf316a9 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php @@ -11,16 +11,11 @@ namespace Alchemy\Phrasea\Controller\Admin; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Response; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * @@ -122,7 +117,7 @@ class Databoxes implements ControllerProviderInterface } } - switch ($errorMsg = $request->get('error')) { + switch ($errorMsg = $request->query->get('error')) { case 'scheduler-started' : $errorMsg = _('Veuillez arreter le planificateur avant la mise a jour'); break; @@ -147,18 +142,8 @@ class Databoxes implements ControllerProviderInterface case 'no-empty' : $errorMsg = _('Database can not be empty'); break; - } - - switch ($msgSuccess = $request->get('success')) { - case 'restart' : - $msgSuccess = _('N\'oubliez pas de redemarrer le planificateur de taches'); - break; - case 'mount-ok' : - $mountBase = true; - case 'database-ok' : - $createBase = false === $mountBase ? : false; - $msgSuccess = _('The operation completed successfully'); - $user->ACL()->delete_data_from_cache(); + case 'mount-failed' : + $errorMsg = _('Database could not be mounted'); break; } @@ -169,11 +154,8 @@ class Databoxes implements ControllerProviderInterface 'sbas' => $sbas, 'upgrade_available' => $upgradeAvailable, 'error_msg' => $errorMsg, - 'success_msg' => $msgSuccess, 'recommendations' => $upgrader->getRecommendations(), - 'advices' => $request->get('advices', array()), - 'mountBase' => $mountBase, - 'createBase' => $createBase, + 'advices' => $request->query->get('advices', array()), ))); } @@ -188,23 +170,23 @@ class Databoxes implements ControllerProviderInterface { if (\phrasea::is_scheduler_started()) { - return $app->redirect('/admin/databoxes/?error=scheduler-started'); + return $app->redirect('/admin/databoxes/?success=0&error=scheduler-started'); } try { $upgrader = new \Setup_Upgrade($app['phraseanet.appbox']); $advices = $app['phraseanet.appbox']->forceUpgrade($upgrader); - return $app->redirect('/admin/databoxes/?success=restart&' . http_build_query(array('advices' => $advices))); + return $app->redirect('/admin/databoxes/?success=1¬ice=restart&' . http_build_query(array('advices' => $advices))); } catch (\Exception_Setup_UpgradeAlreadyStarted $e) { - return $app->redirect('/admin/databoxes/?error=already-started'); + return $app->redirect('/admin/databoxes/?success=0&error=already-started'); } catch (\Exception_Setup_FixBadEmailAddresses $e) { - return $app->redirect('/admin/databoxes/?error=bad-email'); + return $app->redirect('/admin/databoxes/?success=0&error=bad-email'); } catch (\Exception $e) { - return $app->redirect('/admin/databoxes/?error=unknow'); + return $app->redirect('/admin/databoxes/?success=0&error=unknow'); } } diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Description.php b/lib/Alchemy/Phrasea/Controller/Admin/Description.php index 93b1c91449..fa3b2053ad 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Description.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Description.php @@ -13,11 +13,11 @@ namespace Alchemy\Phrasea\Controller\Admin; use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController; use PHPExiftool\Driver\TagProvider; +use Silex\Application; +use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -use Silex\Application; -use Silex\ControllerProviderInterface; /** * diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Fields.php b/lib/Alchemy/Phrasea/Controller/Admin/Fields.php index 098ff4c7bd..8b2a661170 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Fields.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Fields.php @@ -12,9 +12,9 @@ namespace Alchemy\Phrasea\Controller\Admin; use Alchemy\Phrasea\Application as PhraseaApplication; -use Symfony\Component\HttpFoundation\Request; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\Request; /** * diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Publications.php b/lib/Alchemy/Phrasea/Controller/Admin/Publications.php index 52f2ef22b7..a8aceeda05 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Publications.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Publications.php @@ -12,9 +12,9 @@ namespace Alchemy\Phrasea\Controller\Admin; use Alchemy\Phrasea\Application as PhraseaApplication; -use Symfony\Component\HttpFoundation\Request; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\Request; /** * diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Root.php b/lib/Alchemy/Phrasea/Controller/Admin/Root.php index 7a9a60c9b8..1139317317 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Root.php @@ -11,15 +11,10 @@ namespace Alchemy\Phrasea\Controller\Admin; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * @@ -106,7 +101,7 @@ class Root implements ControllerProviderInterface }) ->bind('admin'); - $controllers->get('/tree/', function() { + $controllers->get('/tree/', function(Application $app, Request $request) { $Core = $app['phraseanet.core']; $appbox = $app['phraseanet.appbox']; $user = $Core->getAuthenticatedUser(); @@ -167,7 +162,7 @@ class Root implements ControllerProviderInterface }) ->bind('admin_display_tree'); - $controllers->get('/test-paths/', function() { + $controllers->get('/test-paths/', function(Application $app, Request $request) { if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { $app->abort(400, _('Bad request format, only JSON is allowed')); @@ -220,6 +215,7 @@ class Root implements ControllerProviderInterface } return new Response($app['twig']->render('admin/structure.html.twig', array( + 'databox' => $databox, 'errors' => $errors, 'structure' => $structure, 'errorsStructure' => $errorsStructure, @@ -262,10 +258,8 @@ class Root implements ControllerProviderInterface $app->abort(403); } - $databox = $app['phraseanet.appbox']->get_databox($databox_id); - return new Response($app['twig']->render('admin/statusbit.html.twig', array( - 'status' => $databox->get_statusbits(), + 'databox'=> $app['phraseanet.appbox']->get_databox($databox_id), ))); }) ->assert('databox_id', '\d+') @@ -370,9 +364,9 @@ class Root implements ControllerProviderInterface \databox_status::deleteIcon($databox_id, $bit, 'on'); } - if (isset($_FILES['image_on']) && $_FILES['image_on']['name']) { + if (null !== $file = $request->files->get('image_on')) { try { - \databox_status::updateIcon($databox_id, $bit, 'on', $_FILES['image_on']); + \databox_status::updateIcon($databox_id, $bit, 'on', $file); } catch (\Exception_Forbidden $e) { return $app->redirect('/admin/statusbit/' . $databox_id . '/status/' . $bit . '/?error=rights'); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Setup.php b/lib/Alchemy/Phrasea/Controller/Admin/Setup.php index 1c7e45ef60..10be9a1266 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Setup.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Setup.php @@ -16,11 +16,11 @@ namespace Alchemy\Phrasea\Controller\Admin; * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Response; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Sphinx.php b/lib/Alchemy/Phrasea/Controller/Admin/Sphinx.php index e4d4615c60..42929749e2 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Sphinx.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Sphinx.php @@ -11,16 +11,11 @@ namespace Alchemy\Phrasea\Controller\Admin; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Response; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * @@ -105,11 +100,11 @@ class Sphinx implements ControllerProviderInterface public function submitConfiguration(Application $app, Request $request) { $app['phraseanet.core']['Registry']->set( - 'sphinx_charset_tables', $request->get('charset_tables', array()), \registry::TYPE_ARRAY + 'sphinx_charset_tables', $request->request->get('charset_tables', array()), \registry::TYPE_ARRAY ); $app['phraseanet.core']['Registry']->set( - 'sphinx_user_stemmer', $request->get('libstemmer', array()), \registry::TYPE_ARRAY + 'sphinx_user_stemmer', $request->request->get('libstemmer', array()), \registry::TYPE_ARRAY ); return $app->redirect('/admin/sphinx/configuration/?update=ok'); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Subdefs.php b/lib/Alchemy/Phrasea/Controller/Admin/Subdefs.php index 6ab41d5c49..3344e5bdc6 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Subdefs.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Subdefs.php @@ -11,10 +11,10 @@ namespace Alchemy\Phrasea\Controller\Admin; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index 34c9b9edae..948cc32bf5 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -11,11 +11,11 @@ namespace Alchemy\Phrasea\Controller\Admin; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; +use Alchemy\Phrasea\Helper\User as UserHelper; use Silex\Application; use Silex\ControllerProviderInterface; -use Alchemy\Phrasea\Helper\User as UserHelper; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * @@ -415,7 +415,7 @@ class Users implements ControllerProviderInterface $templates = $deny = $accept = $options = array(); - foreach ($request->get('template', array()) as $tmp) { + foreach ($request->request->get('template', array()) as $tmp) { if (trim($tmp) != '') { $tmp = explode('_', $tmp); @@ -425,14 +425,14 @@ class Users implements ControllerProviderInterface } } - foreach ($request->get('deny', array()) as $den) { + foreach ($request->request->get('deny', array()) as $den) { $den = explode('_', $den); if (count($den) == 2 && ! isset($templates[$den[0]])) { $deny[$den[0]][$den[1]] = $den[1]; } } - foreach ($request->get('accept', array()) as $acc) { + foreach ($request->request->get('accept', array()) as $acc) { $acc = explode('_', $acc); if (count($acc) == 2 && ! isset($templates[$acc[0]])) { $accept[$acc[0]][$acc[1]] = $acc[1]; @@ -440,14 +440,14 @@ class Users implements ControllerProviderInterface } } - foreach ($request->get('accept_hd', array()) as $accHD) { + foreach ($request->request->get('accept_hd', array()) as $accHD) { $accHD = explode('_', $accHD); if (count($accHD) == 2 && isset($accept[$accHD[0]]) && isset($options[$accHD[0]][$accHD[1]])) { $options[$accHD[0]][$accHD[1]]['HD'] = true; } } - foreach ($request->get('watermark', array()) as $wm) { + foreach ($request->request->get('watermark', array()) as $wm) { $wm = explode('_', $wm); if (count($wm) == 2 && isset($accept[$wm[0]]) && isset($options[$wm[0]][$wm[1]])) { $options[$wm[0]][$wm[1]]['WM'] = true; @@ -574,7 +574,7 @@ class Users implements ControllerProviderInterface } } - return $app->redirect('/admin/users/demands/?demands=ok'); + return $app->redirect('/admin/users/demands/?success=1'); }) ->bind('users_submit_demands'); @@ -587,14 +587,14 @@ class Users implements ControllerProviderInterface $controllers->post('/import/file/', function(Application $app, Request $request) { $user = $app['phraseanet.core']->getAuthenticatedUser(); - if ((null === $file = $request->files->get('file')) || ! $file->isValid()) { + if ((null === $file = $request->files->get('files')) || ! $file->isValid()) { - return $app->rediretc('/admin/import/file/?error=file'); + return $app->redirect('/admin/users/import/file/?error=file-invalid'); } $array = \format::csv_to_arr($file->getPathname()); - $equivalenceToMysqlField = $this->getEquivalenceToMysqlField(); + $equivalenceToMysqlField = Users::getEquivalenceToMysqlField(); $loginDefined = $pwdDefined = false; $loginNew = array(); $out = array('ignored_row' => array(), 'errors' => array()); @@ -724,11 +724,11 @@ class Users implements ControllerProviderInterface $nbCreation = 0; $user = $app['phraseanet.core']->getAuthenticatedUser(); - if ((null === $serializedArray = $request->get('sr')) || ('' === $serializedArray)) { + if ((null === $serializedArray = $request->request->get('sr')) || ('' === $serializedArray)) { $app->abort(400); } - if (null === $model = $request->get("modelToAplly")) { + if (null === $model = $request->request->get("modelToAplly")) { $app->abort(400); } @@ -737,7 +737,7 @@ class Users implements ControllerProviderInterface $nbLines = sizeof($array); $nbCols = sizeof($array[0]); - $equivalenceToMysqlField = $this->getEquivalenceToMysqlField(); + $equivalenceToMysqlField = Users::getEquivalenceToMysqlField(); for ($i = 1; $i < $nbLines; $i ++ ) { $curUser = null; @@ -843,7 +843,7 @@ class Users implements ControllerProviderInterface return $controllers; } - private function getEquivalenceToMysqlField() + public static function getEquivalenceToMysqlField() { $equivalenceToMysqlField = array(); diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index c8bf6a6615..d19836c3b5 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -153,7 +153,7 @@ class Installer implements ControllerProviderInterface $appbox_name = $request->get('ab_name'); $databox_name = $request->get('db_name'); $setupRegistry = new \Setup_Registry(); - + try { $conn = new \connection_pdo('appbox', $hostname, $port, $user_ab, $password, $appbox_name, array(), $setupRegistry); } catch (\Exception $e) { @@ -220,7 +220,7 @@ class Installer implements ControllerProviderInterface $registry->set('GV_mp4box', $request->request->get('binary_MP4Box'), \registry::TYPE_STRING); $registry->set('GV_pdftotext', $request->request->get('binary_xpdf'), \registry::TYPE_STRING); - $user = \User_Adapter::create($appbox, $request->request->get('email'), $request->request->get('password'), $request->query->get('email'), true); + $user = \User_Adapter::create($appbox, $request->request->get('email'), $request->request->get('password'), $request->request->get('email'), true); \phrasea::start($app['phraseanet.core']); @@ -229,7 +229,7 @@ class Installer implements ControllerProviderInterface $appbox->get_session()->authenticate($auth); if ($databox_name && ! \p4string::hasAccent($databox_name)) { - $template = new \SplFileInfo(__DIR__ . '/../../../../conf.d/data_templates/' . $request->query->get('db_template') . '.xml'); + $template = new \SplFileInfo(__DIR__ . '/../../../../conf.d/data_templates/' . $request->request->get('db_template') . '.xml'); $databox = \databox::create($appbox, $connbas, $template, $registry); $user->ACL() ->give_access_to_sbas(array($databox->get_sbas_id())) diff --git a/lib/classes/appbox.class.php b/lib/classes/appbox.class.php index 7de473eccb..9230ee397e 100644 --- a/lib/classes/appbox.class.php +++ b/lib/classes/appbox.class.php @@ -103,23 +103,43 @@ class appbox extends base if ( ! in_array(mb_strtolower($pathfile->getMimeType()), array('image/gif', 'image/png', 'image/jpeg', 'image/jpg', 'image/pjpeg'))) { throw new \InvalidArgumentException('Invalid file format'); } + $filename = $pathfile->getPathname(); - //resize collection logo - $imageSpec = new ImageSpecification(); - $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO); - $imageSpec->setDimensions(120, 24); + if ($pic_type === collection::PIC_LOGO) { + //resize collection logo + $imageSpec = new ImageSpecification(); + $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO); + $imageSpec->setDimensions(120, 24); - $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg'; + $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg'; - try { - $core['media-alchemyst'] - ->open($pathfile->getPathname()) - ->turninto($tmp, $imageSpec) - ->close(); - $filename = $tmp; - } catch (\MediaAlchemyst\Exception $e) { + try { + $core['media-alchemyst'] + ->open($pathfile->getPathname()) + ->turninto($tmp, $imageSpec) + ->close(); + $filename = $tmp; + } catch (\MediaAlchemyst\Exception $e) { + } + } else if ($pic_type === collection::PIC_PRESENTATION) { + //resize collection logo + $imageSpec = new ImageSpecification(); + $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO); + $imageSpec->setDimensions(650, 200); + + $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg'; + + try { + $core['media-alchemyst'] + ->open($pathfile->getPathname()) + ->turninto($tmp, $imageSpec) + ->close(); + $filename = $tmp; + } catch (\MediaAlchemyst\Exception $e) { + + } } } @@ -148,7 +168,9 @@ class appbox extends base $custom_path = $registry->get('GV_RootPath') . 'www/custom/' . $pic_type . '/' . $collection->get_base_id(); foreach (array($file, $custom_path) as $target) { + if (is_file($target)) { + $core['file-system']->remove($target); } diff --git a/lib/classes/databox/status.class.php b/lib/classes/databox/status.class.php index e2b4e5d93f..82afde938e 100644 --- a/lib/classes/databox/status.class.php +++ b/lib/classes/databox/status.class.php @@ -435,7 +435,7 @@ class databox_status throw new Exception_Upload_FileTooBig(); } - if ($file->isValid()) { + if ( ! $file->isValid()) { throw new Exception_Upload_Error(); } @@ -444,11 +444,12 @@ class databox_status $name = "-stat_" . $bit . "_" . ($switch == 'on' ? '1' : '0') . ".gif"; try { - $file->move($path, $name); + $file = $file->move($registry->get('GV_RootPath') . "config/status/", $path.$name); } catch (FileException $e) { throw new Exception_Upload_CannotWriteFile(); } + $custom_path = $registry->get('GV_RootPath') . 'www/custom/status/'; $core['file-system']->mkdir($custom_path, 0750); diff --git a/templates/web/admin/collection/collection.html.twig b/templates/web/admin/collection/collection.html.twig index 1322e7c24f..ac21270f93 100644 --- a/templates/web/admin/collection/collection.html.twig +++ b/templates/web/admin/collection/collection.html.twig @@ -1,3 +1,10 @@ +{% if reloadTree %} + +{% endif %} + +{% set bas_id = collection.get_base_id() %} -{% if app.request.get('operation') == 'ok' %} -
- × - {% trans 'forms::operation effectuee OK' %} -
+{% if app.request.query.get('success') == '1' %} +
+ × + {% trans 'forms::operation effectuee OK' %} +
+{% elseif app.request.query.get('success') == '0' %} +
+ × + {% trans 'An error occured' %} + {% if errorMsg is not none %} + {{ errorMsg }} + {% endif %} +
{% endif %} -{% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} +{% if user.ACL.has_right_on_base(bas_id, 'manage') %}
{% trans 'admin::collection:: Gestionnaires des commandes' %}
-
+ {% if admins | length > 0 %}
    {% for user in admins %} @@ -48,7 +63,7 @@
    {% trans 'admin::collection:: presentation des elements lors de la diffusion aux utilisateurs externes (publications)' %}
    - +
    {% endif %} +{# mini logo #}
    {% trans 'admin::base:collection: minilogo actuel' %}
    - {% if collection.getLogo(app.request.get('bas_id')) is not empty %} -
    {{ collection.getLogo(app.request.get('bas_id')) | raw }}
    - {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} -
    - + {% if collection.getLogo(bas_id) is not empty %} +
    {{ collection.getLogo(bas_id) | raw }}
    + {% if user.ACL.has_right_on_base(bas_id, 'manage') %} + +
    {% endif%} - {% elseif user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} + {% elseif user.ACL.has_right_on_base(bas_id, 'manage') %} {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} -
    + - {% trans 'boutton::envoyer' %}
    {% endif %}
    +{# watermark #}
    -
    Watermark
    - {% if collection.getWatermark(app.request.get('bas_id')) is not empty %} -
    {{ collection.getWatermark(app.request.get('bas_id'))| raw }}
    - {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} -
    - +
    {% trans "Watermark" %}
    + {% if collection.getWatermark(bas_id) is not empty %} +
    {{ collection.getWatermark(bas_id)| raw }}
    + {% if user.ACL.has_right_on_base(bas_id, 'manage') %} + +
    {% endif%} - {% elseif user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} + {% elseif user.ACL.has_right_on_base(bas_id, 'manage') %} {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} -
    + - {% trans 'boutton::envoyer' %}
    {% endif %}
    +{# stamp logo #}
    -
    StampLogo
    - {% if collection.getStamp(app.request.get('bas_id')) is not empty %} -
    {{ collection.getStamp(app.request.get('bas_id'))| raw }}
    - {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} -
    - +
    {% trans "Stamp logo" %}
    + {% if collection.getStamp(bas_id) is not empty %} +
    {{ collection.getStamp(bas_id)| raw }}
    + {% if user.ACL.has_right_on_base(bas_id, 'manage') %} + +
    {% endif%} - {% elseif user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} + {% elseif user.ACL.has_right_on_base(bas_id, 'manage') %} {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} -
    + - {% trans 'boutton::envoyer' %}
    {% endif %}
    +{# Bandeau de présentation #}
    {% trans 'admin::base:collection: image de presentation : ' %}
    - {% if collection.getPresentation(app.request.get('bas_id')) is not empty %} -
    {{ collection.getPresentation(app.request.get('bas_id'))| raw }}
    - {% if user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} -
    - + {% if collection.getPresentation(bas_id) is not empty %} +
    {{ collection.getPresentation(bas_id)| raw }}
    + {% if user.ACL.has_right_on_base(bas_id, 'manage') %} + +
    {% endif%} - {% elseif user.ACL.has_right_on_base(app.request.get('bas_id'), 'manage') %} + {% elseif user.ACL.has_right_on_base(bas_id, 'manage') %} {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} -
    + - {% trans 'boutton::envoyer' %} - (max : 650x200)
    {% endif %}
    @@ -189,7 +203,7 @@ $(document).ready(function(){ //add admins $( ".admin_adder" ).autocomplete({ - source: "/admin/users/typeahead/search/?have_not_right[]=order_master&on_base[]={{ app.request.get('bas_id') }}", + source: "/admin/users/typeahead/search/?have_not_right[]=order_master&on_base[]={{ bas_id }}", minLength: 2, select: function( event, ui ) { var form = $('#admin_adder'); @@ -232,7 +246,7 @@ }); }); - $("div.right a.submiter").bind("click", function() { + $("div.right .submiter").bind("click", function() { var $this = $(this); var form = $this.closest('form'); @@ -246,28 +260,60 @@ }); function submitForm(submitLink, form) { + + form.bind('submit', function() { + return false; + }); + $.ajax({ dataType: 'json', type: form.attr('method'), url: form.attr('action'), data: form.serializeArray(), + beforeSend : function() { + submitLink.attr('disabled', true).addClass('disabled'); + }, success: function(datas) { if(datas.success) { if(submitLink.hasClass('reload')) { - parent.reloadTree('base:{{ app.request.get('bas_id') }}'); - } else { - p4.Mustache.Render('Alert-Success', {content:datas.msg}, function(html){ - $this.closest('.action-block').prepend(html); - }); + parent.reloadTree('base:{{ collection.get_sbas_id() }}'); } - } else { - p4.Mustache.Render('Alert-Error', {content:datas.msg}, function(html){ - $this.closest('.action-block').prepend(html); - }); + alert(datas.msg); } + }, + complete: function() { + submitLink.attr('disabled', false).removeClass('disabled'); } }); } + + $('.fileupload').each(function () { + $(this).fileupload({ + dataType: 'html', + add: function(e, data) { + if( ! /(\.|\/)(png|jpeg|jpg|pjpg|gif)$/i.test(data.files[0].type)) { + {% set supported_file_types = ['jpg', 'jpeg', 'pjpg', 'gif', 'png']|join(' | ') %} + alert("{% trans %} Invalid file type, only ({{ supported_file_types }}) file formats are supported {% endtrans %}"); + + return false; + } + + data.submit(); + }, + submit: function(e, data) { + $('#right-ajax').empty().addClass('loading'); + }, + done: function (e, data) { + $('#right-ajax').removeClass('loading').html(data.result); + enableForms($('#right-ajax form:not(.no-ajax)')); + + $.each($('#right-ajax a'),function(i, el){ + enableLink($(el)); + }); + } + }); + }); + }); \ No newline at end of file diff --git a/templates/web/admin/collection/reorder.html.twig b/templates/web/admin/collection/reorder.html.twig index 67e3ae391f..fdb987de95 100644 --- a/templates/web/admin/collection/reorder.html.twig +++ b/templates/web/admin/collection/reorder.html.twig @@ -62,7 +62,7 @@ dataType:'json', type:'POST', data: {order: order}, - url: '{{ path('admin_database_submit_collections_order', {'databox_id': app.request.get('databox_id')}) }}', + url: '{{ path('admin_database_submit_collections_order', {'databox_id': app.request.attributes.get('databox_id')}) }}', beforeSend : function() { $this.attr('disabled', true); }, diff --git a/templates/web/admin/collection/suggested_value.html.twig b/templates/web/admin/collection/suggested_value.html.twig index 8a83b99c04..47a0cf2e16 100644 --- a/templates/web/admin/collection/suggested_value.html.twig +++ b/templates/web/admin/collection/suggested_value.html.twig @@ -13,6 +13,19 @@

    {% trans 'Suggested values' %}

+ +{% if app.request.query.get('success') == '1' %} +
+ × + {% trans 'forms::operation effectuee OK' %} +
+{% elseif app.request.query.get('success') == '0' %} +
+ × + {% trans 'An error occured' %} +
+{% endif %} +
@@ -39,7 +52,7 @@ @@ -123,7 +135,7 @@
- {% trans 'admin::sugval: Valeurs suggerees/Preferences de la collection' %} {{ app.request.get('bas_id')|bas_names }} + {% trans 'admin::sugval: Valeurs suggerees/Preferences de la collection' %} {{ app.request.attributes.get('bas_id')|bas_names }} @@ -86,8 +99,7 @@
- +
-
+
diff --git a/templates/web/admin/databases.html.twig b/templates/web/admin/databases.html.twig index ca95c846fd..6c71211b63 100644 --- a/templates/web/admin/databases.html.twig +++ b/templates/web/admin/databases.html.twig @@ -1,23 +1,22 @@ - - - -{% if success_msg is not none %} -
- {{ success_msg }} +{% if app.request.query.get('success') == '1' %} +
+ × + {% trans 'forms::operation effectuee OK' %} +
+{% elseif app.request.query.get('success') == '0' %} +
+ × + {% trans 'An error occured' %} + {% if error_msg is not none %} + {{ error_msg }} + {% endif %}
{% endif %} -{% if error_msg is not none %} -
- {{ error_msg }} +{% if app.request.query.get('notice') == 'restart' %} +
+ × + {% trans 'N\'oubliez pas de redemarrer le planificateur de taches' %}
{% endif %} diff --git a/templates/web/admin/databox/cgus.html.twig b/templates/web/admin/databox/cgus.html.twig index 89b390d1ab..d79cd57db2 100644 --- a/templates/web/admin/databox/cgus.html.twig +++ b/templates/web/admin/databox/cgus.html.twig @@ -1,8 +1,8 @@

{% trans'Terms Of Use' %}

-
+
- +
@@ -69,7 +91,7 @@
@@ -78,9 +100,9 @@ @@ -176,31 +199,20 @@

{% trans "admin::base: logo impression PDF" %}

- {% if uploadErrorLogoMsg is not none %} -
- × - {{ uploadErrorLogoMsg }} -
- {% endif %}
- + {% if user.ACL().has_right_on_sbas(databox.get_sbas_id(), "bas_manage") %} -
- - {% trans "admin::base:collection: supprimer le logo" %} - + +
{% endif %}
{% trans "admin::base:collection: aucun fichier (minilogo, watermark ...)" %} -
{% if user.ACL().has_right_on_sbas(databox.get_sbas_id(), "bas_manage") %} - - + {% trans "admin::base: envoyer un logo (jpeg 35px de hauteur max)" %} {% endif %} -
@@ -262,7 +274,13 @@ url: form.attr('action'), data: form.serializeArray(), success: function(datas) { - + if(datas.success) { + if(submitLink.hasClass('reload')) { + parent.reloadTree('base:{{ databox.get_sbas_id() }}'); + } + } else { + alert(datas.msg); + } } }); }); @@ -279,7 +297,9 @@ $("#mount-coll").toggle(); }); - $("div.right a.submiter").bind("click", function() { + console.log($("div.right .submiter")); + + $("div.right .submiter").bind("click", function() { var $this = $(this); var form = $this.closest('form'); @@ -293,30 +313,62 @@ }); function submitForm(submitLink, form) { + + form.bind('submit', function(){ + return false; + }); + $.ajax({ dataType: 'json', type: form.attr('method'), url: form.attr('action'), data: form.serializeArray(), + before : function() { + submitLink.attr('disabled', true).addClass('disabled'); + }, success: function(datas) { if(datas.success) { if(submitLink.hasClass('reload')) { - parent.reloadTree('base:{{ app.request.get('bas_id') }}'); - } else { - p4.Mustache.Render('Alert-Success', {content:datas.msg}, function(html){ - $this.closest('.action-block').prepend(html); - }); + parent.reloadTree('base:{{ databox.get_sbas_id() }}'); } - } else { - p4.Mustache.Render('Alert-Error', {content:datas.msg}, function(html){ - $this.closest('.action-block').prepend(html); - }); + alert(datas.msg); } + }, + complete: function() { + submitLink.attr('disabled', false).removeClass('disabled'); } }); } setTimeout("refreshDatabaseInformations();", 6000); + + + + $('#fileupload').fileupload({ + dataType: 'html', + add: function(e, data) { + if( ! /(\.|\/)(jpe?g)$/i.test(data.files[0].type)) { + {% set supported_file_types = ['jpg']|join(' | ') %} + alert("{% trans %} Invalid file type, only ({{ supported_file_types }}) file formats are supported {% endtrans %}"); + + return false; + } + + data.submit(); + }, + submit: function(e, data) { + $('#right-ajax').empty().addClass('loading'); + }, + done: function (e, data) { + $('#right-ajax').removeClass('loading').html(data.result); + enableForms($('#right-ajax form:not(.no-ajax)')); + + $.each($('#right-ajax a'),function(i, el){ + enableLink($(el)); + }); + } + }); }); + \ No newline at end of file diff --git a/templates/web/admin/databox/details.html.twig b/templates/web/admin/databox/details.html.twig index 6dc5804134..fe60f4805c 100644 --- a/templates/web/admin/databox/details.html.twig +++ b/templates/web/admin/databox/details.html.twig @@ -6,14 +6,14 @@ - {% if app.request.get('sort') == 'col' %} + {% if app.request.query.get('sort') == 'col' %} {% endif %} {% trans 'phraseanet:: collection' %} - {% if app.request.get('sort') == 'obj' %} + {% if app.request.query.get('sort') == 'obj' %} {% endif %} {% trans 'admin::base: objet' %} diff --git a/templates/web/admin/index.html.twig b/templates/web/admin/index.html.twig index a2d751097e..d68a4cf047 100644 --- a/templates/web/admin/index.html.twig +++ b/templates/web/admin/index.html.twig @@ -80,6 +80,60 @@ }) }; + function enableForms(forms) { + forms.bind('submit', function(){ + + var method = $(this).attr('method'); + var url = $(this).attr('action'); + var datas = $(this).serializeArray(); + + if(!method) { + method = 'GET'; + } + $('#right-ajax').empty().addClass('loading'); + if(url) { + $.ajax({ + type: method, + url: url, + data: datas, + success: function(datas){ + $('#right-ajax').removeClass('loading').html(datas); + enableForms($('#right-ajax form:not(.no-ajax)')); + + $.each($('#right-ajax a'),function(i, el){ + enableLink($(el)); + }); + return; + } + }); + return false; + } + }); + } + + function enableLink(link) { + + $(link).bind('click',function(event){ + + var dest = link.attr('href'); + + if(dest && dest.indexOf('#') !== 0) { + $('#right-ajax').empty().addClass('loading').parent().show(); + $('#right').hide(); + + $.get(dest, function(data) { + $('#right-ajax').removeClass('loading').html(data); + enableForms($('#right-ajax form:not(.no-ajax)')); + $.each($('#right-ajax a'),function(i, el){ + enableLink($(el)); + }); + }); + return false; + } + + }); + } + function activeTree(click) { $('#FNDR').treeview({ @@ -87,61 +141,6 @@ animated: "medium" }); - - function enableForms(forms) { - forms.bind('submit', function(){ - - var method = $(this).attr('method'); - var url = $(this).attr('action'); - var datas = $(this).serializeArray(); - - if(!method) { - method = 'GET'; - } - $('#right-ajax').empty().addClass('loading'); - if(url) { - $.ajax({ - type: method, - url: url, - data: datas, - success: function(datas){ - $('#right-ajax').removeClass('loading').html(datas); - enableForms($('#right-ajax form:not(.no-ajax)')); - - $.each($('#right-ajax a'),function(i, el){ - enableLink($(el)); - }); - return; - } - }); - return false; - } - }); - } - - function enableLink(link) { - - $(link).bind('click',function(event){ - - var dest = link.attr('href'); - - if(dest && dest.indexOf('#') !== 0) { - $('#right-ajax').empty().addClass('loading').parent().show(); - $('#right').hide(); - - $.get(dest, function(data) { - $('#right-ajax').removeClass('loading').html(data); - enableForms($('#right-ajax form:not(.no-ajax)')); - $.each($('#right-ajax a'),function(i, el){ - enableLink($(el)); - }); - }); - return false; - } - - }); - } - $.each($('#tree a[target=right]'),function(){ var dest = $(this).attr('href'); @@ -181,6 +180,7 @@ $('.zone_online_users').trigger('click'); } } + $(document).ready( function(){ resize(); @@ -189,10 +189,6 @@ } ); - function refreshBaskets() - { - return; - } function resize() { $('#right').height($(this).height()-$('#mainMenu').height()-20); diff --git a/templates/web/admin/statusbit.html.twig b/templates/web/admin/statusbit.html.twig index 555aab1da7..39f60a0312 100644 --- a/templates/web/admin/statusbit.html.twig +++ b/templates/web/admin/statusbit.html.twig @@ -1,3 +1,6 @@ +{% set status = databox.get_statusbits() %} +{% set databox_id = databox.get_sbas_id() %} +

{% trans 'phraseanet::status bit' %}

@@ -20,18 +23,18 @@ {% if attribute(status, bit) is defined %} - + -
+
{% else %} - + diff --git a/templates/web/admin/statusbit/edit.html.twig b/templates/web/admin/statusbit/edit.html.twig index a30465cc96..0c3a27064c 100644 --- a/templates/web/admin/statusbit/edit.html.twig +++ b/templates/web/admin/statusbit/edit.html.twig @@ -7,7 +7,7 @@

{% trans 'status:: numero de bit' %} {{ app.request.get('bit') }}

-
+
+ + \ No newline at end of file diff --git a/templates/web/admin/structure.html.twig b/templates/web/admin/structure.html.twig index 7845ad0c55..028b1cb468 100644 --- a/templates/web/admin/structure.html.twig +++ b/templates/web/admin/structure.html.twig @@ -27,7 +27,7 @@

{% trans 'admin::base: structure' %}

-
+
diff --git a/templates/web/admin/user/demand.html.twig b/templates/web/admin/user/demand.html.twig index 9105a9c64c..79cd8011c4 100644 --- a/templates/web/admin/user/demand.html.twig +++ b/templates/web/admin/user/demand.html.twig @@ -105,7 +105,7 @@

{% trans 'admin:: demandes en cours' %}

-{% if app.request.get('demands') == 'ok' %} +{% if app.request.query.get('success') == '1' %}
× {% trans 'Requests for the application registrations were recorded successfully' %} diff --git a/templates/web/admin/user/import/file.html.twig b/templates/web/admin/user/import/file.html.twig index d742745b64..24a0c0025b 100644 --- a/templates/web/admin/user/import/file.html.twig +++ b/templates/web/admin/user/import/file.html.twig @@ -2,11 +2,11 @@

{% trans 'Upload a "csv" file for users creation' %}

-{% if app.request.get('error') is not none %} - {% set error = app.request.get('error') %} +{% if app.request.query.get('error') is not none %} + {% set error = app.request.query.get('error') %}
- {% if error == 'file' %} + {% if error == 'file-invalid' %} {% trans 'An error occured while upload the file. Please retry' %} {% elseif error == 'row-login' %} {% trans 'Row "login" is missing, script has stopped' %} @@ -37,11 +37,39 @@ {% trans 'You can download the documentation here' %}
- - {% trans "User's file " %} : -
- - {% trans 'boutton::retour' %} -
-
-
\ No newline at end of file + + + {% trans 'Select a file' %} + + + {% trans 'boutton::retour' %} +
+ + \ No newline at end of file diff --git a/templates/web/admin/users.html.twig b/templates/web/admin/users.html.twig index 30018642ae..c4e497f29f 100644 --- a/templates/web/admin/users.html.twig +++ b/templates/web/admin/users.html.twig @@ -3,7 +3,7 @@ {% block content %} -{% if app.request.get('user-updated') is not none%} +{% if app.request.query.get('user-updated') is not none%}
{% set user_count = app.request.get('user-updated') %} diff --git a/tests/Alchemy/Phrasea/Controller/Admin/AdminCollectionTest.php b/tests/Alchemy/Phrasea/Controller/Admin/AdminCollectionTest.php index b08b1f165a..73544638de 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/AdminCollectionTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/AdminCollectionTest.php @@ -150,13 +150,14 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract /** * @covers Alchemy\Phrasea\Controller\Admin\Bas::submitSuggestedValues - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ - public function testPostSuggestedValuesBadRequest() + public function testPostSuggestedValuesNotJson() { $this->setAdmin(true); $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/suggested-values/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -210,13 +211,14 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract /** * @covers Alchemy\Phrasea\Controller\Admin\Bas::enable - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ - public function testPostEnableBadRequest() + public function testPostEnableNotJson() { $this->setAdmin(true); $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/enable/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -248,14 +250,15 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::disabled */ - public function testPostDisabledBadRequest() + public function testPostDisabledNotJson() { $this->setAdmin(true); $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/disabled/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -307,20 +310,23 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'admins' => array(self::$user_alt1->get_id()) )); - $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/'); $this->assertTrue(self::$user_alt1->ACL()->has_right_on_base(self::$collection->get_base_id(), 'order_master')); } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay */ - public function testPostPublicationDisplayBadRequest() + public function testPostPublicationDisplayNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/publication/display/'); + $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/publication/display/', array( + 'pub_wm' => 'wm', + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -364,14 +370,19 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::rename */ - public function testPostNameBadRequest() + public function testPostNameNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/rename/'); + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/collection/' . $collection->get_base_id() . '/rename/', array( + 'name' => 'test_rename_coll' + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -417,14 +428,17 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::emptyCollection */ - public function testPostEmptyCollectionBadRequestFormat() + public function testPostEmptyCollectionNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/empty/'); + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/collection/' . $collection->get_base_id() . '/empty/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -581,19 +595,22 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'newLogo' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') ); $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/picture/mini-logo/', array(), $files); - $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?success=1'); $this->assertEquals(1, count(\collection::getLogo(self::$collection->get_base_id()))); } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteLogo */ - public function testDeleteMiniLogoBadRequestFormat() + public function testDeleteMiniLogoNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/picture/mini-logo/delete/'); + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/collection/' . $collection->get_base_id() . '/picture/mini-logo/delete/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -627,19 +644,22 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'newWm' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') ); $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/picture/watermark/', array(), $files); - $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?success=1'); $this->assertEquals(1, count(\collection::getWatermark(self::$collection->get_base_id()))); } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteWatermark */ - public function testDeleteWmBadRequestFormat() + public function testDeleteWmBadNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/picture/watermark/delete/'); + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/collection/' . $collection->get_base_id() . '/picture/watermark/delete/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -673,19 +693,22 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'newStamp' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') ); $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/picture/stamp-logo/', array(), $files); - $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?success=1'); $this->assertEquals(1, count(\collection::getStamp(self::$collection->get_base_id()))); } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteStamp */ - public function testDeleteStampBadRequestFormat() + public function testDeleteStampBadNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/picture/stamp-logo/delete/'); + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/collection/' .$collection->get_base_id() . '/picture/stamp-logo/delete/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -720,19 +743,22 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'newBanner' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') ); $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/picture/banner/', array(), $files); - $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?operation=ok'); + $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?success=1'); $this->assertEquals(1, count(\collection::getPresentation(self::$collection->get_base_id()))); } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteBanner */ - public function testDeleteBannerBadRequestFormat() + public function testDeleteBannerNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/picture/banner/delete/'); + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/collection/' . $collection->get_base_id() . '/picture/banner/delete/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -788,14 +814,17 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::delete */ - public function testDeleteCollectionBadRequestFormat() + public function testDeleteCollectionNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/delete/'); + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/collection/' . $collection->get_base_id() . '/delete/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -854,14 +883,17 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::unmount */ - public function testPostUnmountCollectionBadRequestFormat() + public function testPostUnmountCollectionNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/collection/' . self::$collection->get_base_id() . '/unmount/'); + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/collection/' . $collection->get_base_id() . '/unmount/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** diff --git a/tests/Alchemy/Phrasea/Controller/Admin/DataboxTest.php b/tests/Alchemy/Phrasea/Controller/Admin/DataboxTest.php index fc82e99160..78a2648e0d 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/DataboxTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/DataboxTest.php @@ -276,11 +276,18 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract /** * @covers \Alchemy\Phrasea\Controller\Admin\Database::updateDatabaseCGU - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ - public function testUpdateDatabaseCGUBadRequestFormat() + public function testUpdateDatabaseCGNotJson() { - $this->client->request('POST', '/databox/' . self::$collection->get_sbas_id() . '/cgus/'); + $this->setAdmin(true); + + $collection = $this->createOneCollection(); + + $this->client->request('POST', '/databox/' . $collection->get_sbas_id() . '/cgus/', array( + 'TOU' => array('fr_FR' => 'Test update CGUS') + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -301,7 +308,7 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'TOU' => array('fr_FR' => $cgusUpdate) )); - $this->checkRedirection($this->client->getResponse(), '/admin/databox/' . self::$collection->get_sbas_id() . '/cgus/'); + $this->checkRedirection($this->client->getResponse(), '/admin/databox/' . self::$collection->get_sbas_id() . '/cgus/?success=1'); $databox = $this->app['phraseanet.appbox']->get_databox(self::$collection->get_sbas_id()); $cgus = $databox->get_cgus(); @@ -318,7 +325,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->setAdmin(true); $this->client->request('GET', '/databox/' . self::$collection->get_sbas_id() . '/informations/documents/'); - $this->assertTrue($this->client->getResponse()->isOk()); } /** @@ -431,14 +437,17 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers \Alchemy\Phrasea\Controller\Admin\Database::reindex */ - public function testPostReindexBadRequestFormat() + public function testPostReindexNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/databox/' . self::$collection->get_sbas_id() . '/reindex/'); + $collection = $this->createOnecollection(); + + $this->client->request('POST', '/databox/' . $collection->get_sbas_id() . '/reindex/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -458,14 +467,17 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers \Alchemy\Phrasea\Controller\Admin\Database::setIndexable */ - public function testPostIndexableBadRequestFormat() + public function testPostIndexableNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/databox/' . self::$collection->get_sbas_id() . '/reindex/'); + $collection = $this->createOnecollection(); + + $this->client->request('POST', '/databox/' . $collection->get_sbas_id() . '/indexable/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -490,14 +502,17 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers \Alchemy\Phrasea\Controller\Admin\Database::clearLogs */ - public function testPostClearLogBadRequestFormat() + public function testPostClearLogNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/databox/' . self::$collection->get_sbas_id() . '/clear-logs/'); + $collection = $this->createOnecollection(); + + $this->client->request('POST', '/databox/' . $collection->get_sbas_id() . '/clear-logs/'); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -518,14 +533,19 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers \Alchemy\Phrasea\Controller\Admin\Database::changeViewName */ - public function testChangeViewBadRequestFormat() + public function testChangeViewNotJson() { $this->setAdmin(true); - $this->client->request('POST', '/databox/' . self::$collection->get_sbas_id() . '/view-name/'); + $collection = $this->createOnecollection(); + + $this->client->request('POST', '/databox/' . $collection->get_sbas_id() . '/view-name/', array( + 'viewname' => 'hello' + )); + + $this->assertTrue($this->client->getResponse()->isRedirect()); } /** @@ -574,7 +594,7 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $response = $this->client->getResponse(); $this->assertTrue($response->isRedirect()); - $this->assertEquals('/admin/databases/?error=no-empty', $response->headers->get('location')); + $this->assertEquals('/admin/databoxes/?error=no-empty', $response->headers->get('location')); } /** @@ -590,7 +610,7 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $response = $this->client->getResponse(); $this->assertTrue($response->isRedirect()); - $this->assertEquals('/admin/databases/?error=special-chars', $response->headers->get('location')); + $this->assertEquals('/admin/databoxes/?error=special-chars', $response->headers->get('location')); } /** @@ -622,8 +642,9 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $response = $this->client->getResponse(); $this->assertTrue($response->isRedirect()); $uriRedirect = $response->headers->get('location'); - $this->assertTrue( ! ! strrpos($uriRedirect, 'success=base-ok')); - $databoxId = array_pop(explode('=', array_pop(explode('&', $uriRedirect)))); + $this->assertTrue( ! ! strrpos($uriRedirect, 'success=1')); + $explode = explode('/', $uriRedirect); + $databoxId = $explode[3]; $databox = $this->app['phraseanet.appbox']->get_databox($databoxId); $databox->unmount_databox($this->app['phraseanet.appbox']); $databox->delete(); @@ -673,8 +694,10 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue($response->isRedirect()); $uriRedirect = $response->headers->get('location'); - $this->assertTrue( ! ! strrpos($uriRedirect, 'success=mount-ok')); - $databoxId = array_pop(explode('=', array_pop(explode('&', $uriRedirect)))); + + $this->assertTrue( ! ! strrpos($uriRedirect, 'success=1')); + $explode = explode('/', $uriRedirect); + $databoxId = $explode[3]; try { $databox = $this->app['phraseanet.appbox']->get_databox($databoxId); @@ -718,7 +741,7 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'newLogoPdf' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') ); $this->client->request('POST', '/databox/' . self::$collection->get_sbas_id() . '/logo/', array(), $files); - $this->checkRedirection($this->client->getResponse(), '/admin/databox/' . self::$collection->get_sbas_id() . '/'); + $this->checkRedirection($this->client->getResponse(), '/admin/databox/' . self::$collection->get_sbas_id() . '/?success=1'); $this->assertNotEmpty(\databox::getPrintLogo(self::$collection->get_sbas_id())); } diff --git a/www/.htaccess b/www/.htaccess index b1a3770d26..302ead186d 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -6,7 +6,7 @@ RewriteRule ^(mail-export)/([a-zA-Z0-9]*)\/?$ /include/download_anonymous.php?type=$1&token=$2 [L] RewriteRule ^(mail-export)/([a-zA-Z0-9]*)\/get$ /include/download_anonymous.php?type=$1&token=$2&get=1 [L] - RewriteRule ^admin/$ /admin/router.php [L] + RewriteRule ^admin/.*$ /admin/router.php [L] RewriteRule ^admin/databox/.*$ /admin/router.php [L] RewriteRule ^admin/sphinx/.*$ /admin/router.php [L] RewriteRule ^admin/structure/.*$ /admin/router.php [L]