diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-11-20 18:48:41 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-11-20 18:49:25 +0100 |
commit | fae882f834409e18174e05d19deea39a3bf01e7b (patch) | |
tree | 8bbac95e549db0d165aff7229de9b465ca8dd1ef | |
parent | bac9ffbc3a93a452270462cce69684e166856ce4 (diff) |
add a fingerprint for all articles
-rw-r--r-- | appinfo/database.xml | 13 | ||||
-rw-r--r-- | appinfo/info.xml | 2 | ||||
-rw-r--r-- | db/item.php | 6 | ||||
-rw-r--r-- | tests/unit/db/ItemTest.php | 9 |
4 files changed, 29 insertions, 1 deletions
diff --git a/appinfo/database.xml b/appinfo/database.xml index 0aa8305e5..b815cee05 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -227,6 +227,12 @@ <length>32</length> </field> <field> + <name>fingerprint</name> + <type>text</type> + <notnull>false</notnull> + <length>32</length> + </field> + <field> <name>rtl</name> <type>boolean</type> <notnull>true</notnull> @@ -306,6 +312,13 @@ </index> <index> + <name>news_items_fingerprint_index</name> + <field> + <name>fingerprint</name> + </field> + </index> + + <index> <name>news_items_item_guid</name> <field> <name>guid_hash</name> diff --git a/appinfo/info.xml b/appinfo/info.xml index c7d8700a2..917229787 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -7,7 +7,7 @@ <author>Bernhard Posselt, Alessandro Cosentino, Jan-Christoph Borchardt</author> <category>multimedia</category> <licence>AGPL</licence> - <version>6.1.1</version> + <version>6.1.2</version> <namespace>News</namespace> <!-- resources --> diff --git a/db/item.php b/db/item.php index c66b68a33..91b3215a6 100644 --- a/db/item.php +++ b/db/item.php @@ -61,6 +61,7 @@ class Item extends Entity implements IAPI, \JsonSerializable { protected $lastModified; protected $searchIndex; protected $rtl; + protected $fingerprint; public function __construct(){ $this->addType('pubDate', 'integer'); @@ -214,6 +215,11 @@ class Item extends Entity implements IAPI, \JsonSerializable { $this->getUrl() ) ); + $this->setFingerprint($this->computeFingerprint()); + } + + private function computeFingerprint() { + return md5($this->getTitle() . $this->getUrl() . $this->getBody()); } public function setUrl($url) { diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php index 2b2502d3a..174d9273b 100644 --- a/tests/unit/db/ItemTest.php +++ b/tests/unit/db/ItemTest.php @@ -289,5 +289,14 @@ class ItemTest extends \PHPUnit_Framework_TestCase { $item->getBody()); } + public function testComputeFingerPrint() { + $item = new Item(); + $item->setBody($body); + $item->setTitle($title); + $item->setUrl($url); + $item->generateSearchIndex(); + + $this->assertEquals(md5($title . $url . $body), $item->getFingerprint()); + } } |