Merge pull request #715 from romainneutron/fix-1550

[3.8] Fix #1550 : Remove feed entry items that are not related to a record
This commit is contained in:
Romain Neutron
2013-10-25 10:05:09 -07:00
2 changed files with 56 additions and 4 deletions

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* *
@@ -273,9 +274,26 @@ class Feed_Entry_Item implements Feed_Entry_ItemInterface, cache_cacheableInterf
} }
if (!isset($items[$row['item']])) { if (!isset($items[$row['item']])) {
$item = new self($app['phraseanet.appbox'], $entries[$row['entry']], $row['item']); try {
$item = new self($app['phraseanet.appbox'], $entries[$row['entry']], $row['item']);
$record = $item->get_record();
} catch (NotFoundHttpException $e) {
$sql = 'DELETE FROM feed_entry_elements WHERE id = :id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':id' => $row['item']));
$stmt->closeCursor();
if (null !== $preview = $item->get_record()->get_subdef('preview')) { continue;
} catch (\Exception_Record_AdapterNotFound $e) {
$sql = 'DELETE FROM feed_entry_elements WHERE id = :id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':id' => $row['item']));
$stmt->closeCursor();
continue;
}
if (null !== $preview = $record->get_subdef('preview')) {
if (null !== $permalink = $preview->get_permalink()) { if (null !== $permalink = $preview->get_permalink()) {
$items[$row['item']] = $item; $items[$row['item']] = $item;

View File

@@ -1,5 +1,7 @@
<?php <?php
use Alchemy\Phrasea\Border\File;
class Feed_Entry_ItemTest extends PhraseanetPHPUnitAuthenticatedAbstract class Feed_Entry_ItemTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
/** /**
@@ -32,7 +34,7 @@ class Feed_Entry_ItemTest extends PhraseanetPHPUnitAuthenticatedAbstract
self::$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_title, self::$feed_subtitle); self::$feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_title, self::$feed_subtitle);
$publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']); $publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']);
self::$entry = Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, $publisher, self::$title, self::$subtitle, self::$author_name, self::$author_email); self::$entry = Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, $publisher, self::$title, self::$subtitle, self::$author_name, self::$author_email, false);
self::$object = Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], self::$entry, self::$DI['record_1']); self::$object = Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], self::$entry, self::$DI['record_1']);
} }
@@ -106,6 +108,38 @@ class Feed_Entry_ItemTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertCount(0, Feed_Entry_Item::loadLatest(self::$DI['app'], 20)); $this->assertCount(0, Feed_Entry_Item::loadLatest(self::$DI['app'], 20));
} }
public function testLoadLatestWithDeletedDatabox()
{
$this->deleteEntries();
self::$feed->set_public(true);
$sql = 'INSERT INTO feed_entry_elements
(id, entry_id, sbas_id, record_id)
VALUES (null, :entry_id, :sbas_id, :record_id)';
$stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':entry_id' => self::$entry->get_id(), ':sbas_id' => self::$DI['record_1']->get_databox()->get_sbas_id(), ':record_id' => 0));
$stmt->closeCursor();
$this->assertCount(0, Feed_Entry_Item::loadLatest(self::$DI['app'], 20));
}
public function testLoadLatestWithDeletedRecord()
{
$this->deleteEntries();
self::$feed->set_public(true);
$sql = 'INSERT INTO feed_entry_elements
(id, entry_id, sbas_id, record_id)
VALUES (null, :entry_id, :sbas_id, :record_id)';
$stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':entry_id' => self::$entry->get_id(), ':sbas_id' => -24, ':record_id' => 0));
$stmt->closeCursor();
$this->assertCount(0, Feed_Entry_Item::loadLatest(self::$DI['app'], 20));
}
public function testIs_record_in_public_feed() public function testIs_record_in_public_feed()
{ {
$this->deleteEntries(); $this->deleteEntries();
@@ -123,7 +157,7 @@ class Feed_Entry_ItemTest extends PhraseanetPHPUnitAuthenticatedAbstract
private function deleteEntries() private function deleteEntries()
{ {
$sql = "TRUNCATE feed_entry_elements"; $sql = "DELETE FROM feed_entry_elements";
$stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(); $stmt->execute();
$stmt->closeCursor(); $stmt->closeCursor();