diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Publications.php b/lib/Alchemy/Phrasea/Controller/Admin/Publications.php index 48829ac11c..49c55fe43b 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Publications.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Publications.php @@ -38,7 +38,7 @@ class Publications implements ControllerProviderInterface $controllers->get('/list/', function(PhraseaApplication $app) { - $feeds = $app["EM"]->getRepository("Entities\Feed")->getAllForUser( + $feeds = $app['EM']->getRepository('Entities\Feed')->getAllForUser( $app['authentication']->getUser() ); @@ -54,11 +54,12 @@ class Publications implements ControllerProviderInterface $publisher->setFeed($feed); $publisher->setUsrId($app['authentication']->getUser()->get_id()); - $publisher->setOwner(true); + $publisher->setIsOwner(true); $feed->addPublisher($publisher); $feed->setTitle($request->request->get('title')); $feed->setSubtitle($request->request->get('subtitle')); + $feed->setIconUrl(false); if ($request->request->get('public') == '1') { $feed->setPublic(true); @@ -68,16 +69,16 @@ class Publications implements ControllerProviderInterface $publisher->setFeed($feed); - $app["EM"]->persist($feed); - $app["EM"]->persist($publisher); + $app['EM']->persist($feed); + $app['EM']->persist($publisher); - $app["EM"]->flush(); + $app['EM']->flush(); return $app->redirectPath('admin_feeds_list'); })->bind('admin_feeds_create'); $controllers->get('/feed/{id}/', function(PhraseaApplication $app, Request $request, $id) { - $feed = $app["EM"]->getRepository("Entities\Feed")->findOneBy(array("id" => $id)); + $feed = $app["EM"]->find('Entities\Feed', $id); return $app['twig'] ->render('admin/publications/fiche.html.twig', array('feed' => $feed, 'error' => $app['request']->query->get('error'))); @@ -87,27 +88,27 @@ class Publications implements ControllerProviderInterface $controllers->post('/feed/{id}/update/', function(PhraseaApplication $app, Request $request, $id) { - $feed = $app["EM"]->getRepository("Entities\Feed")->findOneBy(array("id" => $id)); + $feed = $app["EM"]->find('Entities\Feed', $id); try { $collection = \collection::get_from_base_id($app, $request->request->get('base_id')); } catch (\Exception $e) { $collection = null; } - if (null !== $request->request->get('title')) { - $feed->setTitle($request->request->get('title')); + if (null !== $title = $request->request->get('title')) { + $feed->setTitle($title); } - if (null !== $request->request->get('subtitle')) { - $feed->setSubtitle($request->request->get('subtitle')); + if (null !== $subtitle = $request->request->get('subtitle')) { + $feed->setSubtitle($subtitle); } $feed->setCollection($collection); $feed->setPublic($request->request->get('public') === '1' ? true : false); - $app["EM"]->persist($feed); - $app["EM"]->flush(); + $app['EM']->persist($feed); + $app['EM']->flush(); return $app->redirectPath('admin_feeds_list'); })->before(function(Request $request) use ($app) { - $feed = $app["EM"]->getRepository("Entities\Feed")->findOneBy(array("id" => $request->attributes->get('id'))); + $feed = $app["EM"]->find('Entities\Feed', $request->attributes->get('id')); if (!$feed->getOwner($app['authentication']->getUser())) { return $app->redirectPath('admin_feeds_feed', array('id' => $request->attributes->get('id'), 'error' => _('You are not the owner of this feed, you can not edit it'))); @@ -121,7 +122,7 @@ class Publications implements ControllerProviderInterface 'success' => false, 'message' => '', ); - $feed = $app["EM"]->getRepository("Entities\Feed")->findOneBy(array("id" => $id)); + $feed = $app["EM"]->find('Entities\Feed', $id); $request = $app["request"]; @@ -173,7 +174,7 @@ class Publications implements ControllerProviderInterface $datas['success'] = true; } catch (\Exception $e) { - $datas['message'] = _('Unable to add file to Phraseanet'); + $datas['message'] = _('Unable to add file to Phraseanet') . $e->getMessage(); } return $app->json($datas); @@ -186,19 +187,19 @@ class Publications implements ControllerProviderInterface try { $request = $app['request']; $user = \User_Adapter::getInstance($request->request->get('usr_id'), $app); - $feed = $app["EM"]->getRepository("Entities\Feed")->findOneBy(array("id" => $id)); + $feed = $app["EM"]->find('Entities\Feed', $id); $publisher = new FeedPublisher(); $publisher->setUsrId($user->get_id()); - $publisher->setOwner(false); + $publisher->setIsOwner(false); $publisher->setFeed($feed); $feed->addPublisher($publisher); - $app["EM"]->persist($feed); - $app["EM"]->persist($publisher); + $app['EM']->persist($feed); + $app['EM']->persist($publisher); - $app["EM"]->flush(); + $app['EM']->flush(); } catch (\Exception $e) { $error = $e->getMessage(); } @@ -212,9 +213,9 @@ class Publications implements ControllerProviderInterface try { $request = $app['request']; - $feed = $app["EM"]->getRepository("Entities\Feed")->findOneBy(array("id" => $id)); + $feed = $app["EM"]->find('Entities\Feed', $id); - $publisher = $app["EM"]->getRepository("Entities\FeedPublisher")->findOneBy(array("id" => $request->request->get('publisher_id'))); + $publisher = $app["EM"]->find('Entities\FeedPublisher', $request->request->get('publisher_id')); if (null === $publisher) { throw new \Exception_Feed_PublisherNotFound(); } @@ -223,8 +224,8 @@ class Publications implements ControllerProviderInterface if ($feed->isPublisher($user) === true && $feed->isOwner($user) === false) { $feed->removePublisher($publisher); - $app["EM"]->remove($publisher); - $app["EM"]->flush(); + $app['EM']->remove($publisher); + $app['EM']->flush(); } } catch (\Exception $e) { $error = $e->getMessage(); @@ -236,13 +237,13 @@ class Publications implements ControllerProviderInterface ->assert('id', '\d+'); $controllers->post('/feed/{id}/delete/', function(PhraseaApplication $app, $id) { - $feed = $app["EM"]->getRepository("Entities\Feed")->findOneBy(array("id" => $id)); + $feed = $app["EM"]->find('Entities\Feed', $id); $publishers = $feed->getPublishers(); foreach ($publishers as $publisher) { - $app["EM"]->remove($publisher); + $app['EM']->remove($publisher); } - $app["EM"]->remove($feed); - $app["EM"]->flush(); + $app['EM']->remove($feed); + $app['EM']->flush(); return $app->redirectPath('admin_feeds_list'); }) diff --git a/lib/Alchemy/Phrasea/Controller/Lightbox.php b/lib/Alchemy/Phrasea/Controller/Lightbox.php index 28dae0b327..56c966e2c0 100644 --- a/lib/Alchemy/Phrasea/Controller/Lightbox.php +++ b/lib/Alchemy/Phrasea/Controller/Lightbox.php @@ -160,7 +160,7 @@ class Lightbox implements ControllerProviderInterface $controllers->get('/ajax/LOAD_FEED_ITEM/{entry_id}/{item_id}/', function(SilexApplication $app, $entry_id, $item_id) { - $entry = $app['EM']->getRepository("Entities\FeedEntry")->find($entry_id); + $entry = $app['EM']->getRepository('Entities\FeedEntry')->find($entry_id); $item = $entry->getItems()->getItem($item_id); if ($app['browser']->isMobile()) { @@ -313,7 +313,7 @@ class Lightbox implements ControllerProviderInterface return $app->redirectPath('logout'); } - $feed_entry = $app['EM']->getEntity("Entities\FeedEntry")->find($entry_id); + $feed_entry = $app['EM']->getEntity('Entities\FeedEntry')->find($entry_id); $template = 'lightbox/feed.html.twig'; diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Feed.php b/lib/Alchemy/Phrasea/Controller/Prod/Feed.php index f58b69f2d4..4f905eacdf 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Feed.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Feed.php @@ -44,7 +44,7 @@ class Feed implements ControllerProviderInterface * I got a selection of docs, which publications are available forthese docs ? */ $controllers->post('/requestavailable/', function(Application $app, Request $request) { - $feeds = $app["EM"]->getRepository("Entities\Feed")->getAllForUser($app['authentication']->getUser()); + $feeds = $app['EM']->getRepository('Entities\Feed')->getAllForUser($app['authentication']->getUser()); $publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub')); return $app['twig']->render('prod/actions/publish/publish.html.twig', array('publishing' => $publishing, 'feeds' => $feeds)); @@ -55,8 +55,8 @@ class Feed implements ControllerProviderInterface */ $controllers->post('/entry/create/', function(Application $app, Request $request) { try { - $feed = $app["EM"]->getRepository("Entities\Feed")->find($request->request->get('feed_id')); - $publisher = $app["EM"]->getRepository("Entities\FeedPublisher")->findByUser($feed, $app['authentication']->getUser()); + $feed = $app['EM']->getRepository('Entities\Feed')->find($request->request->get('feed_id')); + $publisher = $app['EM']->getRepository('Entities\FeedPublisher')->findByUser($feed, $app['authentication']->getUser()); $title = $request->request->get('title'); $subtitle = $request->request->get('subtitle'); $author_name = $request->request->get('author_name'); @@ -79,12 +79,12 @@ class Feed implements ControllerProviderInterface $item->setRecordId($record->get_record_id()); $item->setSbasId($record->get_sbas_id()); $entry->addItem($item); - $app["EM"]->persist($item); + $app['EM']->persist($item); } - $app["EM"]->persist($entry); - $app["EM"]->persist($feed); - $app["EM"]->flush(); + $app['EM']->persist($entry); + $app['EM']->persist($feed); + $app['EM']->flush(); $app['events-manager']->trigger('__FEED_ENTRY_CREATE__', array('entry_id' => $entry->getId()), $entry); @@ -101,13 +101,13 @@ class Feed implements ControllerProviderInterface }); $controllers->get('/entry/{id}/edit/', function(Application $app, Request $request, $id) { - $entry = $app["EM"]->getRepository("Entities\FeedEntry")->find($id); + $entry = $app['EM']->getRepository('Entities\FeedEntry')->find($id); if (!$entry->isPublisher($app['authentication']->getUser())) { throw new AccessDeniedHttpException(); } - $feeds = $app["EM"]->getRepository("Entities\Feed")->findAll(); + $feeds = $app['EM']->getRepository('Entities\Feed')->findAll(); $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', array('entry' => $entry, 'feeds' => $feeds)); @@ -121,75 +121,62 @@ class Feed implements ControllerProviderInterface $controllers->post('/entry/{id}/update/', function(Application $app, Request $request, $id) { $datas = array('error' => true, 'message' => '', 'datas' => ''); - try { - $entry = $app["EM"]->getRepository("Entities\FeedEntry")->find($id); + $entry = $app['EM']->getRepository('Entities\FeedEntry')->find($id); - if (null === $entry) { - throw new NotFoundHttpException(); - } - if (!$entry->isPublisher($app['authentication']->getUser())) { - throw new AccessDeniedHttpException(); - } - - $title = $request->request->get('title'); - $subtitle = $request->request->get('subtitle'); - $author_name = $request->request->get('author_name'); - $author_mail = $request->request->get('author_mail'); - - $entry->setAuthorEmail($author_mail) - ->setAuthorName($author_name) - ->setTitle($title) - ->setSubtitle($subtitle); - - $current_feed_id = $entry->getFeed()->getId(); - $new_feed_id = $request->request->get('feed_id', $current_feed_id); - if ($current_feed_id != $new_feed_id) { - try { - $new_feed = $app["EM"]->getRepository("Entities\Feed")->loadWithUser($app, $app['authentication']->getUser(), $new_feed_id); - } catch (NotFoundHttpException $e) { - throw new AccessDeniedHttpException('You have no access to this feed'); - } - - if ($new_feed === null) { - throw new NotFoundHttpException(); - } - - if (!$new_feed->isPublisher($app['authentication']->getUser())) { - throw new \Exception_Forbidden('You are not publisher of this feed'); - } - $entry->setFeed($new_feed); - } - - $items = explode(';', $request->request->get('sorted_lst')); - - foreach ($items as $item_sort) { - $item_sort_datas = explode('_', $item_sort); - if (count($item_sort_datas) != 2) { - continue; - } - - $item = new FeedItem($entry, $item_sort_datas[0]); - $item->setEntry($entry); - $entry->addItem($item); - $item->setOrd($item_sort_datas[1]); - $app["EM"]->persist($item); - } - - $app["EM"]->persist($entry); - $app["EM"]->flush(); - - $entry = $app['twig']->render('prod/feeds/entry.html.twig', array('entry' => $entry)); - - $datas = array('error' => false, 'message' => 'succes', 'datas' => $entry); - } catch (\Exception_Feed_EntryNotFound $e) { - $datas['message'] = _('Feed entry not found'); - } catch (NotFoundHttpException $e) { - $datas['message'] = _('Feed not found'); - } catch (AccessDeniedHttpException $e) { - $datas['message'] = _('You are not authorized to access this feed'); - } catch (\Exception $e) { - $datas['message'] = $e->getMessage(); + if (null === $entry) { + $app->abort(404, 'Entry not found'); } + if (!$entry->isPublisher($app['authentication']->getUser())) { + $app->abort(403, 'Unathorized action'); + } + + $title = $request->request->get('title'); + $subtitle = $request->request->get('subtitle'); + $author_name = $request->request->get('author_name'); + $author_mail = $request->request->get('author_mail'); + + $entry->setAuthorEmail($author_mail) + ->setAuthorName($author_name) + ->setTitle($title) + ->setSubtitle($subtitle); + + $current_feed_id = $entry->getFeed()->getId(); + $new_feed_id = $request->request->get('feed_id', $current_feed_id); + if ($current_feed_id != $new_feed_id) { + + $new_feed = $app['EM']->getRepository('Entities\Feed')->find($new_feed_id); + + if ($new_feed === null) { + $app->abort(404, 'Feed not found'); + } + + if (!$new_feed->isPublisher($app['authentication']->getUser())) { + $app->abort(403, 'You are not publisher of this feed'); + } + $entry->setFeed($new_feed); + } + + $items = explode(';', $request->request->get('sorted_lst')); + + foreach ($items as $item_sort) { + $item_sort_datas = explode('_', $item_sort); + if (count($item_sort_datas) != 2) { + continue; + } + + $item = new FeedItem($entry, $item_sort_datas[0]); + $item->setEntry($entry); + $entry->addItem($item); + $item->setOrd($item_sort_datas[1]); + $app['EM']->persist($item); + } + + $app['EM']->persist($entry); + $app['EM']->flush(); + + $entry = $app['twig']->render('prod/feeds/entry.html.twig', array('entry' => $entry)); + + $datas = array('error' => false, 'message' => 'succes', 'datas' => $entry); return $app->json($datas); }) @@ -200,25 +187,20 @@ class Feed implements ControllerProviderInterface $controllers->post('/entry/{id}/delete/', function(Application $app, Request $request, $id) { $datas = array('error' => true, 'message' => ''); - try { - $entry = $app["EM"]->getRepository("Entities\FeedEntry")->find($id); + + $entry = $app['EM']->getRepository('Entities\FeedEntry')->find($id); - if (null === $entry) { - throw new NotFoundHttpException(); - } - if (!$entry->isPublisher($app['authentication']->getUser()) && $entry->getFeed()->isOwner($app['authentication']->getUser()) === false) { - throw new AccessDeniedHttpException(_('Action Forbidden : You are not the publisher')); - } - - $app["EM"]->remove($entry); - $app["EM"]->flush(); - - $datas = array('error' => false, 'message' => 'succes'); - } catch (NotFoundHttpException $e) { - $datas['message'] = _('Feed entry not found'); - } catch (\Exception $e) { - $datas['message'] = $e->getMessage(); + if (null === $entry) { + $app->abort(404, 'Entry not found'); } + if (!$entry->isPublisher($app['authentication']->getUser()) && $entry->getFeed()->isOwner($app['authentication']->getUser()) === false) { + $app->abort(403, _('Action Forbidden : You are not the publisher')); + } + + $app['EM']->remove($entry); + $app['EM']->flush(); + + $datas = array('error' => false, 'message' => 'succes'); return $app->json($datas); }) @@ -232,12 +214,12 @@ class Feed implements ControllerProviderInterface $page = (int) $request->query->get('page'); $page = $page > 0 ? $page : 1; - $feeds = $app["EM"]->getRepository("Entities\Feed")->findAll(); + $feeds = $app['EM']->getRepository('Entities\Feed')->findAll(); $datas = $app['twig']->render('prod/feeds/feeds.html.twig' , array( 'feeds' => $feeds - , 'feed' => new Aggregate($app["EM"], $feeds) + , 'feed' => new Aggregate($app['EM'], $feeds) , 'page' => $page ) ); @@ -249,8 +231,8 @@ class Feed implements ControllerProviderInterface $page = (int) $request->query->get('page'); $page = $page > 0 ? $page : 1; - $feed = $app["EM"]->getRepository("Entities\Feed")->loadWithUser($app, $app['authentication']->getUser(), $id); - $feeds = $app["EM"]->getRepository("Entities\Feed")->findAll(); + $feed = $app['EM']->getRepository('Entities\Feed')->loadWithUser($app, $app['authentication']->getUser(), $id); + $feeds = $app['EM']->getRepository('Entities\Feed')->findAll(); $datas = $app['twig']->render('prod/feeds/feeds.html.twig', array('feed' => $feed, 'feeds' => $feeds, 'page' => $page)); @@ -262,9 +244,9 @@ class Feed implements ControllerProviderInterface $controllers->get('/subscribe/aggregated/', function(Application $app, Request $request) { $renew = ($request->query->get('renew') === 'true'); - $feeds = $app["EM"]->getRepository("Entities\Feed")->findAll(); + $feeds = $app['EM']->getRepository('Entities\Feed')->findAll(); - $aggregate = new Aggregate($app["EM"], $feeds); + $aggregate = new Aggregate($app['EM'], $feeds); $link = $app['feed.aggregate-link-generator']->generate($aggregate, $app['authentication']->getUser(), AggregateLinkGenerator::FORMAT_RSS, null, $renew); @@ -281,7 +263,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("Entities\Feed")->loadWithUser($app, $app['authentication']->getUser(), $id); + $feed = $app['EM']->getRepository('Entities\Feed')->loadWithUser($app, $app['authentication']->getUser(), $id); $link = $app['feed.user-link-generator']->generate($feed, $app['authentication']->getUser(), FeedLinkGenerator::FORMAT_RSS, null, $renew); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Root.php b/lib/Alchemy/Phrasea/Controller/Prod/Root.php index 607d403f39..39222da584 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Root.php @@ -73,7 +73,7 @@ class Root implements ControllerProviderInterface $cssfile = '000000'; } - $feeds = $app["EM"]->getRepository("Entities\Feed")->getAllForUser($app['authentication']->getUser()); + $feeds = $app['EM']->getRepository('Entities\Feed')->getAllForUser($app['authentication']->getUser()); $thjslist = ""; diff --git a/lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php b/lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php index 02870affb5..e4c22e3ed2 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php +++ b/lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php @@ -30,7 +30,7 @@ class RSSFeeds implements ControllerProviderInterface $controllers = $app['controllers_factory']; $controllers->get('/feed/{id}/{format}/', function(Application $app, $id, $format) { - $feed = $app["EM"]->getRepository("Entities\Feed")->find($id); + $feed = $app['EM']->getRepository('Entities\Feed')->find($id); if (!$feed) { return new Response('Not Found', 404); @@ -52,7 +52,7 @@ class RSSFeeds implements ControllerProviderInterface ->assert('format', '(rss|atom)'); $controllers->get('/userfeed/{token}/{id}/{format}/', function(Application $app, $token, $id, $format) { - $token = $app["EM"]->getRepository("Entities\FeedToken")->findOneBy(array("id" => $id)); + $token = $app["EM"]->find('Entities\FeedToken', $id); $feed = $token->getFeed(); $usrId = $token->getUsrId(); @@ -70,14 +70,14 @@ class RSSFeeds implements ControllerProviderInterface ->assert('format', '(rss|atom)'); $controllers->get('/userfeed/aggregated/{token}/{format}/', function(Application $app, $token, $format) { - $token = $app["EM"]->getRepository("Entities\AggregateToken")->findOneBy(array("value" => $token)); + $token = $app['EM']->getRepository('Entities\AggregateToken')->findOneBy(array("value" => $token)); $usrId = $token->getUsrId(); $user = \User_Adapter::getInstance($usrId, $app); - $feeds = $app["EM"]->getRepository('Entities\Feed')->getAllForUser($user); + $feeds = $app['EM']->getRepository('Entities\Feed')->getAllForUser($user); - $aggregate = new Aggregate($app["EM"], $feeds, $token); + $aggregate = new Aggregate($app['EM'], $feeds, $token); $request = $app['request']; @@ -90,8 +90,8 @@ class RSSFeeds implements ControllerProviderInterface ->assert('format', '(rss|atom)'); $controllers->get('/aggregated/{format}/', function(Application $app, $format) { - $feeds = $app["EM"]->getRepository("Entities\Feed")->findAllPublic(); - $feed = new Aggregate($app["EM"], $feeds); + $feeds = $app['EM']->getRepository('Entities\Feed')->findAllPublic(); + $feed = new Aggregate($app['EM'], $feeds); $request = $app['request']; $page = (int) $request->query->get('page'); @@ -103,8 +103,8 @@ class RSSFeeds implements ControllerProviderInterface ->assert('format', '(rss|atom)'); $controllers->get('/cooliris/', function(Application $app) { - $feeds = $app["EM"]->getRepository("Entities\Feed")->findAllPublic(); - $feed = new Aggregate($app["EM"], $feeds); + $feeds = $app['EM']->getRepository('Entities\Feed')->findAllPublic(); + $feed = new Aggregate($app['EM'], $feeds); $request = $app['request']; $page = (int) $request->query->get('page'); diff --git a/lib/Alchemy/Phrasea/Feed/Aggregate.php b/lib/Alchemy/Phrasea/Feed/Aggregate.php index 03d90e979a..75ca82667d 100644 --- a/lib/Alchemy/Phrasea/Feed/Aggregate.php +++ b/lib/Alchemy/Phrasea/Feed/Aggregate.php @@ -145,7 +145,7 @@ class Aggregate implements FeedInterface public function getCountTotalEntries() { if (count($this->feeds) > 0) { - return count($this->em->getRepository("Entities\FeedEntry")->findByFeeds($this->feeds)); + return count($this->em->getRepository('Entities\FeedEntry')->findByFeeds($this->feeds)); } return 0; } diff --git a/lib/Doctrine/Entities/Feed.php b/lib/Doctrine/Entities/Feed.php index 17f400e5f1..7b4bd64d5e 100644 --- a/lib/Doctrine/Entities/Feed.php +++ b/lib/Doctrine/Entities/Feed.php @@ -22,7 +22,7 @@ class Feed implements FeedInterface private $public = false; /** - * @var string + * @var boolean */ private $icon_url = false; @@ -111,7 +111,7 @@ class Feed implements FeedInterface /** * Set icon_url * - * @param string $iconUrl + * @param boolean $iconUrl * @return Feed */ public function setIconUrl($iconUrl) @@ -124,15 +124,11 @@ class Feed implements FeedInterface /** * Get icon_url * - * @return string + * @return boolean */ public function getIconUrl() { - if (!$this->icon_url) { - return '/skins/icons/rss32.gif'; - } - - return '/www/custom/feed_' . $this->getId() . '.jpg'; + return $this->icon_url; } /** @@ -253,7 +249,7 @@ class Feed implements FeedInterface public function getOwner() { foreach ($this->getPublishers() as $publisher) { - if ($publisher->getOwner()) { + if ($publisher->isOwner()) { return $publisher; } } diff --git a/lib/Doctrine/Entities/FeedPublisher.php b/lib/Doctrine/Entities/FeedPublisher.php index 4b8d3b5dfe..ea72984973 100644 --- a/lib/Doctrine/Entities/FeedPublisher.php +++ b/lib/Doctrine/Entities/FeedPublisher.php @@ -75,7 +75,7 @@ class FeedPublisher * @param boolean $owner * @return FeedPublisher */ - public function setOwner($owner) + public function setIsOwner($owner) { $this->owner = $owner; @@ -87,7 +87,7 @@ class FeedPublisher * * @return boolean */ - public function getOwner() + public function isOwner() { return $this->owner; } @@ -115,6 +115,12 @@ class FeedPublisher return $this->feed; } + + /** + * Get user + * + * @return \User_Adapter + */ public function getUser(Application $app) { $user = \User_Adapter::getInstance($this->getUsrId(), $app); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/PublicationTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/PublicationTest.php index 2e47c8620c..6a6371ee0e 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/PublicationTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/PublicationTest.php @@ -13,7 +13,7 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic $crawler = self::$DI['client']->request('GET', '/admin/publications/list/'); $pageContent = self::$DI['client']->getResponse()->getContent(); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $feeds = self::$DI['app']['EM']->getRepository("Entities\Feed")->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->getAllForUser(self::$DI['user']); foreach ($feeds as $feed) { $this->assertRegExp('/\/admin\/publications\/feed\/' . $feed->getId() . '/', $pageContent); @@ -26,14 +26,14 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic public function testCreate() { - $feeds = self::$DI['app']['EM']->getRepository("Entities\Feed")->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->getAllForUser(self::$DI['user']); $count = sizeof($feeds); $crawler = self::$DI['client']->request('POST', '/admin/publications/create/', array("title" => "hello", "subtitle" => "coucou", "base_id" => self::$DI['collection']->get_base_id())); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect('/admin/publications/list/')); - $feeds = self::$DI['app']['EM']->getRepository("Entities\Feed")->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->getAllForUser(self::$DI['user']); $count_after = sizeof($feeds); $this->assertGreaterThan($count, $count_after); } @@ -58,7 +58,7 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic , 'public' => '1' )); - $feed = self::$DI['app']['EM']->getRepository("Entities\Feed")->findOneBy(array('id' => $feed->getId())); + $feed = self::$DI['app']['EM']->find('Entities\Feed', $feed->getId()); $this->assertTrue( strpos( @@ -89,7 +89,7 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic , '/admin/publications/list/' ) === 0); - $feed = self::$DI['app']['EM']->getRepository("Entities\Feed")->findOneBy(array('id' => $feed->getId())); + $feed = self::$DI['app']['EM']->find('Entities\Feed', $feed->getId()); $collection = $feed->getCollection(self::$DI['app']); @@ -213,7 +213,7 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isRedirect()); - $feed = self::$DI['app']['EM']->getRepository("Entities\Feed")->findOneBy(array('id' => $feed->getId())); + $feed = self::$DI['app']['EM']->find('Entities\Feed', $feed->getId()); $publishers = $feed->getPublishers(); $this->assertTrue($feed->isPublisher(self::$DI['user_alt1'])); @@ -230,7 +230,7 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic self::$DI['client']->request("POST", "/admin/publications/feed/" . $feed->getId() . "/addpublisher/"); - $feed = self::$DI['app']['EM']->getRepository("Entities\Feed")->findOneBy(array('id' => $feed->getId())); + $feed = self::$DI['app']['EM']->find('Entities\Feed', $feed->getId()); $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isRedirect()); $this->assertTrue( @@ -251,7 +251,7 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isRedirect()); - $feed = self::$DI['app']['EM']->getRepository("Entities\Feed")->findOneBy(array('id' => $feed->getId())); + $feed = self::$DI['app']['EM']->find('Entities\Feed', $feed->getId()); $publishers = $feed->getPublishers(); $this->assertFalse(isset($publishers[self::$DI['user_alt1']->get_id()])); @@ -271,7 +271,7 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isRedirect()); - $feed = self::$DI['app']['EM']->getRepository("Entities\Feed")->findOneBy(array('id' => $feed->getId())); + $feed = self::$DI['app']['EM']->find('Entities\Feed', $feed->getId()); $this->assertTrue( strpos( @@ -289,7 +289,7 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isRedirect()); - $feed = self::$DI['app']['EM']->getRepository("Entities\Feed")->findOneBy(array('id' => $feed->getId())); + $feed = self::$DI['app']['EM']->find('Entities\Feed', $feed->getId()); if (null !== $feed) { $this->fail("fail deleting feed"); } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php index da8e27b91d..2845ae2f8b 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php @@ -5,7 +5,7 @@ namespace Alchemy\Tests\Phrasea\Controller\Prod; use Alchemy\Phrasea\Application; use Symfony\Component\CssSelector\CssSelector; -class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract +class FeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { /** * @@ -55,7 +55,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $crawler = self::$DI['client']->request('POST', '/prod/feeds/requestavailable/'); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $feeds = self::$DI['app']["EM"]->getRepository("\Entities\Feed")->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->getAllForUser(self::$DI['user']); foreach ($feeds as $one_feed) { if ($one_feed->isPublisher(self::$DI['user'])) { $this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $one_feed->getId() . "']")->count()); @@ -183,17 +183,17 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue(is_string($pageContent->datas)); $this->assertRegExp("/entry_" . $entry->getId() . "/", $pageContent->datas); - $retrievedentry = self::$DI['app']["EM"]->getRepository("\Entities\FeedEntry")->find($entry->getId()); + $retrievedentry = self::$DI['app']['EM']->getRepository('Entities\FeedEntry')->find($entry->getId()); $this->assertEquals($newfeed->getId(), $retrievedentry->getFeed()->getId()); } public function testEntryUpdateChangeFeedNoAccess() { $entry = $this->insertOneFeedEntry(self::$DI['user']); - $newfeed = $this->insertOneFeed(self::$DI['user'], "test2"); + $newfeed = $this->insertOneFeed(self::$DI['user_alt1'], "test2"); $newfeed->setCollection(self::$DI['collection_no_access']); - self::$DI['app']["EM"]->persist($newfeed); - self::$DI['app']["EM"]->flush(); + self::$DI['app']['EM']->persist($newfeed); + self::$DI['app']['EM']->flush(); $params = array( "feed_id" => $newfeed->getId(), @@ -205,12 +205,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ); $crawler = self::$DI['client']->request('POST', '/prod/feeds/entry/' . $entry->getId() . '/update/', $params); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); - $pageContent = json_decode(self::$DI['client']->getResponse()->getContent()); - $this->assertTrue(is_object($pageContent)); - $this->assertTrue($pageContent->error); - $this->assertTrue(is_string($pageContent->message)); + $this->assertEquals(403, self::$DI['client']->getResponse()->getStatusCode()); } public function testEntryUpdateChangeFeedInvalidFeed() @@ -227,12 +222,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ); $crawler = self::$DI['client']->request('POST', '/prod/feeds/entry/' . $entry->getId() . '/update/', $params); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); - $pageContent = json_decode(self::$DI['client']->getResponse()->getContent()); - $this->assertTrue(is_object($pageContent)); - $this->assertTrue($pageContent->error); - $this->assertTrue(is_string($pageContent->message)); + $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); } public function testEntryUpdateNotFound() @@ -253,11 +243,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $pageContent = json_decode($response->getContent()); - $this->assertTrue($response->isOk()); - $this->assertEquals("application/json", $response->headers->get("content-type")); - $this->assertTrue(is_object($pageContent)); - $this->assertTrue($pageContent->error); - $this->assertTrue(is_string($pageContent->message)); + $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); } public function testEntryUpdateFailed() @@ -277,13 +263,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $response = self::$DI['client']->getResponse(); - $this->assertTrue($response->isOk()); - $pageContent = json_decode($response->getContent()); - - $this->assertEquals("application/json", $response->headers->get("content-type")); - $this->assertTrue(is_object($pageContent)); - $this->assertTrue($pageContent->error); - $this->assertTrue(is_string($pageContent->message)); + $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); } public function testEntryUpdateUnauthorized() @@ -307,13 +287,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $response = self::$DI['client']->getResponse(); - $this->assertTrue($response->isOk()); - $pageContent = json_decode($response->getContent()); - - $this->assertEquals("application/json", $response->headers->get("content-type")); - $this->assertTrue(is_object($pageContent)); - $this->assertTrue($pageContent->error); - $this->assertTrue(is_string($pageContent->message)); + $this->assertEquals(403, self::$DI['client']->getResponse()->getStatusCode());; } public function testDelete() @@ -332,7 +306,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue(is_string($pageContent->message)); try { - self::$DI["app"]["EM"]->getRepository("\Entities\FeedEntry")->find($entry->getId()); + self::$DI["app"]['EM']->getRepository('Entities\FeedEntry')->find($entry->getId()); $this->fail("Failed to delete entry"); } catch (\Exception $e) { @@ -348,11 +322,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $pageContent = json_decode(self::$DI['client']->getResponse()->getContent()); - $this->assertTrue($response->isOk()); - $this->assertEquals("application/json", $response->headers->get("content-type")); - $this->assertTrue(is_object($pageContent)); - $this->assertTrue($pageContent->error); - $this->assertTrue(is_string($pageContent->message)); + $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); } public function testDeleteUnauthorized() @@ -368,11 +338,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $pageContent = json_decode(self::$DI['client']->getResponse()->getContent()); - $this->assertTrue($response->isOk()); - $this->assertEquals("application/json", $response->headers->get("content-type")); - $this->assertTrue(is_object($pageContent)); - $this->assertTrue($pageContent->error); - $this->assertTrue(is_string($pageContent->message)); + $this->assertEquals(403, self::$DI['client']->getResponse()->getStatusCode()); } public function testRoot() @@ -384,7 +350,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $feeds = self::$DI['app']["EM"]->getRepository("\Entities\Feed")->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->getAllForUser(self::$DI['user']); foreach ($feeds as $one_feed) { @@ -404,7 +370,7 @@ class ControllerFeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $feed = $this->insertOneFeed(self::$DI['user']); - $feeds = self::$DI['app']["EM"]->getRepository("\Entities\Feed")->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->getAllForUser(self::$DI['user']); $crawler = self::$DI['client']->request('GET', '/prod/feeds/feed/' . $feed->getId() . "/"); $pageContent = self::$DI['client']->getResponse()->getContent(); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php index 0ebbd57551..7cbbbee057 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php @@ -175,7 +175,7 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract $this->insertOneFeed(self::$DI['user'], "test1", true); $this->insertOneFeed(self::$DI['user'], "test2", true); - $all_feeds = self::$DI['app']['EM']->getRepository("Entities\Feed")->findAllPublic(); + $all_feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->findAllPublic(); foreach ($all_feeds as $feed) { $this->assertTrue($feed->getPublic()); @@ -192,7 +192,7 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract $this->insertOneFeed(self::$DI['user'], "test1", true); $this->insertOneFeed(self::$DI['user'], "test2", true); - $all_feeds = self::$DI['app']['EM']->getRepository("Entities\Feed")->findAllPublic(); + $all_feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->findAllPublic(); foreach ($all_feeds as $feed) { $this->assertTrue($feed->getPublic()); diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/FeedServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/FeedServiceProviderTest.php index 0f160ae1c4..3dfd282d4b 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/FeedServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/FeedServiceProviderTest.php @@ -3,9 +3,9 @@ namespace Alchemy\Tests\Phrasea\Core\Provider; /** - * @covers Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider + * @covers Alchemy\Phrasea\Core\Provider\FeedServiceProvider */ -class GeonamesServiceProvidertest extends ServiceProviderTestCase +class FeedServiceProviderTest extends ServiceProviderTestCase { public function provideServiceDescription() { diff --git a/tests/Alchemy/Tests/Phrasea/Feed/AggregateLinkGeneratorTest.php b/tests/Alchemy/Tests/Phrasea/Feed/AggregateLinkGeneratorTest.php index e53f1e52cd..ad5e7424cc 100644 --- a/tests/Alchemy/Tests/Phrasea/Feed/AggregateLinkGeneratorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Feed/AggregateLinkGeneratorTest.php @@ -67,10 +67,10 @@ class AggregateLinkGeneratorTest extends \PhraseanetPHPUnitAbstract $this->assertNotEquals($tokenValue, $capture['token']); $this->assertCount(0, self::$DI['app']['EM'] - ->getRepository("Entities\AggregateToken") + ->getRepository('Entities\AggregateToken') ->findBy(array('value' => $tokenValue))); $this->assertCount(1, self::$DI['app']['EM'] - ->getRepository("Entities\AggregateToken") + ->getRepository('Entities\AggregateToken') ->findBy(array('value' => $capture['token']))); } else { $expectedParams = array( @@ -85,7 +85,7 @@ class AggregateLinkGeneratorTest extends \PhraseanetPHPUnitAbstract $this->assertEquals($expectedParams, $capture); $this->assertCount(1, self::$DI['app']['EM'] - ->getRepository("Entities\AggregateToken") + ->getRepository('Entities\AggregateToken') ->findBy(array('value' => $tokenValue))); } } else { @@ -96,7 +96,7 @@ class AggregateLinkGeneratorTest extends \PhraseanetPHPUnitAbstract $this->assertEquals(12, strlen($capture['token'])); $this->assertCount(1, self::$DI['app']['EM'] - ->getRepository("Entities\AggregateToken") + ->getRepository('Entities\AggregateToken') ->findBy(array('value' => $capture['token']))); } $token = self::$DI['app']['EM'] diff --git a/tests/Alchemy/Tests/Phrasea/Feed/FeedLinkGeneratorTest.php b/tests/Alchemy/Tests/Phrasea/Feed/FeedLinkGeneratorTest.php index 37c25d4db6..90e417a925 100644 --- a/tests/Alchemy/Tests/Phrasea/Feed/FeedLinkGeneratorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Feed/FeedLinkGeneratorTest.php @@ -60,10 +60,10 @@ class FeedLinkGeneratorTest extends \PhraseanetPHPUnitAbstract } $this->assertCount(0, self::$DI['app']['EM'] - ->getRepository("Entities\FeedToken") + ->getRepository('Entities\FeedToken') ->findBy(array('value' => $tokenValue))); $this->assertCount(1, self::$DI['app']['EM'] - ->getRepository("Entities\FeedToken") + ->getRepository('Entities\FeedToken') ->findBy(array('value' => $capture['token']))); } else { $expectedParams = array( @@ -79,7 +79,7 @@ class FeedLinkGeneratorTest extends \PhraseanetPHPUnitAbstract $this->assertEquals($expectedParams, $capture); $this->assertCount(1, self::$DI['app']['EM'] - ->getRepository("Entities\FeedToken") + ->getRepository('Entities\FeedToken') ->findBy(array('value' => $tokenValue))); } } else { @@ -91,7 +91,7 @@ class FeedLinkGeneratorTest extends \PhraseanetPHPUnitAbstract $this->assertEquals(12, strlen($capture['token'])); $this->assertCount(1, self::$DI['app']['EM'] - ->getRepository("Entities\FeedToken") + ->getRepository('Entities\FeedToken') ->findBy(array('value' => $capture['token']))); } $token = self::$DI['app']['EM']