Add error pages, fix error handling and PHP conf

This commit is contained in:
Romain Neutron
2013-06-14 20:35:39 +02:00
parent 09c6361475
commit 42db38d055
140 changed files with 1962 additions and 1218 deletions

View File

@@ -73,7 +73,8 @@ use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest;
use Alchemy\Phrasea\Controller\User\Notifications; use Alchemy\Phrasea\Controller\User\Notifications;
use Alchemy\Phrasea\Controller\User\Preferences; use Alchemy\Phrasea\Controller\User\Preferences;
use Alchemy\Phrasea\Core\Event\Subscriber\Logout; use Alchemy\Phrasea\Core\PhraseaExceptionHandler;
use Alchemy\Phrasea\Core\Event\Subscriber\LogoutSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaLocaleSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaLocaleSubscriber;
use Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider; use Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider;
use Alchemy\Phrasea\Core\Provider\BrowserServiceProvider; use Alchemy\Phrasea\Core\Provider\BrowserServiceProvider;
@@ -121,7 +122,6 @@ use Silex\Provider\SwiftmailerServiceProvider;
use Silex\Provider\UrlGeneratorServiceProvider; use Silex\Provider\UrlGeneratorServiceProvider;
use Silex\Provider\ValidatorServiceProvider; use Silex\Provider\ValidatorServiceProvider;
use Silex\Provider\ServiceControllerServiceProvider; use Silex\Provider\ServiceControllerServiceProvider;
use Silex\Provider\WebProfilerServiceProvider;
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Unoconv\UnoconvServiceProvider; use Unoconv\UnoconvServiceProvider;
@@ -155,34 +155,25 @@ class Application extends SilexApplication
private $environment; private $environment;
private $sessionCookieEnabled = true; private $sessionCookieEnabled = true;
const ENV_DEV = 'dev';
const ENV_PROD = 'prod';
const ENV_TEST = 'test';
public function getEnvironment() public function getEnvironment()
{ {
return $this->environment; return $this->environment;
} }
public function __construct($environment = 'prod') public function __construct($environment = self::ENV_PROD)
{ {
parent::__construct(); parent::__construct();
error_reporting(-1);
$this['root.path'] = realpath(__DIR__ . '/../../..'); $this['root.path'] = realpath(__DIR__ . '/../../..');
$this->environment = $environment; $this->environment = $environment;
if ((int) ini_get('memory_limit') < 2048) {
ini_set('memory_limit', '2048M');
}
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'on');
ini_set('output_buffering', '4096');
ini_set('default_charset', 'UTF-8'); ini_set('default_charset', 'UTF-8');
ini_set('session.use_cookies', '1');
ini_set('session.use_only_cookies', '1');
ini_set('session.auto_start', '0');
ini_set('session.hash_function', '1');
ini_set('session.hash_bits_per_character', '6');
ini_set('session.cache_limiter', '');
ini_set('allow_url_fopen', 'on');
mb_internal_encoding("UTF-8"); mb_internal_encoding("UTF-8");
!defined('JETON_MAKE_SUBDEF') ? define('JETON_MAKE_SUBDEF', 0x01) : ''; !defined('JETON_MAKE_SUBDEF') ? define('JETON_MAKE_SUBDEF', 0x01) : '';
@@ -193,17 +184,12 @@ class Application extends SilexApplication
$this['charset'] = 'UTF-8'; $this['charset'] = 'UTF-8';
$this['debug'] = $this->share(function(Application $app) { $this['debug'] = $this->share(function(Application $app) {
return $app->getEnvironment() !== 'prod'; return Application::ENV_PROD !== $app->getEnvironment();
}); });
if ($this['debug'] === true) { if ($this['debug'] === true) {
ini_set('display_errors', 'on'); ini_set('log_errors', 'on');
if ($this->getEnvironment() === 'dev') { ini_set('error_log', $this['root.path'] . '/logs/php_error.log');
ini_set('log_errors', 'on');
ini_set('error_log', __DIR__ . '/../../../logs/php_error.log');
}
} else {
ini_set('display_errors', 'off');
} }
$this->register(new AuthenticationManagerServiceProvider()); $this->register(new AuthenticationManagerServiceProvider());
@@ -263,7 +249,7 @@ class Application extends SilexApplication
$this->register(new SearchEngineServiceProvider()); $this->register(new SearchEngineServiceProvider());
$this->register(new SessionServiceProvider(), array( $this->register(new SessionServiceProvider(), array(
'session.test' => $this->getEnvironment() == 'test' 'session.test' => $this->getEnvironment() === static::ENV_TEST
)); ));
$this->register(new ServiceControllerServiceProvider()); $this->register(new ServiceControllerServiceProvider());
$this->register(new SwiftmailerServiceProvider()); $this->register(new SwiftmailerServiceProvider());
@@ -272,7 +258,7 @@ class Application extends SilexApplication
$this->register(new TokensServiceProvider()); $this->register(new TokensServiceProvider());
$this->register(new TwigServiceProvider(), array( $this->register(new TwigServiceProvider(), array(
'twig.options' => array( 'twig.options' => array(
'cache' => realpath(__DIR__ . '/../../../tmp/cache_twig/'), 'cache' => $this['root.path'] . '/tmp/cache_twig/',
), ),
'twig.form.templates' => array('login/common/form_div_layout.html.twig') 'twig.form.templates' => array('login/common/form_div_layout.html.twig')
)); ));
@@ -285,19 +271,14 @@ class Application extends SilexApplication
$this->register(new UnicodeServiceProvider()); $this->register(new UnicodeServiceProvider());
$this->register(new ValidatorServiceProvider()); $this->register(new ValidatorServiceProvider());
if ('dev' === $this->environment) {
$this->register($p = new WebProfilerServiceProvider(), array(
'profiler.cache_dir' => __DIR__ . '/../../../tmp/cache/profiler',
));
$this->mount('/_profiler', $p);
}
$this->register(new XPDFServiceProvider()); $this->register(new XPDFServiceProvider());
$this['phraseanet.exception_handler'] = $this->share(function ($app) {
return PhraseaExceptionHandler::register($app['debug']);
});
$this['swiftmailer.transport'] = $this->share(function ($app) { $this['swiftmailer.transport'] = $this->share(function ($app) {
if ($app['phraseanet.registry']->get('GV_smtp')) { if ($app['phraseanet.registry']->get('GV_smtp')) {
$transport = new \Swift_Transport_EsmtpTransport( $transport = new \Swift_Transport_EsmtpTransport(
$app['swiftmailer.transport.buffer'], $app['swiftmailer.transport.buffer'],
array($app['swiftmailer.transport.authhandler']), array($app['swiftmailer.transport.authhandler']),
@@ -340,9 +321,6 @@ class Application extends SilexApplication
return $transport; return $transport;
}); });
// $this->register(new \Silex\Provider\HttpCacheServiceProvider());
// $this->register(new \Silex\Provider\SecurityServiceProvider());
$this['imagine.factory'] = $this->share(function(Application $app) { $this['imagine.factory'] = $this->share(function(Application $app) {
if ($app['phraseanet.registry']->get('GV_imagine_driver') != '') { if ($app['phraseanet.registry']->get('GV_imagine_driver') != '') {
return $app['phraseanet.registry']->get('GV_imagine_driver'); return $app['phraseanet.registry']->get('GV_imagine_driver');
@@ -384,11 +362,17 @@ class Application extends SilexApplication
}) })
); );
$this['dispatcher']->addListener(KernelEvents::REQUEST, array($this, 'initSession'), 254); $this['dispatcher'] = $this->share(
$this['dispatcher']->addListener(KernelEvents::RESPONSE, array($this, 'addUTF8Charset'), -128); $this->extend('dispatcher', function($dispatcher, Application $app){
$this['dispatcher']->addListener(KernelEvents::RESPONSE, array($this, 'disableCookiesIfRequired'), -256); $dispatcher->addListener(KernelEvents::REQUEST, array($app, 'initSession'), 254);
$this['dispatcher']->addSubscriber(new Logout()); $dispatcher->addListener(KernelEvents::RESPONSE, array($app, 'addUTF8Charset'), -128);
$this['dispatcher']->addSubscriber(new PhraseaLocaleSubscriber($this)); $dispatcher->addListener(KernelEvents::RESPONSE, array($app, 'disableCookiesIfRequired'), -256);
$dispatcher->addSubscriber(new LogoutSubscriber());
$dispatcher->addSubscriber(new PhraseaLocaleSubscriber($app));
return $dispatcher;
})
);
$this->register(new LocaleServiceProvider()); $this->register(new LocaleServiceProvider());

View File

@@ -17,17 +17,19 @@ use Alchemy\Phrasea\Controller\Api\Oauth2;
use Alchemy\Phrasea\Controller\Api\V1; use Alchemy\Phrasea\Controller\Api\V1;
use Alchemy\Phrasea\Core\Event\ApiLoadEndEvent; use Alchemy\Phrasea\Core\Event\ApiLoadEndEvent;
use Alchemy\Phrasea\Core\Event\ApiLoadStartEvent; use Alchemy\Phrasea\Core\Event\ApiLoadStartEvent;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiOauth2ErrorsSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiExceptionHandlerSubscriber;
use Silex\Application as SilexApplication; use Silex\Application as SilexApplication;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Response;
return call_user_func(function($environment = 'prod') { return call_user_func(function($environment = PhraseaApplication::ENV_PROD) {
$app = new PhraseaApplication($environment); $app = new PhraseaApplication($environment);
$app['exception_handler'] = $app->share(function ($app) {
return new ApiExceptionHandlerSubscriber($app);
});
$app->disableCookies(); $app->disableCookies();
$app->register(new \API_V1_Timer()); $app->register(new \API_V1_Timer());
@@ -61,72 +63,7 @@ return call_user_func(function($environment = 'prod') {
$app->mount('/api/oauthv2', new Oauth2()); $app->mount('/api/oauthv2', new Oauth2());
$app->mount('/api/v1', new V1()); $app->mount('/api/v1', new V1());
/** $app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber($app['phraseanet.exception_handler']));
* Route Errors
*/
$app->error(function (\Exception $e) use ($app) {
$request = $app['request'];
if (0 === strpos($request->getPathInfo(), '/api/oauthv2')) {
if ($e instanceof NotFoundHttpException || $e instanceof \Exception_NotFound) {
return new Response('The requested page could not be found.', 404, array('X-Status-Code' => 404));
}
$code = 500;
$msg = 'We are sorry, but something went wrong';
$headers = array();
if ($e instanceof HttpExceptionInterface) {
$headers = $e->getHeaders();
$msg = $e->getMessage();
$code = $e->getStatusCode();
if (isset($headers['content-type']) && $headers['content-type'] == 'application/json') {
$msg = json_encode(array('msg' => $msg, 'code' => $code));
}
}
return new Response($msg, $code, $headers);
}
$headers = array();
if ($e instanceof \API_V1_exception_methodnotallowed) {
$code = \API_V1_result::ERROR_METHODNOTALLOWED;
} elseif ($e instanceof MethodNotAllowedHttpException) {
$code = \API_V1_result::ERROR_METHODNOTALLOWED;
} elseif ($e instanceof \API_V1_exception_badrequest) {
$code = \API_V1_result::ERROR_BAD_REQUEST;
} elseif ($e instanceof \API_V1_exception_forbidden) {
$code = \API_V1_result::ERROR_FORBIDDEN;
} elseif ($e instanceof \API_V1_exception_unauthorized) {
$code = \API_V1_result::ERROR_UNAUTHORIZED;
} elseif ($e instanceof \API_V1_exception_internalservererror) {
$code = \API_V1_result::ERROR_INTERNALSERVERERROR;
} elseif ($e instanceof \Exception_NotFound) {
$code = \API_V1_result::ERROR_NOTFOUND;
} elseif ($e instanceof NotFoundHttpException) {
$code = \API_V1_result::ERROR_NOTFOUND;
} else {
$code = \API_V1_result::ERROR_INTERNALSERVERERROR;
}
if ($e instanceof HttpException) {
$headers = $e->getHeaders();
}
$result = $app['api']->get_error_message($app['request'], $code, $e->getMessage());
$response = $result->get_response();
$response->headers->set('X-Status-Code', $result->get_http_code());
foreach ($headers as $key => $value) {
$response->headers->set($key, $value);
}
return $response;
});
$app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_END, new ApiLoadEndEvent()); $app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_END, new ApiLoadEndEvent());
return $app; return $app;

View File

@@ -12,15 +12,22 @@
namespace Alchemy\Phrasea\Application; namespace Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaExceptionHandlerSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\BridgeExceptionSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\FirewallSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\JsonRequestSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\DebuggerSubscriber;
use Silex\Provider\WebProfilerServiceProvider;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
return call_user_func(function($environment = null) { return call_user_func(function($environment = PhraseaApplication::ENV_PROD) {
$app = new PhraseaApplication($environment); $app = new PhraseaApplication($environment);
$app['exception_handler'] = $app->share(function ($app) {
return new PhraseaExceptionHandlerSubscriber($app['phraseanet.exception_handler']);
});
$app->before(function (Request $request) use ($app) { $app->before(function (Request $request) use ($app) {
if (0 === strpos($request->getPathInfo(), '/setup')) { if (0 === strpos($request->getPathInfo(), '/setup')) {
if (!$app['phraseanet.configuration-tester']->isBlank()) { if (!$app['phraseanet.configuration-tester']->isBlank()) {
@@ -41,98 +48,23 @@ return call_user_func(function($environment = null) {
$app->bindRoutes(); $app->bindRoutes();
$app->error(function(\Exception $e) use ($app) { if (PhraseaApplication::ENV_DEV === $app->getEnvironment()) {
$request = $app['request']; $app->register(new WebProfilerServiceProvider(), array(
'profiler.cache_dir' => $app['root.path'] . '/tmp/cache/profiler',
'profiler.mount_prefix' => '/_profiler',
));
}
if ($e instanceof \Bridge_Exception) { $app['dispatcher'] = $app->share(
$params = array( $app->extend('dispatcher', function($dispatcher, PhraseaApplication $app){
'message' => $e->getMessage() $dispatcher->addSubscriber(new BridgeExceptionSubscriber($app));
, 'file' => $e->getFile() $dispatcher->addSubscriber(new FirewallSubscriber());
, 'line' => $e->getLine() $dispatcher->addSubscriber(new JsonRequestSubscriber());
, 'r_method' => $request->getMethod() $dispatcher->addSubscriber(new DebuggerSubscriber($app));
, 'r_action' => $request->getRequestUri()
, 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all())
);
if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) { return $dispatcher;
$params = array_merge($params, array('account' => $app['current_account'])); })
);
$response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
$params = array_merge($params, array('account' => $app['current_account']));
$response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
$params = array_merge($params, array('account' => $app['current_account']));
$response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
$params = array_merge($params, array('api' => $e->get_api()));
$response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200, array('X-Status-Code' => 200));
} else {
$response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, array('X-Status-Code' => 200));
}
$response->headers->set('Phrasea-StatusCode', 200);
return $response;
}
if ((0 !== strpos($request->getPathInfo(), '/admin/')
|| 0 === strpos($request->getPathInfo(), '/admin/collection/')
|| 0 === strpos($request->getPathInfo(), '/admin/databox/'))
&& $request->getRequestFormat() == 'json') {
$datas = array(
'success' => false
, 'message' => $e->getMessage()
);
return $app->json($datas, 200, array('X-Status-Code' => 200));
}
if ($e instanceof HttpExceptionInterface) {
$headers = $e->getHeaders();
if (isset($headers['X-Phraseanet-Redirect'])) {
return new RedirectResponse($headers['X-Phraseanet-Redirect'], 302, array('X-Status-Code' => 302));
}
$message = isset(Response::$statusTexts[$e->getStatusCode()]) ? Response::$statusTexts[$e->getStatusCode()] : '';
if (400 === $e->getStatusCode()) {
$message .= ' : ' . $e->getMessage();
}
return new Response($message, $e->getStatusCode(), $e->getHeaders());
}
if ($e instanceof \Exception_BadRequest) {
return new Response('Bad Request', 400, array('X-Status-Code' => 400));
}
if ($e instanceof \Exception_Forbidden) {
return new Response('Forbidden', 403, array('X-Status-Code' => 403));
}
if ($e instanceof \Exception_Session_NotAuthenticated) {
$code = 403;
$message = 'Forbidden';
} elseif ($e instanceof \Exception_NotAllowed) {
$code = 403;
$message = 'Forbidden';
} elseif ($e instanceof \Exception_NotFound) {
$code = 404;
$message = 'Not Found';
} elseif ($e instanceof \Exception_UnauthorizedAction) {
$code = 403;
$message = 'Forbidden';
} else {
$code = 500;
$message = 'Server Error' . ($app['debug'] ? ' : ' . $e->getMessage() : '');
}
return new Response($message, $code, array('X-Status-Code' => $code));
});
return $app; return $app;
}, isset($environment) ? $environment : null); }, isset($environment) ? $environment : null);

View File

@@ -17,6 +17,7 @@ use Browser;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Entities\Session; use Entities\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Authenticator class Authenticator
{ {
@@ -93,7 +94,7 @@ class Authenticator
try { try {
$user = \User_Adapter::getInstance($session->getUsrId(), $this->app); $user = \User_Adapter::getInstance($session->getUsrId(), $this->app);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
throw new RuntimeException('Unable to refresh the session', $e->getCode(), $e); throw new RuntimeException('Unable to refresh the session', $e->getCode(), $e);
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Authentication\Token; namespace Alchemy\Phrasea\Authentication\Token;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class TokenValidator class TokenValidator
{ {
@@ -34,7 +35,7 @@ class TokenValidator
$datas = $this->app['tokens']->helloToken($token); $datas = $this->app['tokens']->helloToken($token);
return $datas['usr_id']; return $datas['usr_id'];
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Border\Attribute; namespace Alchemy\Phrasea\Border\Attribute;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Phraseanet Border MetaField Attribute * Phraseanet Border MetaField Attribute
@@ -108,7 +109,7 @@ class MetaField implements AttributeInterface
return new static($app['phraseanet.appbox'] return new static($app['phraseanet.appbox']
->get_databox($datas['sbas_id']) ->get_databox($datas['sbas_id'])
->get_meta_structure()->get_element($datas['id']), $datas['value']); ->get_meta_structure()->get_element($datas['id']), $datas['value']);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
throw new \InvalidArgumentException('Field does not exist anymore'); throw new \InvalidArgumentException('Field does not exist anymore');
} }
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Border\Attribute; namespace Alchemy\Phrasea\Border\Attribute;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Phraseanet Border Story Attribute * Phraseanet Border Story Attribute
@@ -82,7 +83,7 @@ class Story implements AttributeInterface
try { try {
$story = new \record_adapter($app, $ids[0], $ids[1]); $story = new \record_adapter($app, $ids[0], $ids[1]);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
throw new \InvalidArgumentException('Unable to fetch a story from string'); throw new \InvalidArgumentException('Unable to fetch a story from string');
} }

View File

@@ -219,11 +219,11 @@ class Manager
*/ */
protected function bookLazaretPathfile($filename, $suffix = '') protected function bookLazaretPathfile($filename, $suffix = '')
{ {
$output = __DIR__ . '/../../../../tmp/lazaret/lzrt_' . substr($filename, 0, 3) . '_' . $suffix . '.' . pathinfo($filename, PATHINFO_EXTENSION); $output = $this->app['root.path'] . '/tmp/lazaret/lzrt_' . substr($filename, 0, 3) . '_' . $suffix . '.' . pathinfo($filename, PATHINFO_EXTENSION);
$infos = pathinfo($output); $infos = pathinfo($output);
$n = 0; $n = 0;
$this->app['filesystem']->mkdir(__DIR__ . '/../../../../tmp/lazaret'); $this->app['filesystem']->mkdir($this->app['root.path'] . '/tmp/lazaret');
while (true) { while (true) {
$output = sprintf('%s/%s-%d%s', $infos['dirname'], $infos['filename'], ++ $n, (isset($infos['extension']) ? '.' . $infos['extension'] : '')); $output = sprintf('%s/%s-%d%s', $infos['dirname'], $infos['filename'], ++ $n, (isset($infos['extension']) ? '.' . $infos['extension'] : ''));

View File

@@ -27,7 +27,7 @@ class Configuration extends Command
{ {
$this->container['phraseanet.configuration']->compileAndWrite(); $this->container['phraseanet.configuration']->compileAndWrite();
$output->writeln("Confguration compiled."); $output->writeln("Confguration compiled.");
return 0; return 0;
} }
} }

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Application as PhraseaApplication;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
/** /**
* *
@@ -111,23 +112,23 @@ class Publications implements ControllerProviderInterface
try { try {
if (!$request->files->get('files')) { if (!$request->files->get('files')) {
throw new \Exception_BadRequest('Missing file parameter'); throw new BadRequestHttpException('Missing file parameter');
} }
if (count($request->files->get('files')) > 1) { if (count($request->files->get('files')) > 1) {
throw new \Exception_BadRequest('Upload is limited to 1 file per request'); throw new BadRequestHttpException('Upload is limited to 1 file per request');
} }
$file = current($request->files->get('files')); $file = current($request->files->get('files'));
if (!$file->isValid()) { if (!$file->isValid()) {
throw new \Exception_BadRequest('Uploaded file is invalid'); throw new BadRequestHttpException('Uploaded file is invalid');
} }
$media = $app['mediavorus']->guess($file->getPathname()); $media = $app['mediavorus']->guess($file->getPathname());
if ($media->getType() !== \MediaVorus\Media\MediaInterface::TYPE_IMAGE) { if ($media->getType() !== \MediaVorus\Media\MediaInterface::TYPE_IMAGE) {
throw new \Exception_BadRequest('Bad filetype'); throw new BadRequestHttpException('Bad filetype');
} }
$spec = new \MediaAlchemyst\Specification\Image(); $spec = new \MediaAlchemyst\Specification\Image();

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Exception\SessionNotFound;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
* *
@@ -340,7 +341,7 @@ class Root implements ControllerProviderInterface
if (null !== $file = $request->files->get('image_off')) { if (null !== $file = $request->files->get('image_off')) {
try { try {
\databox_status::updateIcon($app, $databox_id, $bit, 'off', $file); \databox_status::updateIcon($app, $databox_id, $bit, 'off', $file);
} catch (\Exception_Forbidden $e) { } catch (AccessDeniedHttpException $e) {
return $app->redirectPath('database_display_statusbit_form', array( return $app->redirectPath('database_display_statusbit_form', array(
'databox_id' => $databox_id, 'databox_id' => $databox_id,
'bit' => $bit, 'bit' => $bit,
@@ -386,7 +387,7 @@ class Root implements ControllerProviderInterface
if (null !== $file = $request->files->get('image_on')) { if (null !== $file = $request->files->get('image_on')) {
try { try {
\databox_status::updateIcon($app, $databox_id, $bit, 'on', $file); \databox_status::updateIcon($app, $databox_id, $bit, 'on', $file);
} catch (\Exception_Forbidden $e) { } catch (AccessDeniedHttpException $e) {
return $app->redirectPath('database_display_statusbit_form', array( return $app->redirectPath('database_display_statusbit_form', array(
'databox_id' => $databox_id, 'databox_id' => $databox_id,
'bit' => $bit, 'bit' => $bit,

View File

@@ -165,6 +165,7 @@ class TaskManager implements ControllerProviderInterface
/** /**
* todo : add a message back * todo : add a message back
*/ */
return $app->redirectPath('admin_tasks_list'); return $app->redirectPath('admin_tasks_list');
} }
})->bind('admin_tasks_task_delete'); })->bind('admin_tasks_task_delete');

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Application as PhraseaApplication;
use Silex\Application; use Silex\Application;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
* *
@@ -63,7 +64,7 @@ class Datafiles extends AbstractDelivery
} }
if (!$app['authentication']->getUser()->ACL()->has_access_to_subdef($record, $subdef)) { if (!$app['authentication']->getUser()->ACL()->has_access_to_subdef($record, $subdef)) {
throw new \Exception_UnauthorizedAction(sprintf('User has not access to subdef %s', $subdef)); throw new AccessDeniedHttpException(sprintf('User has not access to subdef %s', $subdef));
} }
$stamp = false; $stamp = false;

View File

@@ -17,6 +17,7 @@ use Silex\ControllerProviderInterface;
use Silex\Application as SilexApplication; use Silex\Application as SilexApplication;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Lightbox implements ControllerProviderInterface class Lightbox implements ControllerProviderInterface
{ {
@@ -43,7 +44,7 @@ class Lightbox implements ControllerProviderInterface
try { try {
$datas = $app['tokens']->helloToken($request->query->get('LOG')); $datas = $app['tokens']->helloToken($request->query->get('LOG'));
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
return; return;
} }
switch ($datas['type']) { switch ($datas['type']) {

View File

@@ -26,7 +26,7 @@ class Minifier implements ControllerProviderInterface
$controllers->get('/', function (Application $app, Request $request) { $controllers->get('/', function (Application $app, Request $request) {
// cache directory path // cache directory path
$min_cachePath = __DIR__ . '/../../../../tmp/cache_minify'; $min_cachePath = $app['root.path'] . '/tmp/cache_minify';
/** /**
* Cache file locking. Set to false if filesystem is NFS. On at least one * Cache file locking. Set to false if filesystem is NFS. On at least one

View File

@@ -37,7 +37,7 @@ class Permalink extends AbstractDelivery
$record = \media_Permalink_Adapter::challenge_token($app, $databox, $token, $record_id, $subdef); $record = \media_Permalink_Adapter::challenge_token($app, $databox, $token, $record_id, $subdef);
if (!$record instanceof \record_adapter) { if (!$record instanceof \record_adapter) {
throw new \Exception_NotFound('bad luck'); throw new NotFoundHttpException('bad luck');
} }
$params = array( $params = array(
@@ -56,7 +56,7 @@ class Permalink extends AbstractDelivery
$record = \media_Permalink_Adapter::challenge_token($app, $databox, $token, $record_id, $subdef); $record = \media_Permalink_Adapter::challenge_token($app, $databox, $token, $record_id, $subdef);
if (!($record instanceof \record_adapter)) { if (!($record instanceof \record_adapter)) {
throw new \Exception_NotFound('bad luck'); throw new NotFoundHttpException('bad luck');
} }
$watermark = $stamp = false; $watermark = $stamp = false;

View File

@@ -18,6 +18,8 @@ use Entities\ValidationData;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -272,9 +274,9 @@ class Basket implements ControllerProviderInterface
$success = true; $success = true;
$msg = _('Basket has been updated'); $msg = _('Basket has been updated');
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$msg = _('The requested basket does not exist'); $msg = _('The requested basket does not exist');
} catch (\Exception_Forbidden $e) { } catch (AccessDeniedHttpException $e) {
$msg = _('You do not have access to this basket'); $msg = _('You do not have access to this basket');
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = _('An error occurred'); $msg = _('An error occurred');

View File

@@ -17,433 +17,456 @@ use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Bridge implements ControllerProviderInterface class Bridge implements ControllerProviderInterface
{ {
public function connect(Application $app) public function connect(Application $app)
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) { $controllers->before(function(Request $request) use ($app) {
$app['firewall'] $app['firewall']->requireRight('bas_chupub');
->requireNotGuest()
->requireRight('bas_chupub');
}); });
$app['require_connection'] = $app->protect(function(\Bridge_Account $account) use ($app) { $app['bridge.controller'] = $this;
$app['current_account'] = function() use ($account) {
return $account;
};
if (!$account->get_api()->get_connector()->is_configured()) $controllers
throw new \Bridge_Exception_ApiConnectorNotConfigured("Bridge API Connector is not configured"); ->post('/manager/', 'bridge.controller:doPostManager');
if (!$account->get_api()->get_connector()->is_connected())
throw new \Bridge_Exception_ApiConnectorNotConnected("Bridge API Connector is not connected");
return; $controllers
}); ->get('/login/{api_name}/', 'bridge.controller:doGetLogin')
->bind('prod_bridge_login');
$controllers->post('/manager/', function(Application $app) { $controllers
$route = new RecordHelper\Bridge($app, $app['request']); ->get('/callback/{api_name}/', 'bridge.controller:doGetCallback')
->bind('prod_bridge_callback');
$params = array( $controllers
'user_accounts' => \Bridge_Account::get_accounts_by_user($app, $app['authentication']->getUser()) ->get('/adapter/{account_id}/logout/', 'bridge.controller:doGetAccountLogout')
, 'available_apis' => \Bridge_Api::get_availables($app)
, 'route' => $route
, 'current_account_id' => ''
);
return $app['twig']->render('prod/actions/Bridge/index.html.twig', $params);
});
$controllers->get('/login/{api_name}/', function(Application $app, $api_name) {
$connector = \Bridge_Api::get_connector_by_name($app, $api_name);
return $app->redirect($connector->get_auth_url());
})->bind('prod_bridge_login');
$controllers->get('/callback/{api_name}/', function(Application $app, $api_name) {
$error_message = '';
try {
$api = \Bridge_Api::get_by_api_name($app, $api_name);
$connector = $api->get_connector();
$response = $connector->connect();
$user_id = $connector->get_user_id();
try {
$account = \Bridge_Account::load_account_from_distant_id($app, $api, $app['authentication']->getUser(), $user_id);
} catch (\Bridge_Exception_AccountNotFound $e) {
$account = \Bridge_Account::create($app, $api, $app['authentication']->getUser(), $user_id, $connector->get_user_name());
}
$settings = $account->get_settings();
if (isset($response['auth_token']))
$settings->set('auth_token', $response['auth_token']);
if (isset($response['refresh_token']))
$settings->set('refresh_token', $response['refresh_token']);
$connector->set_auth_settings($settings);
$connector->reconnect();
} catch (\Exception $e) {
$error_message = $e->getMessage();
}
$params = array('error_message' => $error_message);
return $app['twig']->render('prod/actions/Bridge/callback.html.twig', $params);
})->bind('prod_bridge_callback');
$controllers->get('/adapter/{account_id}/logout/', function(Application $app, $account_id) {
$account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account);
$account->get_api()->get_connector()->disconnect();
return $app->redirectPath('bridge_load_elements', array(
'account_id' => $account_id,
'type' => $account->get_api()->get_connector()->get_default_element_type(),
));
})
->bind('prod_bridge_account_logout') ->bind('prod_bridge_account_logout')
->assert('account_id', '\d+'); ->assert('account_id', '\d+');
$controllers->post('/adapter/{account_id}/delete/' $controllers
, function($account_id) use ($app) { ->post('/adapter/{account_id}/delete/', 'bridge.controller:doPostAccountDelete')
$success = false; ->assert('account_id', '\d+');
$message = '';
try {
$account = \Bridge_Account::load_account($app, $account_id);
if ($account->get_user()->get_id() !== $app['authentication']->getUser()->get_id()) { $controllers
throw new HttpException(403, 'Access forbiden'); ->get('/adapter/{account_id}/load-records/', 'bridge.controller:doGetloadRecords')
}
$account->delete();
$success = true;
} catch (\Bridge_Exception_AccountNotFound $e) {
$message = _('Account is not found.');
} catch (\Exception $e) {
$message = _('Something went wrong, please contact an administrator');
}
return $app->json(array('success' => $success, 'message' => $message));
})->assert('account_id', '\d+');
$controllers->get('/adapter/{account_id}/load-records/', function(Application $app, $account_id) {
$page = max((int) $app['request']->query->get('page'), 0);
$quantity = 10;
$offset_start = max(($page - 1) * $quantity, 0);
$account = \Bridge_Account::load_account($app, $account_id);
$elements = \Bridge_Element::get_elements_by_account($app, $account, $offset_start, $quantity);
$app['require_connection']($account);
$params = array(
'adapter_action' => 'load-records'
, 'account' => $account
, 'elements' => $elements
, 'error_message' => $app['request']->query->get('error')
, 'notice_message' => $app['request']->query->get('notice')
);
return $app['twig']->render('prod/actions/Bridge/records_list.html.twig', $params);
})
->bind('prod_bridge_account_loadrecords') ->bind('prod_bridge_account_loadrecords')
->assert('account_id', '\d+'); ->assert('account_id', '\d+');
$controllers->get('/adapter/{account_id}/load-elements/{type}/', function($account_id, $type) use ($app) { $controllers
$page = max((int) $app['request']->query->get('page'), 0); ->get('/adapter/{account_id}/load-elements/{type}/', 'bridge.controller:doGetLoadElements')
$quantity = 5;
$offset_start = max(($page - 1) * $quantity, 0);
$account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account);
$elements = $account->get_api()->list_elements($type, $offset_start, $quantity);
$params = array(
'action_type' => $type
, 'adapter_action' => 'load-elements'
, 'account' => $account
, 'elements' => $elements
, 'error_message' => $app['request']->query->get('error')
, 'notice_message' => $app['request']->query->get('notice')
);
return $app['twig']->render('prod/actions/Bridge/element_list.html.twig', $params);
})
->bind('bridge_load_elements') ->bind('bridge_load_elements')
->assert('account_id', '\d+'); ->assert('account_id', '\d+');
$controllers->get('/adapter/{account_id}/load-containers/{type}/', function(Application $app, $account_id, $type) { $controllers
->get('/adapter/{account_id}/load-containers/{type}/', 'bridge.controller:doGetLoadContainers')
$page = max((int) $app['request']->query->get('page'), 0);
$quantity = 5;
$offset_start = max(($page - 1) * $quantity, 0);
$account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account);
$elements = $account->get_api()->list_containers($type, $offset_start, $quantity);
$params = array(
'action_type' => $type
, 'adapter_action' => 'load-containers'
, 'account' => $account
, 'elements' => $elements
, 'error_message' => $app['request']->query->get('error')
, 'notice_message' => $app['request']->query->get('notice')
);
return $app['twig']->render('prod/actions/Bridge/element_list.html.twig', $params);
})
->bind('prod_bridge_account_loadcontainers') ->bind('prod_bridge_account_loadcontainers')
->assert('account_id', '\d+'); ->assert('account_id', '\d+');
$controllers->get('/action/{account_id}/{action}/{element_type}/', function(Application $app, $account_id, $action, $element_type) { $controllers
->get('/action/{account_id}/{action}/{element_type}/', 'bridge.controller:doGetAction')
$account = \Bridge_Account::load_account($app, $account_id);
$app['require_connection']($account);
$request = $app['request'];
$elements = $request->query->get('elements_list', array());
$elements = is_array($elements) ? $elements : explode(';', $elements);
$destination = $request->query->get('destination');
$route_params = array();
$class = $account->get_api()->get_connector()->get_object_class_from_type($element_type);
switch ($action) {
case 'createcontainer':
break;
case 'modify':
if (count($elements) != 1) {
return $app->redirectPath('bridge_load_elements', array(
'account_id' => $account_id,
'type' => $element_type,
'page' => '',
'error' => _('Vous ne pouvez pas editer plusieurs elements simultanement'),
));
}
foreach ($elements as $element_id) {
if ($class === \Bridge_Api_Interface::OBJECT_CLASS_ELEMENT) {
$route_params = array('element' => $account->get_api()->get_element_from_id($element_id, $element_type));
}
if ($class === \Bridge_Api_Interface::OBJECT_CLASS_CONTAINER) {
$route_params = array('element' => $account->get_api()->get_container_from_id($element_id, $element_type));
}
}
break;
case 'moveinto':
$route_params = array('containers' => $account->get_api()->list_containers($destination, 0, 0));
break;
case 'deleteelement':
break;
default:
throw new \Exception(_('Vous essayez de faire une action que je ne connais pas !'));
break;
}
$params = array(
'account' => $account
, 'destination' => $destination
, 'element_type' => $element_type
, 'action' => $action
, 'constraint_errors' => null
, 'adapter_action' => $action
, 'elements' => $elements
, 'error_message' => $app['request']->query->get('error')
, 'notice_message' => $app['request']->query->get('notice')
);
$params = array_merge($params, $route_params);
$template = 'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/' . $element_type . '_' . $action . ($destination ? '_' . $destination : '') . '.html.twig';
return $app['twig']->render($template, $params);
})
->bind('bridge_account_action') ->bind('bridge_account_action')
->assert('account_id', '\d+'); ->assert('account_id', '\d+');
$controllers->post('/action/{account_id}/{action}/{element_type}/', function(Application $app, $account_id, $action, $element_type) { $controllers
$account = \Bridge_Account::load_account($app, $account_id); ->post('/action/{account_id}/{action}/{element_type}/', 'bridge.controller:doPostAction')
$app['require_connection']($account);
$request = $app['request'];
$elements = $request->request->get('elements_list', array());
$elements = is_array($elements) ? $elements : explode(';', $elements);
$destination = $request->request->get('destination');
$class = $account->get_api()->get_connector()->get_object_class_from_type($element_type);
$html = '';
switch ($action) {
case 'modify':
if (count($elements) != 1) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?elements_list=' . implode(';', $elements) . '&error=' . _('Vous ne pouvez pas editer plusieurs elements simultanement'));
}
try {
foreach ($elements as $element_id) {
$datas = $account->get_api()->get_connector()->get_update_datas($app['request']);
$errors = $account->get_api()->get_connector()->check_update_constraints($datas);
}
if (count($errors) > 0) {
$params = array(
'element' => $account->get_api()->get_element_from_id($element_id, $element_type)
, 'account' => $account
, 'destination' => $destination
, 'element_type' => $element_type
, 'action' => $action
, 'elements' => $elements
, 'adapter_action' => $action
, 'error_message' => _('Request contains invalid datas')
, 'constraint_errors' => $errors
, 'notice_message' => $app['request']->request->get('notice')
);
$template = 'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/' . $element_type . '_' . $action . ($destination ? '_' . $destination : '') . '.html.twig';
return $app['twig']->render($template, $params);
}
foreach ($elements as $element_id) {
$datas = $account->get_api()->get_connector()->get_update_datas($app['request']);
$account->get_api()->update_element($element_type, $element_id, $datas);
}
} catch (\Exception $e) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?elements_list[]=' . $element_id . '&error=' . get_class($e) . ' : ' . $e->getMessage());
}
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/?page=&update=success#anchor');
break;
case 'createcontainer':
try {
$container_type = $request->request->get('f_container_type');
$account->get_api()->create_container($container_type, $app['request']);
} catch (\Exception $e) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . ' : ' . $e->getMessage());
}
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/?page=&update=success#anchor');
break;
case 'moveinto':
try {
$container_id = $request->request->get('container_id');
foreach ($elements as $element_id) {
$account->get_api()->add_element_to_container($element_type, $element_id, $destination, $container_id);
}
} catch (\Exception $e) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . ' : ' . $e->getMessage());
}
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-containers/' . $destination . '/?page=&update=success#anchor');
break;
case 'deleteelement':
try {
foreach ($elements as $element_id) {
$account->get_api()->delete_object($element_type, $element_id);
}
} catch (\Exception $e) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . $e->getMessage());
}
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/');
break;
default:
throw new \Exception('Unknown action');
break;
}
return new Response($html);
})
->bind('bridge_account_do_action') ->bind('bridge_account_do_action')
->assert('account_id', '\d+'); ->assert('account_id', '\d+');
$controllers->get('/upload/', function(Application $app) { $controllers
$request = $app['request']; ->get('/upload/', 'bridge.controller:doGetUpload')
$account = \Bridge_Account::load_account($app, $request->query->get('account_id')); ->bind('prod_bridge_upload');
$app['require_connection']($account);
$route = new RecordHelper\Bridge($app, $app['request']); $controllers
->post('/upload/', 'bridge.controller:doPostUpload')
$route->grep_records($account->get_api()->acceptable_records()); ->bind('prod_bridge_do_upload');
$params = array(
'route' => $route
, 'account' => $account
, 'error_message' => $app['request']->query->get('error')
, 'notice_message' => $app['request']->query->get('notice')
, 'constraint_errors' => null
, 'adapter_action' => 'upload'
);
return $app['twig']->render(
'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/upload.html.twig', $params
);
})->bind('prod_bridge_upload');
$controllers->post('/upload/', function(Application $app) {
$errors = array();
$request = $app['request'];
$account = \Bridge_Account::load_account($app, $request->request->get('account_id'));
$app['require_connection']($account);
$route = new RecordHelper\Bridge($app, $app['request']);
$route->grep_records($account->get_api()->acceptable_records());
$connector = $account->get_api()->get_connector();
/**
* check constraints
*/
foreach ($route->get_elements() as $record) {
$datas = $connector->get_upload_datas($request, $record);
$errors = array_merge($errors, $connector->check_upload_constraints($datas, $record));
}
if (count($errors) > 0) {
$params = array(
'route' => $route
, 'account' => $account
, 'error_message' => _('Request contains invalid datas')
, 'constraint_errors' => $errors
, 'notice_message' => $app['request']->request->get('notice')
, 'adapter_action' => 'upload'
);
return $app['twig']->render('prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/upload.html.twig', $params);
}
foreach ($route->get_elements() as $record) {
$datas = $connector->get_upload_datas($request, $record);
$title = isset($datas["title"]) ? $datas["title"] : '';
$default_type = $connector->get_default_element_type();
\Bridge_Element::create($app, $account, $record, $title, \Bridge_Element::STATUS_PENDING, $default_type, $datas);
}
return $app->redirect('/prod/bridge/adapter/' . $account->get_id() . '/load-records/?notice=' . sprintf(_('%d elements en attente'), count($route->get_elements())));
})->bind('prod_bridge_do_upload');
return $controllers; return $controllers;
} }
private function requireConnection(Application $app, \Bridge_Account $account)
{
$app['bridge.account'] = $account;
if (!$account->get_api()->get_connector()->is_configured()) {
throw new \Bridge_Exception_ApiConnectorNotConfigured("Bridge API Connector is not configured");
}
if (!$account->get_api()->get_connector()->is_connected()) {
throw new \Bridge_Exception_ApiConnectorNotConnected("Bridge API Connector is not connected");
}
}
public function doPostManager(Application $app, Request $request)
{
$route = new RecordHelper\Bridge($app, $request);
$params = array(
'user_accounts' => \Bridge_Account::get_accounts_by_user($app, $app['authentication']->getUser()),
'available_apis' => \Bridge_Api::get_availables($app),
'route' => $route,
'current_account_id' => '',
);
return $app['twig']->render('prod/actions/Bridge/index.html.twig', $params);
}
public function doGetLogin(Application $app, Request $request, $api_name)
{
$connector = \Bridge_Api::get_connector_by_name($app, $api_name);
return $app->redirect($connector->get_auth_url());
}
public function doGetCallback(Application $app, Request $request, $api_name)
{
$error_message = '';
try {
$api = \Bridge_Api::get_by_api_name($app, $api_name);
$connector = $api->get_connector();
$response = $connector->connect();
$user_id = $connector->get_user_id();
try {
$account = \Bridge_Account::load_account_from_distant_id($app, $api, $app['authentication']->getUser(), $user_id);
} catch (\Bridge_Exception_AccountNotFound $e) {
$account = \Bridge_Account::create($app, $api, $app['authentication']->getUser(), $user_id, $connector->get_user_name());
}
$settings = $account->get_settings();
if (isset($response['auth_token'])) {
$settings->set('auth_token', $response['auth_token']);
}
if (isset($response['refresh_token'])) {
$settings->set('refresh_token', $response['refresh_token']);
}
$connector->set_auth_settings($settings);
$connector->reconnect();
} catch (\Exception $e) {
$error_message = $e->getMessage();
}
$params = array('error_message' => $error_message);
return $app['twig']->render('prod/actions/Bridge/callback.html.twig', $params);
}
public function doGetAccountLogout(Application $app, Request $request, $account_id)
{
$account = \Bridge_Account::load_account($app, $account_id);
$this->requireConnection($app, $account);
$account->get_api()->get_connector()->disconnect();
return $app->redirectPath('bridge_load_elements', array(
'account_id' => $account_id,
'type' => $account->get_api()->get_connector()->get_default_element_type(),
));
}
public function doPostAccountDelete(Application $app, Request $request, $account_id)
{
$success = false;
$message = '';
try {
$account = \Bridge_Account::load_account($app, $account_id);
if ($account->get_user()->get_id() !== $app['authentication']->getUser()->get_id()) {
throw new HttpException(403, 'Access forbiden');
}
$account->delete();
$success = true;
} catch (\Bridge_Exception_AccountNotFound $e) {
$message = _('Account is not found.');
} catch (\Exception $e) {
$message = _('Something went wrong, please contact an administrator');
}
return $app->json(array('success' => $success, 'message' => $message));
}
public function doGetloadRecords(Application $app, Request $request, $account_id)
{
$page = max((int) $request->query->get('page'), 0);
$quantity = 10;
$offset_start = max(($page - 1) * $quantity, 0);
$account = \Bridge_Account::load_account($app, $account_id);
$elements = \Bridge_Element::get_elements_by_account($app, $account, $offset_start, $quantity);
$this->requireConnection($app, $account);
$params = array(
'adapter_action' => 'load-records'
, 'account' => $account
, 'elements' => $elements
, 'error_message' => $request->query->get('error')
, 'notice_message' => $request->query->get('notice')
);
return $app['twig']->render('prod/actions/Bridge/records_list.html.twig', $params);
}
public function doGetLoadElements(Application $app, Request $request, $account_id, $type)
{
$page = max((int) $request->query->get('page'), 0);
$quantity = 5;
$offset_start = max(($page - 1) * $quantity, 0);
$account = \Bridge_Account::load_account($app, $account_id);
$this->requireConnection($app, $account);
$elements = $account->get_api()->list_elements($type, $offset_start, $quantity);
$params = array(
'action_type' => $type,
'adapter_action' => 'load-elements',
'account' => $account,
'elements' => $elements,
'error_message' => $request->query->get('error'),
'notice_message' => $request->query->get('notice'),
);
return $app['twig']->render('prod/actions/Bridge/element_list.html.twig', $params);
}
public function doGetLoadContainers(Application $app, Request $request, $account_id, $type)
{
$page = max((int) $request->query->get('page'), 0);
$quantity = 5;
$offset_start = max(($page - 1) * $quantity, 0);
$account = \Bridge_Account::load_account($app, $account_id);
$this->requireConnection($app, $account);
$elements = $account->get_api()->list_containers($type, $offset_start, $quantity);
$params = array(
'action_type' => $type,
'adapter_action' => 'load-containers',
'account' => $account,
'elements' => $elements,
'error_message' => $request->query->get('error'),
'notice_message' => $request->query->get('notice'),
);
return $app['twig']->render('prod/actions/Bridge/element_list.html.twig', $params);
}
public function doGetAction(Application $app, Request $request, $account_id, $action, $element_type)
{
$account = \Bridge_Account::load_account($app, $account_id);
$this->requireConnection($app, $account);
$elements = $request->query->get('elements_list', array());
$elements = is_array($elements) ? $elements : explode(';', $elements);
$destination = $request->query->get('destination');
$route_params = array();
$class = $account->get_api()->get_connector()->get_object_class_from_type($element_type);
switch ($action) {
case 'createcontainer':
break;
case 'modify':
if (count($elements) != 1) {
return $app->redirectPath('bridge_load_elements', array(
'account_id' => $account_id,
'type' => $element_type,
'page' => '',
'error' => _('Vous ne pouvez pas editer plusieurs elements simultanement'),
));
}
foreach ($elements as $element_id) {
if ($class === \Bridge_Api_Interface::OBJECT_CLASS_ELEMENT) {
$route_params = array('element' => $account->get_api()->get_element_from_id($element_id, $element_type));
}
if ($class === \Bridge_Api_Interface::OBJECT_CLASS_CONTAINER) {
$route_params = array('element' => $account->get_api()->get_container_from_id($element_id, $element_type));
}
}
break;
case 'moveinto':
$route_params = array('containers' => $account->get_api()->list_containers($destination, 0, 0));
break;
case 'deleteelement':
break;
default:
throw new \Exception(_('Vous essayez de faire une action que je ne connais pas !'));
break;
}
$params = array(
'account' => $account,
'destination' => $destination,
'element_type' => $element_type,
'action' => $action,
'constraint_errors' => null,
'adapter_action' => $action,
'elements' => $elements,
'error_message' => $request->query->get('error'),
'notice_message' => $request->query->get('notice'),
);
$params = array_merge($params, $route_params);
$template = 'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/' . $element_type . '_' . $action . ($destination ? '_' . $destination : '') . '.html.twig';
return $app['twig']->render($template, $params);
}
public function doPostAction(Application $app, Request $request, $account_id, $action, $element_type)
{
$account = \Bridge_Account::load_account($app, $account_id);
$this->requireConnection($app, $account);
$elements = $request->request->get('elements_list', array());
$elements = is_array($elements) ? $elements : explode(';', $elements);
$destination = $request->request->get('destination');
$class = $account->get_api()->get_connector()->get_object_class_from_type($element_type);
$html = '';
switch ($action) {
case 'modify':
if (count($elements) != 1) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?elements_list=' . implode(';', $elements) . '&error=' . _('Vous ne pouvez pas editer plusieurs elements simultanement'));
}
try {
foreach ($elements as $element_id) {
$datas = $account->get_api()->get_connector()->get_update_datas($request);
$errors = $account->get_api()->get_connector()->check_update_constraints($datas);
}
if (count($errors) > 0) {
$params = array(
'element' => $account->get_api()->get_element_from_id($element_id, $element_type),
'account' => $account,
'destination' => $destination,
'element_type' => $element_type,
'action' => $action,
'elements' => $elements,
'adapter_action' => $action,
'error_message' => _('Request contains invalid datas'),
'constraint_errors' => $errors,
'notice_message' => $request->request->get('notice'),
);
$template = 'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/' . $element_type . '_' . $action . ($destination ? '_' . $destination : '') . '.html.twig';
return $app['twig']->render($template, $params);
}
foreach ($elements as $element_id) {
$datas = $account->get_api()->get_connector()->get_update_datas($request);
$account->get_api()->update_element($element_type, $element_id, $datas);
}
} catch (\Exception $e) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?elements_list[]=' . $element_id . '&error=' . get_class($e) . ' : ' . $e->getMessage());
}
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/?page=&update=success#anchor');
case 'createcontainer':
try {
$container_type = $request->request->get('f_container_type');
$account->get_api()->create_container($container_type, $request);
} catch (\Exception $e) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . ' : ' . $e->getMessage());
}
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/?page=&update=success#anchor');
case 'moveinto':
try {
$container_id = $request->request->get('container_id');
foreach ($elements as $element_id) {
$account->get_api()->add_element_to_container($element_type, $element_id, $destination, $container_id);
}
} catch (\Exception $e) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . ' : ' . $e->getMessage());
}
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-containers/' . $destination . '/?page=&update=success#anchor');
case 'deleteelement':
try {
foreach ($elements as $element_id) {
$account->get_api()->delete_object($element_type, $element_id);
}
} catch (\Exception $e) {
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . $e->getMessage());
}
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/');
default:
throw new \Exception('Unknown action');
break;
}
return new Response($html);
}
public function doGetUpload(Application $app, Request $request)
{
$account = \Bridge_Account::load_account($app, $request->query->get('account_id'));
$this->requireConnection($app, $account);
$route = new RecordHelper\Bridge($app, $request);
$route->grep_records($account->get_api()->acceptable_records());
$params = array(
'route' => $route,
'account' => $account,
'error_message' => $request->query->get('error'),
'notice_message' => $request->query->get('notice'),
'constraint_errors' => null,
'adapter_action' => 'upload',
);
return $app['twig']->render(
'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/upload.html.twig', $params
);
}
public function doPostUpload(Application $app, Request $request)
{
$errors = array();
$account = \Bridge_Account::load_account($app, $request->request->get('account_id'));
$this->requireConnection($app, $account);
$route = new RecordHelper\Bridge($app, $request);
$route->grep_records($account->get_api()->acceptable_records());
$connector = $account->get_api()->get_connector();
// check constraints
foreach ($route->get_elements() as $record) {
$datas = $connector->get_upload_datas($request, $record);
$errors = array_merge($errors, $connector->check_upload_constraints($datas, $record));
}
if (count($errors) > 0) {
$params = array(
'route' => $route,
'account' => $account,
'error_message' => _('Request contains invalid datas'),
'constraint_errors' => $errors,
'notice_message' => $request->request->get('notice'),
'adapter_action' => 'upload',
);
return $app['twig']->render('prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/upload.html.twig', $params);
}
foreach ($route->get_elements() as $record) {
$datas = $connector->get_upload_datas($request, $record);
$title = isset($datas["title"]) ? $datas["title"] : '';
$default_type = $connector->get_default_element_type();
\Bridge_Element::create($app, $account, $record, $title, \Bridge_Element::STATUS_PENDING, $default_type, $datas);
}
return $app->redirect('/prod/bridge/adapter/' . $account->get_id() . '/load-records/?notice=' . sprintf(_('%d elements en attente'), count($route->get_elements())));
}
} }

View File

@@ -15,6 +15,7 @@ use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class DoDownload implements ControllerProviderInterface class DoDownload implements ControllerProviderInterface
{ {
@@ -91,11 +92,7 @@ class DoDownload implements ControllerProviderInterface
*/ */
public function prepareDownload(Application $app, Request $request, $token) public function prepareDownload(Application $app, Request $request, $token)
{ {
try { $datas = $app['tokens']->helloToken($token);
$datas = $app['tokens']->helloToken($token);
} catch (\Exception_NotFound $e) {
$app->abort(404, 'Invalid token');
}
if (false === $list = @unserialize((string) $datas['datas'])) { if (false === $list = @unserialize((string) $datas['datas'])) {
$app->abort(500, 'Invalid datas'); $app->abort(500, 'Invalid datas');
@@ -140,11 +137,7 @@ class DoDownload implements ControllerProviderInterface
*/ */
public function downloadDocuments(Application $app, Request $request, $token) public function downloadDocuments(Application $app, Request $request, $token)
{ {
try { $datas = $app['tokens']->helloToken($token);
$datas = $app['tokens']->helloToken($token);
} catch (\Exception_NotFound $e) {
$app->abort(404, 'Invalid token');
}
if (false === $list = @unserialize((string) $datas['datas'])) { if (false === $list = @unserialize((string) $datas['datas'])) {
$app->abort(500, 'Invalid datas'); $app->abort(500, 'Invalid datas');
@@ -160,7 +153,7 @@ class DoDownload implements ControllerProviderInterface
$mime = $subdef['mime']; $mime = $subdef['mime'];
$list['complete'] = true; $list['complete'] = true;
} else { } else {
$exportFile = __DIR__ . '/../../../../../tmp/download/' . $datas['value'] . '.zip'; $exportFile = $app['root.path'] . '/tmp/download/' . $datas['value'] . '.zip';
$mime = 'application/zip'; $mime = 'application/zip';
} }
@@ -202,7 +195,7 @@ class DoDownload implements ControllerProviderInterface
{ {
try { try {
$datas = $app['tokens']->helloToken($token); $datas = $app['tokens']->helloToken($token);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
return $app->json(array( return $app->json(array(
'success' => false, 'success' => false,
'message' => 'Invalid token' 'message' => 'Invalid token'
@@ -225,7 +218,7 @@ class DoDownload implements ControllerProviderInterface
$app, $app,
$token, $token,
$list, $list,
sprintf('%s/../../../../../tmp/download/%s.zip', __DIR__, $datas['value']) // Dest file sprintf($app['root.path'] . '/tmp/download/%s.zip', $datas['value']) // Dest file
); );
return $app->json(array( return $app->json(array(

View File

@@ -16,6 +16,8 @@ use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -79,7 +81,7 @@ class Feed implements ControllerProviderInterface
$entry = \Feed_Entry_Adapter::load_from_id($app, $id); $entry = \Feed_Entry_Adapter::load_from_id($app, $id);
if (!$entry->is_publisher($app['authentication']->getUser())) { if (!$entry->is_publisher($app['authentication']->getUser())) {
throw new \Exception_UnauthorizedAction(); throw new AccessDeniedHttpException();
} }
$feeds = \Feed_Collection::load_all($app, $app['authentication']->getUser()); $feeds = \Feed_Collection::load_all($app, $app['authentication']->getUser());
@@ -102,7 +104,7 @@ class Feed implements ControllerProviderInterface
$entry = \Feed_Entry_Adapter::load_from_id($app, $id); $entry = \Feed_Entry_Adapter::load_from_id($app, $id);
if (!$entry->is_publisher($app['authentication']->getUser())) { if (!$entry->is_publisher($app['authentication']->getUser())) {
throw new \Exception_UnauthorizedAction(); throw new AccessDeniedHttpException();
} }
$title = $request->request->get('title'); $title = $request->request->get('title');
@@ -120,12 +122,12 @@ class Feed implements ControllerProviderInterface
if ($current_feed_id != $new_feed_id) { if ($current_feed_id != $new_feed_id) {
try { try {
$new_feed = \Feed_Adapter::load_with_user($app, $app['authentication']->getUser(), $new_feed_id); $new_feed = \Feed_Adapter::load_with_user($app, $app['authentication']->getUser(), $new_feed_id);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
throw new \Exception_Forbidden('You have no access to this feed'); throw new AccessDeniedHttpException('You have no access to this feed');
} }
if (!$new_feed->is_publisher($app['authentication']->getUser())) { if (!$new_feed->is_publisher($app['authentication']->getUser())) {
throw new \Exception_Forbidden('You are not publisher of this feed'); throw new AccessDeniedHttpException('You are not publisher of this feed');
} }
$entry->set_feed($new_feed); $entry->set_feed($new_feed);
@@ -151,10 +153,10 @@ class Feed implements ControllerProviderInterface
} catch (\Exception_Feed_EntryNotFound $e) { } catch (\Exception_Feed_EntryNotFound $e) {
$app['phraseanet.appbox']->get_connection()->rollBack(); $app['phraseanet.appbox']->get_connection()->rollBack();
$datas['message'] = _('Feed entry not found'); $datas['message'] = _('Feed entry not found');
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$app['phraseanet.appbox']->get_connection()->rollBack(); $app['phraseanet.appbox']->get_connection()->rollBack();
$datas['message'] = _('Feed not found'); $datas['message'] = _('Feed not found');
} catch (\Exception_Forbidden $e) { } catch (AccessDeniedHttpException $e) {
$app['phraseanet.appbox']->get_connection()->rollBack(); $app['phraseanet.appbox']->get_connection()->rollBack();
$datas['message'] = _('You are not authorized to access this feed'); $datas['message'] = _('You are not authorized to access this feed');
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -178,7 +180,7 @@ class Feed implements ControllerProviderInterface
if (!$entry->is_publisher($app['authentication']->getUser()) if (!$entry->is_publisher($app['authentication']->getUser())
&& $entry->get_feed()->is_owner($app['authentication']->getUser()) === false) { && $entry->get_feed()->is_owner($app['authentication']->getUser()) === false) {
throw new \Exception_UnauthorizedAction(_('Action Forbidden : You are not the publisher')); throw new AccessDeniedHttpException(_('Action Forbidden : You are not the publisher'));
} }
$entry->delete(); $entry->delete();

View File

@@ -14,6 +14,8 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -31,13 +33,13 @@ class MustacheLoader implements ControllerProviderInterface
$template_name = $request->query->get('template'); $template_name = $request->query->get('template');
if (!preg_match('/^[a-zA-Z0-9-_]+$/', $template_name)) { if (!preg_match('/^[a-zA-Z0-9-_]+$/', $template_name)) {
throw new \Exception_BadRequest('Wrong template name : ' . $template_name); throw new BadRequestHttpException('Wrong template name : ' . $template_name);
} }
$template_path = realpath(__DIR__ . '/../../../../../templates/web/Mustache/Prod/' . $template_name . '.Mustache.html'); $template_path = realpath(__DIR__ . '/../../../../../templates/web/Mustache/Prod/' . $template_name . '.Mustache.html');
if (!file_exists($template_path)) { if (!file_exists($template_path)) {
throw new \Exception_NotFound('Template does not exists : ' . $template_path); throw new NotFoundHttpException('Template does not exists : ' . $template_path);
} }
return new \Symfony\Component\HttpFoundation\Response(file_get_contents($template_path)); return new \Symfony\Component\HttpFoundation\Response(file_get_contents($template_path));

View File

@@ -255,11 +255,7 @@ class Order implements ControllerProviderInterface
*/ */
public function displayOneOrder(Application $app, Request $request, $order_id) public function displayOneOrder(Application $app, Request $request, $order_id)
{ {
try { $order = new \set_order($app, $order_id);
$order = new \set_order($app, $order_id);
} catch (\Exception_NotFound $e) {
$app->abort(404);
}
return $app['twig']->render('prod/orders/order_item.html.twig', array( return $app['twig']->render('prod/orders/order_item.html.twig', array(
'order' => $order 'order' => $order
@@ -278,11 +274,7 @@ class Order implements ControllerProviderInterface
{ {
$success = false; $success = false;
try { $order = new \set_order($app, $order_id);
$order = new \set_order($app, $order_id);
} catch (\Exception_NotFound $e) {
$app->abort(404);
}
try { try {
$order->send_elements($app, $request->request->get('elements', array()), !!$request->request->get('force', false)); $order->send_elements($app, $request->request->get('elements', array()), !!$request->request->get('force', false));
@@ -317,11 +309,7 @@ class Order implements ControllerProviderInterface
{ {
$success = false; $success = false;
try { $order = new \set_order($app, $order_id);
$order = new \set_order($app, $order_id);
} catch (\Exception_NotFound $e) {
$app->abort(404);
}
try { try {
$order->deny_elements($request->request->get('elements', array())); $order->deny_elements($request->request->get('elements', array()));

View File

@@ -17,6 +17,7 @@ use Alchemy\Phrasea\Helper\Record as RecordHelper;
use Alchemy\Phrasea\Controller\Exception as ControllerException; use Alchemy\Phrasea\Controller\Exception as ControllerException;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -370,7 +371,7 @@ class Push implements ControllerProviderInterface
try { try {
$Participant = $Validation->getParticipant($participant_user, $app); $Participant = $Validation->getParticipant($participant_user, $app);
continue; continue;
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
} }

View File

@@ -32,7 +32,6 @@ class Root implements ControllerProviderInterface
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) { $controllers->before(function(Request $request) use ($app) {
if (!$app['authentication']->isAuthenticated() && null !== $request->query->get('nolog')) { if (!$app['authentication']->isAuthenticated() && null !== $request->query->get('nolog')) {
return $app->redirectPath('login_authenticate_as_guest'); return $app->redirectPath('login_authenticate_as_guest');
} }

View File

@@ -17,6 +17,7 @@ use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
* *
@@ -43,7 +44,7 @@ class Story implements ControllerProviderInterface
$collection = \collection::get_from_base_id($app, $request->request->get('base_id')); $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
if (!$app['authentication']->getUser()->ACL()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
throw new \Exception_Forbidden('You can not create a story on this collection'); throw new AccessDeniedHttpException('You can not create a story on this collection');
} }
$Story = \record_adapter::createStory($app, $collection); $Story = \record_adapter::createStory($app, $collection);
@@ -121,7 +122,7 @@ class Story implements ControllerProviderInterface
$Story = new \record_adapter($app, $sbas_id, $record_id); $Story = new \record_adapter($app, $sbas_id, $record_id);
if (!$app['authentication']->getUser()->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) if (!$app['authentication']->getUser()->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
throw new \Exception_Forbidden('You can not add document to this Story'); throw new AccessDeniedHttpException('You can not add document to this Story');
$n = 0; $n = 0;
@@ -154,7 +155,7 @@ class Story implements ControllerProviderInterface
$record = new \record_adapter($app, $child_sbas_id, $child_record_id); $record = new \record_adapter($app, $child_sbas_id, $child_record_id);
if (!$app['authentication']->getUser()->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) if (!$app['authentication']->getUser()->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
throw new \Exception_Forbidden('You can not add document to this Story'); throw new AccessDeniedHttpException('You can not add document to this Story');
$Story->removeChild($record); $Story->removeChild($record);

View File

@@ -19,6 +19,8 @@ use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
* Upload controller collection * Upload controller collection
@@ -159,27 +161,27 @@ class Upload implements ControllerProviderInterface
); );
if (null === $request->files->get('files')) { if (null === $request->files->get('files')) {
throw new \Exception_BadRequest('Missing file parameter'); throw new BadRequestHttpException('Missing file parameter');
} }
if (count($request->files->get('files')) > 1) { if (count($request->files->get('files')) > 1) {
throw new \Exception_BadRequest('Upload is limited to 1 file per request'); throw new BadRequestHttpException('Upload is limited to 1 file per request');
} }
$base_id = $request->request->get('base_id'); $base_id = $request->request->get('base_id');
if (!$base_id) { if (!$base_id) {
throw new \Exception_BadRequest('Missing base_id parameter'); throw new BadRequestHttpException('Missing base_id parameter');
} }
if (!$app['authentication']->getUser()->ACL()->has_right_on_base($base_id, 'canaddrecord')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_base($base_id, 'canaddrecord')) {
throw new \Exception_Forbidden('User is not allowed to add record on this collection'); throw new AccessDeniedHttpException('User is not allowed to add record on this collection');
} }
$file = current($request->files->get('files')); $file = current($request->files->get('files'));
if (!$file->isValid()) { if (!$file->isValid()) {
throw new \Exception_BadRequest('Uploaded file is invalid'); throw new BadRequestHttpException('Uploaded file is invalid');
} }
try { try {

View File

@@ -19,6 +19,7 @@ use Silex\ControllerProviderInterface;
use Alchemy\Phrasea\Controller\Exception as ControllerException; use Alchemy\Phrasea\Controller\Exception as ControllerException;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
/** /**
* *
@@ -477,9 +478,9 @@ class UsrLists implements ControllerProviderInterface
); );
if (!$app['request']->request->get('role')) if (!$app['request']->request->get('role'))
throw new \Exception_BadRequest('Missing role parameter'); throw new BadRequestHttpException('Missing role parameter');
elseif (!in_array($app['request']->request->get('role'), $availableRoles)) elseif (!in_array($app['request']->request->get('role'), $availableRoles))
throw new \Exception_BadRequest('Role is invalid'); throw new BadRequestHttpException('Role is invalid');
try { try {
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');

View File

@@ -16,6 +16,9 @@ use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Alchemy\Phrasea\Helper\WorkZone as WorkzoneHelper; use Alchemy\Phrasea\Helper\WorkZone as WorkzoneHelper;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -121,7 +124,7 @@ class WorkZone implements ControllerProviderInterface
public function attachStories(Application $app, Request $request) public function attachStories(Application $app, Request $request)
{ {
if (!$request->request->get('stories')) { if (!$request->request->get('stories')) {
throw new \Exception_BadRequest(); throw new BadRequestHttpException('Missing parameters stories');
} }
$StoryWZRepo = $app['EM']->getRepository('\Entities\StoryWZ'); $StoryWZRepo = $app['EM']->getRepository('\Entities\StoryWZ');
@@ -139,7 +142,7 @@ class WorkZone implements ControllerProviderInterface
} }
if (!$app['authentication']->getUser()->ACL()->has_access_to_base($Story->get_base_id())) { if (!$app['authentication']->getUser()->ACL()->has_access_to_base($Story->get_base_id())) {
throw new \Exception_Forbidden('You do not have access to this Story'); throw new AccessDeniedHttpException('You do not have access to this Story');
} }
if ($StoryWZRepo->findUserStory($app, $app['authentication']->getUser(), $Story)) { if ($StoryWZRepo->findUserStory($app, $app['authentication']->getUser(), $Story)) {
@@ -205,7 +208,7 @@ class WorkZone implements ControllerProviderInterface
$StoryWZ = $repository->findUserStory($app, $app['authentication']->getUser(), $Story); $StoryWZ = $repository->findUserStory($app, $app['authentication']->getUser(), $Story);
if (!$StoryWZ) { if (!$StoryWZ) {
throw new \Exception_NotFound('Story not found'); throw new NotFoundHttpException('Story not found');
} }
$app['EM']->remove($StoryWZ); $app['EM']->remove($StoryWZ);

View File

@@ -15,6 +15,7 @@ use Entities\Basket;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class RecordsRequest extends ArrayCollection class RecordsRequest extends ArrayCollection
{ {
@@ -223,7 +224,7 @@ class RecordsRequest extends ArrayCollection
$record = new \record_adapter($app, (int) $basrec[0], (int) $basrec[1]); $record = new \record_adapter($app, (int) $basrec[0], (int) $basrec[1]);
$received[$record->get_serialize_key()] = $record; $received[$record->get_serialize_key()] = $record;
unset($record); unset($record);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
continue; continue;
} }
} }

View File

@@ -22,6 +22,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Account implements ControllerProviderInterface class Account implements ControllerProviderInterface
{ {
@@ -221,7 +222,7 @@ class Account implements ControllerProviderInterface
); );
$account->set_revoked((bool) $request->query->get('revoke'), false); $account->set_revoked((bool) $request->query->get('revoke'), false);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$error = true; $error = true;
} }

View File

@@ -16,6 +16,7 @@ use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -189,7 +190,7 @@ class Developers implements ControllerProviderInterface
try { try {
$clientApp = new \API_OAuth2_Application($app, $id); $clientApp = new \API_OAuth2_Application($app, $id);
$clientApp->delete(); $clientApp->delete();
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$error = true; $error = true;
} }
@@ -220,7 +221,7 @@ class Developers implements ControllerProviderInterface
} else { } else {
$error = true; $error = true;
} }
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$error = true; $error = true;
} }
@@ -283,7 +284,7 @@ class Developers implements ControllerProviderInterface
try { try {
$clientApp = new \API_OAuth2_Application($app, $id); $clientApp = new \API_OAuth2_Application($app, $id);
$clientApp->set_grant_password((bool) $request->request->get('grant', false)); $clientApp->set_grant_password((bool) $request->request->get('grant', false));
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$error = true; $error = true;
} }
@@ -368,7 +369,7 @@ class Developers implements ControllerProviderInterface
{ {
try { try {
$client = new \API_OAuth2_Application($app, $id); $client = new \API_OAuth2_Application($app, $id);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$app->abort(404); $app->abort(404);
} }

View File

@@ -474,7 +474,7 @@ class Login implements ControllerProviderInterface
try { try {
$datas = $app['tokens']->helloToken($code); $datas = $app['tokens']->helloToken($code);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$app->addFlash('error', _('Invalid unlock link.')); $app->addFlash('error', _('Invalid unlock link.'));
return $app->redirectPath('homepage'); return $app->redirectPath('homepage');
@@ -795,7 +795,7 @@ class Login implements ControllerProviderInterface
try { try {
$token = $this->app['tokens']->getValidationToken($participantId, $basketId); $token = $this->app['tokens']->getValidationToken($participantId, $basketId);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
continue; continue;
} }

View File

@@ -0,0 +1,75 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
class ApiExceptionHandlerSubscriber implements EventSubscriberInterface
{
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::EXCEPTION => array('onSilexError', 0),
);
}
public function onSilexError(GetResponseForExceptionEvent $event)
{
$headers = array();
$e = $event->getException();
if ($e instanceof \API_V1_exception_methodnotallowed) {
$code = \API_V1_result::ERROR_METHODNOTALLOWED;
} elseif ($e instanceof MethodNotAllowedHttpException) {
$code = \API_V1_result::ERROR_METHODNOTALLOWED;
} elseif ($e instanceof \API_V1_exception_badrequest) {
$code = \API_V1_result::ERROR_BAD_REQUEST;
} elseif ($e instanceof \API_V1_exception_forbidden) {
$code = \API_V1_result::ERROR_FORBIDDEN;
} elseif ($e instanceof \API_V1_exception_unauthorized) {
$code = \API_V1_result::ERROR_UNAUTHORIZED;
} elseif ($e instanceof \API_V1_exception_internalservererror) {
$code = \API_V1_result::ERROR_INTERNALSERVERERROR;
} elseif ($e instanceof NotFoundHttpException) {
$code = \API_V1_result::ERROR_NOTFOUND;
} else {
$code = \API_V1_result::ERROR_INTERNALSERVERERROR;
}
if ($e instanceof HttpException) {
$headers = $e->getHeaders();
}
$result = $this->app['api']->get_error_message($event->getRequest(), $code, $e->getMessage());
$response = $result->get_response();
$response->headers->set('X-Status-Code', $result->get_http_code());
foreach ($headers as $key => $value) {
$response->headers->set($key, $value);
}
$event->setResponse($response);
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class ApiOauth2ErrorsSubscriber implements EventSubscriberInterface
{
private $handler;
public function __construct(ExceptionHandler $handler)
{
$this->handler = $handler;
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::EXCEPTION => array('onSilexError', 20),
);
}
public function onSilexError(GetResponseForExceptionEvent $event)
{
$request = $event->getRequest();
if (0 !== strpos($request->getPathInfo(), '/api/oauthv2')) {
return;
}
$e = $event->getException();
$code = 500;
$msg = _('Whoops, looks like something went wrong.');
$headers = array();
if ($e instanceof HttpExceptionInterface) {
$headers = $e->getHeaders();
$msg = $e->getMessage();
$code = $e->getStatusCode();
}
if (isset($headers['content-type']) && $headers['content-type'] == 'application/json') {
$msg = json_encode(array('msg' => $msg, 'code' => $code));
$event->setResponse(new Response($msg, $code, $headers));
} else {
$event->setResponse($this->handler->createResponseBasedOnRequest($event->getRequest(), $event->getException()));
}
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Alchemy\Phrasea\Application;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Response;
class BridgeExceptionSubscriber implements EventSubscriberInterface
{
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function onSilexError(GetResponseForExceptionEvent $event)
{
if (!$event->getException() instanceof \Bridge_Exception) {
return;
}
$e = $event->getException();
$request = $event->getRequest();
$params = array(
'account' => null,
'elements' => array(),
'message' => $e->getMessage(),
'error_message' => null,
'notice_message' => null,
'file' => $e->getFile(),
'line' => $e->getLine(),
'r_method' => $request->getMethod(),
'r_action' => $request->getRequestUri(),
'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all()),
);
if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) {
$params = array_replace($params, array('account' => $this->app['bridge.account']));
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
$params = array_replace($params, array('account' => $this->app['bridge.account']));
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
$params = array_replace($params, array('account' => $this->app['bridge.account']));
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
$params = array_replace($params, array('api' => $e->get_api()));
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200, array('X-Status-Code' => 200));
} else {
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, array('X-Status-Code' => 200));
}
$response->headers->set('Phrasea-StatusCode', 200);
$event->setResponse($response);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(KernelEvents::EXCEPTION => array('onSilexError', 20));
}
}

View File

@@ -0,0 +1,59 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Alchemy\Phrasea\Application;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
class DebuggerSubscriber implements EventSubscriberInterface
{
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array(
array('checkIp', 255),
),
);
}
public function checkIp(GetResponseEvent $event)
{
if (Application::ENV_DEV !== $this->app->getEnvironment()) {
return;
}
if (isset($this->app['phraseanet.configuration']['debugger'])
&& isset($this->app['phraseanet.configuration']['debugger']['allowed-ips'])) {
$allowedIps = $this->app['phraseanet.configuration']['debugger']['allowed-ips'];
$allowedIps = is_array($allowedIps) ? $allowedIps : array($allowedIps);
} else {
$allowedIps = array();
}
$ips = array_merge(array('127.0.0.1', 'fe80::1', '::1'), $allowedIps);
if (!in_array($event->getRequest()->getClientIp(), $ips)) {
throw new AccessDeniedHttpException('You are not allowed to access this file. Check index_dev.php for more information.');
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
class FirewallSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(
KernelEvents::RESPONSE => array('onKernelResponse', 0),
KernelEvents::EXCEPTION => array('onSilexError', 20),
);
}
public function onKernelResponse(FilterResponseEvent $event)
{
if ($event->getResponse()->headers->has('X-Phraseanet-Redirect')) {
$event->getResponse()->headers->remove('X-Phraseanet-Redirect');
}
}
public function onSilexError(GetResponseForExceptionEvent $event)
{
$e = $event->getException();
if ($e instanceof HttpExceptionInterface) {
$headers = $e->getHeaders();
if (isset($headers['X-Phraseanet-Redirect'])) {
$event->setResponse(new RedirectResponse($headers['X-Phraseanet-Redirect'], 302, array('X-Status-Code' => 302)));
}
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\JsonResponse;
class JsonRequestSubscriber implements EventSubscriberInterface
{
public function onSilexError(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$request = $event->getRequest();
if ((0 !== strpos($request->getPathInfo(), '/admin/')
|| 0 === strpos($request->getPathInfo(), '/admin/collection/')
|| 0 === strpos($request->getPathInfo(), '/admin/databox/'))
&& $request->getRequestFormat() == 'json') {
$datas = array(
'success' => false,
'message' => $exception->getMessage(),
);
$event->setResponse(new JsonResponse($datas, 200, array('X-Status-Code' => 200)));
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(KernelEvents::EXCEPTION => array('onSilexError', 10));
}
}

View File

@@ -15,7 +15,7 @@ use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Core\Event\LogoutEvent; use Alchemy\Phrasea\Core\Event\LogoutEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class Logout implements EventSubscriberInterface class LogoutSubscriber implements EventSubscriberInterface
{ {
public function onLogout(LogoutEvent $event) public function onLogout(LogoutEvent $event)
{ {

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class PhraseaExceptionHandlerSubscriber implements EventSubscriberInterface
{
protected $enabled;
protected $handler;
public function __construct(ExceptionHandler $handler)
{
$this->enabled = true;
$this->handler = $handler;
}
public function disable()
{
$this->enabled = false;
}
public function onSilexError(GetResponseForExceptionEvent $event)
{
if (!$this->enabled) {
return;
}
$event->setResponse($this->handler->createResponseBasedOnRequest($event->getRequest(), $event->getException()));
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(KernelEvents::EXCEPTION => array('onSilexError', 0));
}
}

View File

@@ -0,0 +1,143 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core;
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class PhraseaExceptionHandler extends SymfonyExceptionHandler
{
public function createResponseBasedOnRequest(Request $request, $exception)
{
return parent::createResponse($exception);
}
public function getContent(FlattenException $exception)
{
switch (true) {
case 404 === $exception->getStatusCode():
$title = _('Sorry, the page you are looking for could not be found.');
break;
case 403 === $exception->getStatusCode():
$title = _('Sorry, you do have access to the page you are looking for.');
break;
case 500 === $exception->getStatusCode():
$title = _('Whoops, looks like something went wrong.');
break;
case isset(Response::$statusTexts[$exception->getStatusCode()]):
$title = $exception->getStatusCode() . ' : ' . Response::$statusTexts[$exception->getStatusCode()];
break;
default:
$title = 'Whoops, looks like something went wrong.';
}
$content = parent::getContent($exception);
$start = strpos($content, '</h1>');
$content = '<div id="sf-resetcontent" class="sf-reset">'
. '<h1><span>' . $title . '</span></h1>'
. substr($content, $start);
return $content;
}
public function getStylesheet(FlattenException $exception)
{
$exception->getStatusCode();
switch ($exception->getStatusCode()) {
case 403:
$errorImg = '/skins/error-pages/403.png';
break;
case 404:
$errorImg = '/skins/error-pages/404.png';
break;
case 500:
$errorImg = '/skins/error-pages/500.png';
break;
default:
$errorImg = '/skins/error-pages/error.png';
break;
}
return <<<EOF
html {
background-image:url("/skins/error-pages/background.png");
background-repeat:repeat;
padding-top:0px;
}
body {
background-image:url("$errorImg");
background-repeat:no-repeat;
background-position:top center;
}
.sf-reset { font: 11px Arial, Verdana, sans-serif; color: #333 }
.sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; }
.sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }
.sf-reset .clear_fix { display:inline-block; }
.sf-reset * html .clear_fix { height:1%; }
.sf-reset .clear_fix { display:block; }
.sf-reset, .sf-reset .block { margin: auto }
.sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; }
.sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }
.sf-reset strong { font-weight:bold; }
.sf-reset a { color:#6c6159; }
.sf-reset a img { border:none; }
.sf-reset a:hover { text-decoration:underline; }
.sf-reset em { font-style:italic; }
.sf-reset h2 { font: 20px Arial, Verdana, sans-serif; color: #3C3C3B; }
.sf-reset h2 span {
background-color: #fff;
color: #333;
padding: 6px;
float: left;
margin-right: 10px;
color: #ED7060;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
}
.sf-reset .traces li { font-size:15px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; margin-top:15px; }
.sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;
border-bottom:1px solid #ccc;
border-right:1px solid #ccc;
border-left:1px solid #ccc;
}
.sf-reset .block_exception {
background-color:#ddd;
color: #333;
padding:20px;
-webkit-border-top-left-radius: 16px;
-webkit-border-top-right-radius: 16px;
-moz-border-radius-topleft: 16px;
-moz-border-radius-topright: 16px;
border-top-left-radius: 16px;
border-top-right-radius: 16px;
border-top:1px solid #ccc;
border-right:1px solid #ccc;
border-left:1px solid #ccc;
overflow: hidden;
word-wrap: break-word;
background-color: #719AAF;
}
.sf-reset li a { background:none; color:#868686; text-decoration:none; }
.sf-reset li a:hover { background:none; color:#313131; text-decoration:underline; }
.sf-reset ol { padding: 10px 0; }
.sf-reset h1 {
height:510px;
}
.sf-reset h1 span { color:#646363; display:inline-block; margin-top:430px; margin-left:190px; font-size:28px; }
EOF;
}
}

View File

@@ -22,7 +22,7 @@ class CacheServiceProvider implements ServiceProviderInterface
public function register(Application $app) public function register(Application $app)
{ {
$app['phraseanet.cache-registry'] = __DIR__ . '/../../../../../tmp/cache_registry.php'; $app['phraseanet.cache-registry'] = $app['root.path'] . '/tmp/cache_registry.php';
$app['phraseanet.cache-compiler'] = $app->share(function () { $app['phraseanet.cache-compiler'] = $app->share(function () {
return new Compiler(); return new Compiler();

View File

@@ -21,8 +21,8 @@ class JMSSerializerServiceProvider implements ServiceProviderInterface
{ {
public function register(Application $app) public function register(Application $app)
{ {
$app['serializer.cache-directory'] = __DIR__ . '/../../../../../tmp/serializer/'; $app['serializer.cache-directory'] = $app['root.path'] . '/tmp/serializer/';
$app['serializer.src_directory'] = __DIR__ . '/../../../../../vendor/jms/serializer/src/'; $app['serializer.src_directory'] = $app['root.path'] . '/vendor/jms/serializer/src/';
$app['serializer.metadata.annotation_reader'] = $app->share(function () use ($app) { $app['serializer.metadata.annotation_reader'] = $app->share(function () use ($app) {
AnnotationRegistry::registerAutoloadNamespace("JMS\Serializer\Annotation", $app['serializer.src_directory']); AnnotationRegistry::registerAutoloadNamespace("JMS\Serializer\Annotation", $app['serializer.src_directory']);

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Form\Constraint;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class PasswordToken extends Constraint class PasswordToken extends Constraint
{ {
@@ -32,7 +33,7 @@ class PasswordToken extends Constraint
{ {
try { try {
$data = $this->random->helloToken($token); $data = $this->random->helloToken($token);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
return false; return false;
} }

View File

@@ -44,7 +44,6 @@ class PhraseaRegisterForm extends AbstractType
), ),
)); ));
$builder->add('password', 'repeated', array( $builder->add('password', 'repeated', array(
'type' => 'password', 'type' => 'password',
'required' => true, 'required' => true,

View File

@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate; use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate;
use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Receiver;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
* *
@@ -644,7 +645,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
$template = \User_adapter::getInstance($this->request->get('template'), $this->app); $template = \User_adapter::getInstance($this->request->get('template'), $this->app);
if ($template->get_template_owner()->get_id() != $this->app['authentication']->getUser()->get_id()) { if ($template->get_template_owner()->get_id() != $this->app['authentication']->getUser()->get_id()) {
throw new \Exception_Forbidden('You are not the owner of the template'); throw new AccessDeniedHttpException('You are not the owner of the template');
} }
$base_ids = array_keys($this->app['authentication']->getUser()->ACL()->get_granted_base(array('canadmin'))); $base_ids = array_keys($this->app['authentication']->getUser()->ACL()->get_granted_base(array('canadmin')));

View File

@@ -12,6 +12,7 @@
namespace Entities; namespace Entities;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Kernel * Kernel
@@ -279,7 +280,7 @@ class ValidationSession
} }
} }
throw new \Exception_NotFound('Particpant not found' . $user->get_email()); throw new NotFoundHttpException('Particpant not found' . $user->get_email());
} }
/** /**
* @var integer $initiator * @var integer $initiator
@@ -380,7 +381,7 @@ class ValidationSession
public function addParticipant(\Entities\ValidationParticipant $participants) public function addParticipant(\Entities\ValidationParticipant $participants)
{ {
$this->participants[] = $participants; $this->participants[] = $participants;
return $this; return $this;
} }

View File

@@ -4,6 +4,7 @@ namespace Repositories;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Entities; use Entities;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* BasketElementRepository * BasketElementRepository
@@ -38,7 +39,7 @@ class BasketElementRepository extends EntityRepository
/* @var $element \Entities\BasketElement */ /* @var $element \Entities\BasketElement */
if (null === $element) { if (null === $element) {
throw new \Exception_NotFound(_('Element is not found')); throw new NotFoundHttpException(_('Element is not found'));
} }
return $element; return $element;

View File

@@ -14,6 +14,8 @@ namespace Repositories;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Entities; use Entities;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -120,8 +122,8 @@ class BasketRepository extends EntityRepository
/** /**
* Find a basket specified by his basket_id and his owner * Find a basket specified by his basket_id and his owner
* *
* @throws \Exception_NotFound * @throws NotFoundHttpException
* @throws \Exception_Forbidden * @throws AccessDeniedHttpException
* @param type $basket_id * @param type $basket_id
* @param \User_Adapter $user * @param \User_Adapter $user
* @return \Entities\Basket * @return \Entities\Basket
@@ -140,7 +142,7 @@ class BasketRepository extends EntityRepository
/* @var $basket \Entities\Basket */ /* @var $basket \Entities\Basket */
if (null === $basket) { if (null === $basket) {
throw new \Exception_NotFound(_('Basket is not found')); throw new NotFoundHttpException(_('Basket is not found'));
} }
if ($basket->getOwner($app)->get_id() != $user->get_id()) { if ($basket->getOwner($app)->get_id() != $user->get_id()) {
@@ -155,7 +157,7 @@ class BasketRepository extends EntityRepository
} }
} }
if ( ! $participant) { if ( ! $participant) {
throw new \Exception_Forbidden(_('You have not access to this basket')); throw new AccessDeniedHttpException(_('You have not access to this basket'));
} }
} }

View File

@@ -4,6 +4,8 @@ namespace Repositories;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* StoryWZRepository * StoryWZRepository
@@ -30,7 +32,7 @@ class StoryWZRepository extends EntityRepository
foreach ($stories as $key => $story) { foreach ($stories as $key => $story) {
try { try {
$story->getRecord($app)->get_title(); $story->getRecord($app)->get_title();
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$this->getEntityManager()->remove($story); $this->getEntityManager()->remove($story);
unset($stories[$key]); unset($stories[$key]);
} }
@@ -67,16 +69,16 @@ class StoryWZRepository extends EntityRepository
if ($story) { if ($story) {
try { try {
$story->getRecord($app)->get_title(); $story->getRecord($app)->get_title();
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$this->getEntityManager()->remove($story); $this->getEntityManager()->remove($story);
throw new \Exception_NotFound('Story not found'); throw new NotFoundHttpException('Story not found');
} }
if ($story->getUser($app)->get_id() !== $user->get_id()) { if ($story->getUser($app)->get_id() !== $user->get_id()) {
throw new \Exception_Forbidden('You have not access to ths story'); throw new AccessDeniedHttpException('You have not access to ths story');
} }
} else { } else {
throw new \Exception_NotFound('Story not found'); throw new NotFoundHttpException('Story not found');
} }
return $story; return $story;
@@ -95,7 +97,7 @@ class StoryWZRepository extends EntityRepository
if ($story) { if ($story) {
try { try {
$record = $story->getRecord($app); $record = $story->getRecord($app);
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$this->getEntityManager()->remove($story); $this->getEntityManager()->remove($story);
$this->getEntityManager()->flush(); $this->getEntityManager()->flush();
$story = null; $story = null;
@@ -121,7 +123,7 @@ class StoryWZRepository extends EntityRepository
foreach ($stories as $key => $story) { foreach ($stories as $key => $story) {
try { try {
$record = $story->getRecord(); $record = $story->getRecord();
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$this->getEntityManager()->remove($story); $this->getEntityManager()->remove($story);
$this->getEntityManager()->flush(); $this->getEntityManager()->flush();
unset($stories[$key]); unset($stories[$key]);
@@ -145,7 +147,7 @@ class StoryWZRepository extends EntityRepository
foreach ($stories as $key => $story) { foreach ($stories as $key => $story) {
try { try {
$record = $story->getRecord(); $record = $story->getRecord();
} catch (\Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$this->getEntityManager()->remove($story); $this->getEntityManager()->remove($story);
$this->getEntityManager()->flush(); $this->getEntityManager()->flush();
unset($stories[$key]); unset($stories[$key]);

View File

@@ -3,6 +3,8 @@
namespace Repositories; namespace Repositories;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* UsrListEntryRepository * UsrListEntryRepository
@@ -40,12 +42,12 @@ class UsrListEntryRepository extends EntityRepository
$entry = $this->find($entry_id); $entry = $this->find($entry_id);
if ( ! $entry) { if ( ! $entry) {
throw new \Exception_NotFound('Entry not found'); throw new NotFoundHttpException('Entry not found');
} }
/* @var $entry \Entities\UsrListEntry */ /* @var $entry \Entities\UsrListEntry */
if ($entry->getList()->getId() != $list->getId()) { if ($entry->getList()->getId() != $list->getId()) {
throw new \Exception_Forbidden('Entry mismatch list'); throw new AccessDeniedHttpException('Entry mismatch list');
} }
return $entry; return $entry;
@@ -68,7 +70,7 @@ class UsrListEntryRepository extends EntityRepository
$entry = $query->getResult(); $entry = $query->getResult();
if ( ! $entry) { if ( ! $entry) {
throw new \Exception_NotFound('Entry not found'); throw new NotFoundHttpException('Entry not found');
} }
return $query->getSingleResult(); return $query->getSingleResult();

View File

@@ -3,6 +3,8 @@
namespace Repositories; namespace Repositories;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* UsrListOwnerRepository * UsrListOwnerRepository
@@ -26,11 +28,11 @@ class UsrListOwnerRepository extends EntityRepository
/* @var $owner \Entities\UsrListOwner */ /* @var $owner \Entities\UsrListOwner */
if (null === $owner) { if (null === $owner) {
throw new \Exception_NotFound(_('Owner is not found')); throw new NotFoundHttpException(_('Owner is not found'));
} }
if ( ! $owner->getList()->getid() != $list->getId()) { if ( ! $owner->getList()->getid() != $list->getId()) {
throw new \Exception_Forbidden(_('Owner and list mismatch')); throw new AccessDeniedHttpException(_('Owner and list mismatch'));
} }
return $owner; return $owner;
@@ -61,7 +63,7 @@ class UsrListOwnerRepository extends EntityRepository
/* @var $owner \Entities\UsrListOwner */ /* @var $owner \Entities\UsrListOwner */
if (null === $owner) { if (null === $owner) {
throw new \Exception_NotFound(_('Owner is not found')); throw new NotFoundHttpException(_('Owner is not found'));
} }
return $owner; return $owner;

View File

@@ -4,6 +4,8 @@ namespace Repositories;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* UsrListRepository * UsrListRepository
@@ -49,11 +51,11 @@ class UsrListRepository extends EntityRepository
/* @var $basket \Entities\UsrList */ /* @var $basket \Entities\UsrList */
if (null === $list) { if (null === $list) {
throw new \Exception_NotFound(_('List is not found')); throw new NotFoundHttpException(_('List is not found'));
} }
if ( ! $list->hasAccess($user, $app)) { if ( ! $list->hasAccess($user, $app)) {
throw new \Exception_Forbidden(_('You have not access to this list')); throw new AccessDeniedHttpException(_('You have not access to this list'));
} }
return $list; return $list;

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -179,7 +180,7 @@ class API_OAuth2_Account
if (! $this->token) { if (! $this->token) {
try { try {
$this->token = new API_OAuth2_Token($this->app['phraseanet.appbox'], $this); $this->token = new API_OAuth2_Token($this->app['phraseanet.appbox'], $this);
} catch (Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$this->token = API_OAuth2_Token::create($this->app['phraseanet.appbox'], $this); $this->token = API_OAuth2_Token::create($this->app['phraseanet.appbox'], $this);
} }
} }
@@ -263,7 +264,7 @@ class API_OAuth2_Account
$stmt->closeCursor(); $stmt->closeCursor();
if (! $row) { if (! $row) {
throw new Exception_NotFound(); throw new NotFoundHttpException('Account nof found.');
} }
return new self($app, $row['api_account_id']); return new self($app, $row['api_account_id']);

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -149,7 +150,7 @@ class API_OAuth2_Application
$stmt->execute(array(':application_id' => $this->id)); $stmt->execute(array(':application_id' => $this->id));
if (0 === $stmt->rowCount()) { if (0 === $stmt->rowCount()) {
throw new \Exception_NotFound(sprintf('Application with id %d not found', $this->id)); throw new NotFoundHttpException(sprintf('Application with id %d not found', $this->id));
} }
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -546,7 +547,7 @@ class API_OAuth2_Application
$stmt->closeCursor(); $stmt->closeCursor();
if ( ! $row) if ( ! $row)
throw new Exception_NotFound(); throw new NotFoundHttpException('Application not found.');
return new API_OAuth2_Account($this->app, $row['api_account_id']); return new API_OAuth2_Account($this->app, $row['api_account_id']);
} }
@@ -659,7 +660,7 @@ class API_OAuth2_Application
$stmt->closeCursor(); $stmt->closeCursor();
if ( ! $row) if ( ! $row)
throw new Exception_NotFound(); throw new NotFoundHttpException('Client not found.');
return new self($app, $row['application_id']); return new self($app, $row['application_id']);
} }

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -44,7 +45,7 @@ class API_OAuth2_AuthCode
$stmt->closeCursor(); $stmt->closeCursor();
if ( ! $row) if ( ! $row)
throw new Exception_NotFound(); throw new NotFoundHttpException('Code not found');
$this->account_id = (int) $row['api_account_id']; $this->account_id = (int) $row['api_account_id'];
$this->redirect_uri = $row['redirect_uri']; $this->redirect_uri = $row['redirect_uri'];

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -78,7 +79,7 @@ class API_OAuth2_Token
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
if ( ! $row) if ( ! $row)
throw new Exception_NotFound(); throw new NotFoundHttpException('Account not found');
$stmt->closeCursor(); $stmt->closeCursor();
@@ -286,7 +287,7 @@ class API_OAuth2_Token
$stmt->closeCursor(); $stmt->closeCursor();
if ( ! $row) if ( ! $row)
throw new Exception_NotFound(); throw new NotFoundHttpException('Account not found');
$account = new API_OAuth2_Account($app, $row['api_account_id']); $account = new API_OAuth2_Account($app, $row['api_account_id']);

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Border\Attribute\Status; use Alchemy\Phrasea\Border\Attribute\Status;
use Alchemy\Phrasea\Border\Manager as BorderManager; use Alchemy\Phrasea\Border\Manager as BorderManager;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -1190,7 +1191,7 @@ class API_V1_adapter extends API_V1_Abstract
try { try {
$record = $databox->get_record($record_id); $record = $databox->get_record($record_id);
$result->set_datas(array('record' => $this->list_record($record))); $result->set_datas(array('record' => $this->list_record($record)));
} catch (Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('Record Not Found')); $result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('Record Not Found'));
} catch (Exception $e) { } catch (Exception $e) {
$result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured')); $result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured'));
@@ -1214,7 +1215,7 @@ class API_V1_adapter extends API_V1_Abstract
try { try {
$story = $databox->get_record($story_id); $story = $databox->get_record($story_id);
$result->set_datas(array('story' => $this->list_story($story))); $result->set_datas(array('story' => $this->list_story($story)));
} catch (Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('Story Not Found')); $result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('Story Not Found'));
} catch (Exception $e) { } catch (Exception $e) {
$result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured')); $result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured'));

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Bridge * @package Bridge
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Bridge_Exception_AccountNotFound extends Exception_NotFound class Bridge_Exception_AccountNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
* *
* @package Bridge * @package Bridge
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Bridge_Exception_ActionForbidden extends Exception_Forbidden class Bridge_Exception_ActionForbidden extends AccessDeniedHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Bridge * @package Bridge
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Bridge_Exception_ApiConnectorNotFound extends Exception_NotFound class Bridge_Exception_ApiConnectorNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Bridge * @package Bridge
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Bridge_Exception_ApiNotFound extends Exception_NotFound class Bridge_Exception_ApiNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Bridge * @package Bridge
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Bridge_Exception_ElementNotFound extends Exception_NotFound class Bridge_Exception_ElementNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Bridge * @package Bridge
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Bridge_Exception_TokenNotFound extends Exception_NotFound class Bridge_Exception_TokenNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -1,20 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_BadRequest extends Exception_Abstract
{
}

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Databox_CollectionNotFound extends Exception_NotFound class Exception_Databox_CollectionNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Databox_FieldNotFound extends Exception_NotFound class Exception_Databox_FieldNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Databox_SubdefNotFound extends Exception_NotFound class Exception_Databox_SubdefNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Databox_metadataDescriptionNotFound extends Exception_NotFound class Exception_Databox_metadataDescriptionNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_DataboxNotFound extends Exception_NotFound
{
}

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Feed_EntryNotFound extends Exception_NotFound class Exception_Feed_EntryNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Feed_ItemNotFound extends Exception_NotFound class Exception_Feed_ItemNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Feed_PublisherNotFound extends Exception_NotFound class Exception_Feed_PublisherNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_FeedNotFound extends Exception_NotFound
{
}

View File

@@ -1,20 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Forbidden extends Exception
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Media_Subdef_PermalinkNotFound extends Exception_Abstract
{
}

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Media_SubdefNotFound extends Exception_NotFound class Exception_Media_SubdefNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_NotAllowed extends Exception_Abstract
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_NotFound extends Exception_Abstract
{
}

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Record_AdapterNotFound extends Exception_NotFound class Exception_Record_AdapterNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -1,20 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_ServiceUnavailable extends Exception
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Session_AlreadyCreated extends Exception
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Session_BadSalinity extends Exception
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Session_Closed extends Exception
{
}

View File

@@ -9,13 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
* @package Exception * @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Exception_Session_LoggerNotFound extends Exception_NotFound class Exception_Session_LoggerNotFound extends NotFoundHttpException
{ {
} }

View File

@@ -1,32 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Session_MailLocked extends Exception
{
protected $usr_id;
public function __construct($usr_id = null, $message = null, $code = null, $previous = null)
{
$this->usr_id = $usr_id;
parent::__construct($message, $code, $previous);
}
public function get_usr_id()
{
return $this->usr_id;
}
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Session_NotAuthenticated extends Exception_NotAllowed
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Session_RequireCaptcha extends Exception
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Session_StorageClosed extends Exception_NotAllowed
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Session_WrongToken extends Exception
{
}

View File

@@ -1,20 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_Unauthorized extends Exception_Abstract
{
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Exception
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Exception_UnauthorizedAction extends Exception_Abstract
{
}

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -94,7 +95,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea
$stmt->closeCursor(); $stmt->closeCursor();
if (!$row) if (!$row)
throw new Exception_FeedNotFound (); throw new NotFoundHttpException('Feed not found');
$this->title = $row['title']; $this->title = $row['title'];
$this->subtitle = $row['subtitle']; $this->subtitle = $row['subtitle'];
@@ -464,7 +465,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea
return $feed; return $feed;
} }
throw new Exception_FeedNotFound(); throw new NotFoundHttpException('Feed not found');
} }
/** /**

View File

@@ -10,6 +10,8 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
* *
@@ -451,7 +453,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa
foreach ($rs as $item_id) { foreach ($rs as $item_id) {
try { try {
$items[] = new Feed_Entry_Item($this->app['phraseanet.appbox'], $this, $item_id); $items[] = new Feed_Entry_Item($this->app['phraseanet.appbox'], $this, $item_id);
} catch (Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
} }
} }
@@ -514,7 +516,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa
if ( ! $feed->is_public() && $feed->get_collection() instanceof Collection) { if ( ! $feed->is_public() && $feed->get_collection() instanceof Collection) {
if ( ! $publisher->get_user()->ACL()->has_access_to_base($feed->get_collection()->get_base_id())) { if ( ! $publisher->get_user()->ACL()->has_access_to_base($feed->get_collection()->get_base_id())) {
throw new Exception_Unauthorized("User has no rights to publish in current feed"); throw new AccessDeniedHttpException("User has no rights to publish in current feed");
} }
} }

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -74,7 +75,7 @@ class Feed_Token
$stmt->closeCursor(); $stmt->closeCursor();
if ( ! $row) if ( ! $row)
throw new Exception_FeedNotFound($token); throw new NotFoundHttpException('Feed not found.');
$this->feed_id = (int) $row['feed_id']; $this->feed_id = (int) $row['feed_id'];
$this->usr_id = (int) $row['usr_id']; $this->usr_id = (int) $row['usr_id'];

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -42,7 +43,7 @@ class Feed_TokenAggregate extends Feed_Token
$stmt->closeCursor(); $stmt->closeCursor();
if ( ! $row) if ( ! $row)
throw new Exception_FeedNotFound($token); throw new NotFoundHttpException('Feed not found.');
$this->usr_id = $row['usr_id']; $this->usr_id = $row['usr_id'];
$this->app = $app; $this->app = $app;

View File

@@ -15,6 +15,7 @@ use MediaAlchemyst\Specification\Image as ImageSpecification;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File as SymfoFile; use Symfony\Component\HttpFoundation\File\File as SymfoFile;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -436,7 +437,7 @@ class appbox extends base
foreach ($this->retrieve_sbas_ids() as $sbas_id) { foreach ($this->retrieve_sbas_ids() as $sbas_id) {
try { try {
$ret[$sbas_id] = new \databox($this->app, $sbas_id); $ret[$sbas_id] = new \databox($this->app, $sbas_id);
} catch (\Exception_DataboxNotFound $e) { } catch (NotFoundHttpException $e) {
} }
} }
@@ -476,7 +477,7 @@ class appbox extends base
$databoxes = $this->get_databoxes(); $databoxes = $this->get_databoxes();
if (!array_key_exists($sbas_id, $databoxes)) { if (!array_key_exists($sbas_id, $databoxes)) {
throw new Exception_DataboxNotFound('Databox `' . $sbas_id . '` not found'); throw new NotFoundHttpException('Databox `' . $sbas_id . '` not found');
} }
return $databoxes[$sbas_id]; return $databoxes[$sbas_id];

View File

@@ -12,6 +12,7 @@
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class databox extends base class databox extends base
{ {
@@ -115,7 +116,7 @@ class databox extends base
$connection_params = phrasea::sbas_params($this->app); $connection_params = phrasea::sbas_params($this->app);
if ( ! isset($connection_params[$sbas_id])) { if ( ! isset($connection_params[$sbas_id])) {
throw new Exception_DataboxNotFound(sprintf('databox %d not found', $sbas_id)); throw new NotFoundHttpException(sprintf('databox %d not found', $sbas_id));
} }
$this->host = $connection_params[$sbas_id]['host']; $this->host = $connection_params[$sbas_id]['host'];
@@ -147,7 +148,7 @@ class databox extends base
} }
if (!$row) { if (!$row) {
throw new Exception_DataboxNotFound(sprintf('databox %d not found', $sbas_id)); throw new NotFoundHttpException(sprintf('databox %d not found', $sbas_id));
} }
$this->ord = $row['ord']; $this->ord = $row['ord'];

View File

@@ -40,8 +40,8 @@ class module_console_systemClearCache extends Command
->exclude('.git') ->exclude('.git')
->exclude('.svn') ->exclude('.svn')
->in(array( ->in(array(
__DIR__ . '/../../../../tmp/cache_minify/', $this->container['root.path'] . '/tmp/cache_minify/',
__DIR__ . '/../../../../tmp/cache_twig/' $this->container['root.path'] . '/tmp/cache_twig/'
)); ));
$filesystem = new Filesystem(); $filesystem = new Filesystem();

View File

@@ -20,6 +20,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class module_console_taskState extends Command class module_console_taskState extends Command
{ {
@@ -80,7 +81,7 @@ class module_console_taskState extends Command
$task = $task_manager->getTask($task_id); $task = $task_manager->getTask($task_id);
$taskPID = $task->getPID(); $taskPID = $task->getPID();
$taskState = $task->getState(); $taskState = $task->getState();
} catch (Exception_NotFound $e) { } catch (NotFoundHttpException $e) {
$output->writeln($input->getOption('short') ? 'unknown_id' : $e->getMessage()); $output->writeln($input->getOption('short') ? 'unknown_id' : $e->getMessage());
return self::EXITCODE_TASK_UNKNOWN; return self::EXITCODE_TASK_UNKNOWN;

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