From 6aaa9ab38eaa8a85b45181ce9de595feed2fa397 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 27 Feb 2014 17:10:34 +0100 Subject: [PATCH] Add feed repository as a service --- .../Phrasea/Controller/Admin/Publications.php | 2 +- lib/Alchemy/Phrasea/Controller/Prod/Feed.php | 18 +++++++++--------- lib/Alchemy/Phrasea/Controller/Prod/Root.php | 2 +- lib/Alchemy/Phrasea/Controller/Root/Login.php | 2 +- .../Phrasea/Controller/Root/RSSFeeds.php | 4 ++-- .../Core/Provider/ORMServiceProvider.php | 3 +++ lib/Alchemy/Phrasea/Feed/Aggregate.php | 6 +++--- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Publications.php b/lib/Alchemy/Phrasea/Controller/Admin/Publications.php index ca97fa7fc7..01245d8c37 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Publications.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Publications.php @@ -34,7 +34,7 @@ class Publications implements ControllerProviderInterface }); $controllers->get('/list/', function (PhraseaApplication $app) { - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser( + $feeds = $app['repo.feeds']->getAllForUser( $app['acl']->get($app['authentication']->getUser()) ); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Feed.php b/lib/Alchemy/Phrasea/Controller/Prod/Feed.php index 56c7976d30..09c90a8d31 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Feed.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Feed.php @@ -34,7 +34,7 @@ class Feed implements ControllerProviderInterface $app['firewall']->addMandatoryAuthentication($controllers); $controllers->post('/requestavailable/', function (Application $app, Request $request) { - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser( + $feeds = $app['repo.feeds']->getAllForUser( $app['acl']->get($app['authentication']->getUser()) ); $publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']); @@ -43,7 +43,7 @@ class Feed implements ControllerProviderInterface }); $controllers->post('/entry/create/', function (Application $app, Request $request) { - $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($request->request->get('feed_id')); + $feed = $app['repo.feeds']->find($request->request->get('feed_id')); if (null === $feed) { $app->abort(404, "Feed not found"); @@ -101,7 +101,7 @@ class Feed implements ControllerProviderInterface throw new AccessDeniedHttpException(); } - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); + $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser())); $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', ['entry' => $entry, 'feeds' => $feeds]); @@ -136,7 +136,7 @@ class Feed implements ControllerProviderInterface $new_feed_id = $request->request->get('feed_id', $currentFeedId); if ($currentFeedId !== (int) $new_feed_id) { - $new_feed = $app['EM']->getRepository('Phraseanet:Feed')->find($new_feed_id); + $new_feed = $app['repo.feeds']->find($new_feed_id); if ($new_feed === null) { $app->abort(404, 'Feed not found'); @@ -203,7 +203,7 @@ class Feed implements ControllerProviderInterface $page = (int) $request->query->get('page'); $page = $page > 0 ? $page : 1; - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); + $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser())); $datas = $app['twig']->render('prod/feeds/feeds.html.twig', [ 'feeds' => $feeds, @@ -218,11 +218,11 @@ class Feed implements ControllerProviderInterface $page = (int) $request->query->get('page'); $page = $page > 0 ? $page : 1; - $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id); + $feed = $app['repo.feeds']->find($id); if (!$feed->isAccessible($app['authentication']->getUser(), $app)) { $app->abort(404, 'Feed not found'); } - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); + $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser())); $datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feed' => $feed, 'feeds' => $feeds, 'page' => $page]); @@ -234,7 +234,7 @@ class Feed implements ControllerProviderInterface $controllers->get('/subscribe/aggregated/', function (Application $app, Request $request) { $renew = ($request->query->get('renew') === 'true'); - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); + $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser())); $link = $app['feed.aggregate-link-generator']->generate(new Aggregate($app['EM'], $feeds), $app['authentication']->getUser(), @@ -255,7 +255,7 @@ class Feed implements ControllerProviderInterface $controllers->get('/subscribe/{id}/', function (Application $app, Request $request, $id) { $renew = ($request->query->get('renew') === 'true'); - $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id); + $feed = $app['repo.feeds']->find($id); if (!$feed->isAccessible($app['authentication']->getUser(), $app)) { $app->abort(404, 'Feed not found'); } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Root.php b/lib/Alchemy/Phrasea/Controller/Prod/Root.php index 3c96a27cb8..d91ba571dc 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Root.php @@ -71,7 +71,7 @@ class Root implements ControllerProviderInterface $cssfile = '000000'; } - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); + $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser())); $aggregate = Aggregate::createFromUser($app, $app['authentication']->getUser()); $thjslist = ""; diff --git a/lib/Alchemy/Phrasea/Controller/Root/Login.php b/lib/Alchemy/Phrasea/Controller/Root/Login.php index de847f99c7..54bcfee11a 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Login.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Login.php @@ -739,7 +739,7 @@ class Login implements ControllerProviderInterface $app->addFlash('error', $app->trans('login::erreur: No available connection - Please contact sys-admin')); } - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->findBy(['public' => true], ['updatedOn' => 'DESC']); + $feeds = $app['repo.feeds']->findBy(['public' => true], ['updatedOn' => 'DESC']); $form = $app->form(new PhraseaAuthenticationForm()); $form->setData([ diff --git a/lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php b/lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php index 2a3e8583b5..a9b122d3b1 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php +++ b/lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php @@ -25,7 +25,7 @@ class RSSFeeds implements ControllerProviderInterface $controllers = $app['controllers_factory']; $controllers->get('/feed/{id}/{format}/', function (Application $app, $id, $format) { - $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id); + $feed = $app['repo.feeds']->find($id); if (null === $feed) { $app->abort(404, 'Feed not found'); @@ -66,7 +66,7 @@ class RSSFeeds implements ControllerProviderInterface $user = $token->getUser(); - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($user)); + $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($user)); $aggregate = new Aggregate($app['EM'], $feeds, $token); diff --git a/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php index d7791e6436..7aef28c933 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php @@ -202,6 +202,9 @@ class ORMServiceProvider implements ServiceProviderInterface $app['repo.orders'] = $app->share(function (PhraseaApplication $app) { return $app['EM']->getRepository('Phraseanet:Order'); }); + $app['repo.feeds'] = $app->share(function (PhraseaApplication $app) { + return $app['EM']->getRepository('Phraseanet:Feed'); + }); $app['repo.feed-entries'] = $app->share(function (PhraseaApplication $app) { return $app['EM']->getRepository('Phraseanet:FeedEntry'); }); diff --git a/lib/Alchemy/Phrasea/Feed/Aggregate.php b/lib/Alchemy/Phrasea/Feed/Aggregate.php index dd0b456a07..a5f42e68e5 100644 --- a/lib/Alchemy/Phrasea/Feed/Aggregate.php +++ b/lib/Alchemy/Phrasea/Feed/Aggregate.php @@ -78,7 +78,7 @@ class Aggregate implements FeedInterface */ public static function createFromUser(Application $app, User $user) { - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($user)); + $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($user)); $token = $app['EM']->getRepository('Phraseanet:AggregateToken')->findOneBy(['user' => $user]); return new static($app['EM'], $feeds, $token); @@ -94,7 +94,7 @@ class Aggregate implements FeedInterface */ public static function create(Application $app, array $feed_ids) { - $feeds = $app['EM']->getRepository('Phraseanet:Feed')->findByIds($feed_ids); + $feeds = $app['repo.feeds']->findByIds($feed_ids); return new static($app, $feeds); } @@ -239,6 +239,6 @@ class Aggregate implements FeedInterface */ public static function getPublic(Application $app) { - return new static($app['EM'], $app['EM']->getRepository('Phraseanet:Feed')->findBy(['public' => true], ['updatedOn' => 'DESC'])); + return new static($app['EM'], $app['repo.feeds']->findBy(['public' => true], ['updatedOn' => 'DESC'])); } }