Fix #1606 & #1712 Homepage does not display when deleting a feed

This commit is contained in:
Nicolas Le Goff
2014-03-03 19:07:59 +01:00
parent b8d2702975
commit 1ce11430fe
2 changed files with 27 additions and 20 deletions

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Cache\Exception as CacheException;
/** /**
* *
@@ -107,40 +108,34 @@ class Feed_Collection implements Feed_CollectionInterface, cache_cacheableInterf
*/ */
public static function load_public_feeds(Application $app) public static function load_public_feeds(Application $app)
{ {
$rs = self::retrieve_public_feed_ids($app['phraseanet.appbox']); $collection = new self($app, array());
$feeds = array();
foreach ($rs as $feed_id) {
$feeds[] = new Feed_Adapter($app, $feed_id);
}
return new self($app, $feeds);
}
protected static function retrieve_public_feed_ids(appbox $appbox)
{
$key = 'feedcollection_' . self::CACHE_PUBLIC;
try { try {
return $appbox->get_data_from_cache($key); $feedIds = $collection->get_data_from_cache(self::CACHE_PUBLIC);
} catch (\Exception $e) {
return new self($app, array_map(function($id) use ($app) {
return new \Feed_Adapter($app, $id);
}, $feedIds));
} catch (CacheException $e) {
} }
$sql = 'SELECT id FROM feeds WHERE public = "1" AND base_id IS null ORDER BY created_on DESC'; $sql = 'SELECT id FROM feeds WHERE public = "1" AND base_id IS null ORDER BY created_on DESC';
$stmt = $appbox->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(); $stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$feeds = array(); $feeds = array();
foreach ($rs as $row) { foreach ($rs as $row) {
$feeds[] = $row['id']; $feeds[] = new \Feed_Adapter($app, $row['id']);
} }
$appbox->set_data_to_cache($feeds, $key); $collection->set_data_to_cache(array_map(function($feed) {
return $feed->get_id();
}, $feeds), self::CACHE_PUBLIC);
return $feeds; return new self($app, $feeds);
} }
public function get_cache_key($option = null) public function get_cache_key($option = null)

View File

@@ -56,4 +56,16 @@ class Feed_CollectionTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertTrue($feed->is_public()); $this->assertTrue($feed->is_public());
} }
} }
public function testLoadPublicFeedsAfterDelete()
{
$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$title, self::$subtitle);
$feed->set_public(true);
$coll = Feed_Collection::load_public_feeds(self::$DI['app']);
$countBefore = count($coll->get_feeds());
$feed->delete();
$coll = Feed_Collection::load_public_feeds(self::$DI['app']);
$this->assertGreaterThan(count($coll->get_feeds()), $countBefore);
$feed->delete();
}
} }