diff --git a/lib/classes/Feed/Entry/Adapter.class.php b/lib/classes/Feed/Entry/Adapter.class.php index 0c241d5c80..5049af587f 100644 --- a/lib/classes/Feed/Entry/Adapter.class.php +++ b/lib/classes/Feed/Entry/Adapter.class.php @@ -127,7 +127,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa return $this; } catch (Exception $e) { - + } $sql = 'SELECT publisher, title, description, created_on, updated_on @@ -215,6 +215,31 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa return $this->subtitle; } + /** + * Change the parent feed of the entry + * + * @param Feed_Adapter $feed + * @return \Feed_Entry_Adapter + */ + public function set_feed(Feed_Adapter $feed) + { + $sql = 'UPDATE feed_entries + SET feed_id = :feed_id, updated_on = NOW() WHERE id = :entry_id'; + $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt->execute(array( + ':feed_id' => $feed->get_id(), + ':entry_id' => $this->get_id(), + )); + $stmt->closeCursor(); + + $this->feed->delete_data_from_cache(); + $this->feed = $feed; + $feed->delete_data_from_cache(); + $this->delete_data_from_cache(); + + return $this; + } + /** * * @param string $title @@ -416,7 +441,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa try { $items[] = new Feed_Entry_Item($this->appbox, $this, $item_id); } catch (Exception_NotFound $e) { - + } } @@ -430,7 +455,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa try { return $this->get_data_from_cache(self::CACHE_ELEMENTS); } catch (Exception $e) { - + } $sql = 'SELECT id FROM feed_entry_elements @@ -499,12 +524,12 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa , :description, NOW(), NOW(), :author_name, :author_email)'; $params = array( - ':feed_id' => $feed->get_id() - , ':publisher_id' => $publisher->get_id() - , ':title' => trim($title) - , ':description' => trim($subtitle) - , ':author_name' => trim($author_name) - , ':author_email' => trim($author_mail) + ':feed_id' => $feed->get_id(), + ':publisher_id' => $publisher->get_id(), + ':title' => trim($title), + ':description' => trim($subtitle), + ':author_name' => trim($author_name), + ':author_email' => trim($author_mail), ); $stmt = $appbox->get_connection()->prepare($sql); diff --git a/tests/Feed/Entry/Feed_Entry_AdapterTest.php b/tests/Feed/Entry/Feed_Entry_AdapterTest.php index d3b2f14d4b..5514f8f35f 100644 --- a/tests/Feed/Entry/Feed_Entry_AdapterTest.php +++ b/tests/Feed/Entry/Feed_Entry_AdapterTest.php @@ -74,7 +74,7 @@ class Feed_Entry_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract self::$object->set_title(''); $this->fail(); } catch (Exception_InvalidArgument $e) { - + } } @@ -98,6 +98,21 @@ class Feed_Entry_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract $this->assertEquals(self::$author_name, self::$object->get_author_name()); } + public function testSetFeed() + { + $appbox = appbox::get_instance(\bootstrap::getCore()); + $new_feed = Feed_Adapter::create($appbox, self::$user, self::$feed_title, self::$feed_subtitle); + + $publisher = Feed_Publisher_Adapter::getPublisher($appbox, $new_feed, self::$user); + $entry = Feed_Entry_Adapter::create($appbox, self::$feed, $publisher, self::$title, self::$subtitle, self::$author_name, self::$author_email); + + $this->assertEquals(self::$feed, $entry->get_feed()); + $entry->set_feed($new_feed); + $this->assertEquals($new_feed, $entry->get_feed()); + + $new_feed->delete(); + } + public function testSet_author_email() { $new_email = 'Tintin@herge.be';