Fixed RSSFeeds bug for php 5.3, fixed Aggregate->getEntries() called without any feed

This commit is contained in:
Andrey
2013-06-17 14:01:03 +02:00
parent 3f8855f5cb
commit 6bdfa2da29
6 changed files with 40 additions and 45 deletions

View File

@@ -30,7 +30,7 @@ class RSSFeeds implements ControllerProviderInterface
$controllers = $app['controllers_factory'];
$that = $this;
$controllers->get('/feed/{id}/{format}/', function(Application $app, $id, $format) use ($that) {
$controllers->get('/feed/{id}/{format}/', function(Application $app, $id, $format) {
$feed = $app['EM']->getRepository('Entities\Feed')->find($id);
if (!$feed) {
@@ -46,13 +46,13 @@ class RSSFeeds implements ControllerProviderInterface
$page = (int) $request->query->get('page');
$page = $page < 1 ? 1 : $page;
return $app[$that->getFormater($format)]->createResponse($feed, $page);
return $app['feed.formatter-strategy']($format)->createResponse($feed, $page);
})
->bind('feed_public')
->assert('id', '\d+')
->assert('format', '(rss|atom)');
$controllers->get('/userfeed/{token}/{id}/{format}/', function(Application $app, $token, $id, $format) use ($that) {
$controllers->get('/userfeed/{token}/{id}/{format}/', function(Application $app, $token, $id, $format) {
$token = $app["EM"]->find('Entities\FeedToken', $id);
$feed = $token->getFeed();
$usrId = $token->getUsrId();
@@ -64,13 +64,13 @@ class RSSFeeds implements ControllerProviderInterface
$page = (int) $request->query->get('page');
$page = $page < 1 ? 1 : $page;
return $app[$that->getFormater($format)]->createResponse($feed, $page, $user);
return $app['feed.formatter-strategy']($format)->createResponse($feed, $page, $user);
})
->bind('feed_user')
->assert('id', '\d+')
->assert('format', '(rss|atom)');
$controllers->get('/userfeed/aggregated/{token}/{format}/', function(Application $app, $token, $format) use ($that) {
$controllers->get('/userfeed/aggregated/{token}/{format}/', function(Application $app, $token, $format) {
$token = $app['EM']->getRepository('Entities\AggregateToken')->findOneBy(array("value" => $token));
$usrId = $token->getUsrId();
@@ -85,12 +85,12 @@ class RSSFeeds implements ControllerProviderInterface
$page = (int) $request->query->get('page');
$page = $page < 1 ? 1 : $page;
return $app[$that->getFormater($format)]->createResponse($aggregate, $page, $user);
return $app['feed.formatter-strategy']($format)->createResponse($aggregate, $page, $user);
})
->bind('feed_user_aggregated')
->assert('format', '(rss|atom)');
$controllers->get('/aggregated/{format}/', function(Application $app, $format) use ($that) {
$controllers->get('/aggregated/{format}/', function(Application $app, $format) {
$feeds = $app['EM']->getRepository('Entities\Feed')->findAllPublic();
$feed = new Aggregate($app['EM'], $feeds);
@@ -98,12 +98,12 @@ class RSSFeeds implements ControllerProviderInterface
$page = (int) $request->query->get('page');
$page = $page < 1 ? 1 : $page;
return $app[$that->getFormater($format)]->createResponse($feed, $page);
return $app['feed.formatter-strategy']($format)->createResponse($feed, $page);
})
->bind('feed_public_aggregated')
->assert('format', '(rss|atom)');
$controllers->get('/cooliris/', function(Application $app) use ($that) {
$controllers->get('/cooliris/', function(Application $app) {
$feeds = $app['EM']->getRepository('Entities\Feed')->findAllPublic();
$feed = new Aggregate($app['EM'], $feeds);
@@ -111,27 +111,11 @@ class RSSFeeds implements ControllerProviderInterface
$page = (int) $request->query->get('page');
$page = $page < 1 ? 1 : $page;
return $app[$that->getFormater('cooliris')]->createResponse($feed, $page, null, 'Phraseanet', $app);
return $app['feed.formatter-strategy']('cooliris')->createResponse($feed, $page, null, 'Phraseanet', $app);
})
->bind('feed_public_cooliris');
return $controllers;
}
private function getFormater($type)
{
switch ($type) {
case 'rss':
return 'feed.rss-formatter';
break;
case 'atom':
return 'feed.atom-formatter';
break;
case 'cooliris':
return 'feed.cooliris-formatter';
break;
default:
throw new InvalidArgumentException(sprintf('Format %s is not recognized.', $format));
}
}
}

View File

@@ -45,6 +45,21 @@ class FeedServiceProvider implements ServiceProviderInterface
$app['feed.cooliris-formatter'] = $app->share(function($app) {
return new CoolirisFormatter($app['feed.link-generator-collection']);
});
$app['feed.formatter-strategy'] = $app->protect(function($type) use ($app) {
switch ($type) {
case 'rss':
return $app['feed.rss-formatter'];
break;
case 'atom':
return $app['feed.atom-formatter'];
break;
case 'cooliris':
return $app['feed.cooliris-formatter'];
break;
default:
throw new InvalidArgumentException(sprintf('Format %s is not recognized.', $type));
}
});
}
public function boot(Application $app)

View File

@@ -80,6 +80,9 @@ class Aggregate implements FeedInterface
public function getEntries($offset_start = null, $how_many = null)
{
if (count($this->feeds) == 0) {
return null;
}
return $this->em->getRepository('Entities\FeedEntry')->findByFeeds($this->feeds, $offset_start, $how_many);
}

View File

@@ -43,7 +43,7 @@ class UserSettingRepository extends EntityRepository
$query = $this->_em->createQuery($dql);
$query->setParameter('feeds', $feeds);
if (null !== $offset_start) {
if (null !== $offset_start && 0 !== $offset_start) {
$query->setFirstResult($offset_start);
}
if (null !== $how_many) {

View File

@@ -32,8 +32,8 @@
</div>
<div class="descPubli">
<div style="margin:10px 0 10px 20px;width:80%;">
{% if entry.get_subtitle()|trim is not empty %}
{{ entry.get_subtitle()|nl2br }}
{% if entry.getSubtitle()|trim is not empty %}
{{ entry.getSubtitle()|nl2br }}
{% endif %}
</div>
</div>
@@ -76,7 +76,7 @@
{% endset %}
{% endif %}
<div style="width:{{ wrapper_size }}px;" sbas="{{ record.get_sbas_id() }}" id="{{"IMGT_" ~ record.get_serialize_key() ~ "_PUB_" ~ entry.get_id() }}" class="IMGT diapo" onclick="openPreview('FEED','{{ item.get_ord() }}','{{ entry.get_id() }}');">
<div style="width:{{ wrapper_size }}px;" sbas="{{ record.get_sbas_id() }}" id="{{"IMGT_" ~ record.get_serialize_key() ~ "_PUB_" ~ entry.getId() }}" class="IMGT diapo" onclick="openPreview('FEED','{{ item.getOrd() }}','{{ entry.getId() }}');">
<div>
<div class="title" style="height:40px;">
{{ record.get_title() }}

View File

@@ -653,10 +653,9 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSearch_publications()
{
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], "hello", "salut");
$feed = $this->insertOneFeed(self::$DI['user']);
$result = $this->object->search_publications($request, self::$DI['user']);
$this->checkResponseField($result, "feeds", 'array');
$feed->delete();
}
public function testRemove_publications()
@@ -673,25 +672,19 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
->disableOriginalConstructor()
->getMock();
self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce())
->method('deliver')
->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null));
$date = new DateTime();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], "hello", "salut");
$feed_publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], $feed, self::$DI['user']);
$feed_entry = Feed_Entry_Adapter::create(self::$DI['app'], $feed, $feed_publisher, "coucou", "hello", "me", "my@email.com");
$feed_entry_item = Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $feed_entry, self::$DI['record_1']);
$coll = Feed_Collection::load_all(self::$DI['app'], self::$DI['user']);
foreach ($coll->get_feeds() as $feed) {
$result = $this->object->get_publication($request, $feed->get_id(), self::$DI['user']);
$feedItem = $this->insertOneFeedItem(self::$DI['user']);
$feed = $feedItem->getEntry()->getFeed();
$feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->getAllForUser(self::$DI['user']);
foreach ($feeds as $feed) {
$result = $this->object->get_publication($request, $feed->getId(), self::$DI['user']);
$this->checkResponseField($result, "feed", 'array');
$this->checkResponseField($result, "entries", 'array');
$this->checkResponseField($result, "offset_start", 'integer');
$this->checkResponseField($result, "per_page", 'integer');
}
$feed->delete();
}
protected function checkResponseField(API_V1_result $result, $field, $type)