summaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2016-05-28 12:49:48 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2016-05-28 12:49:48 +0200
commit782896cb44c6d64af088c951768d6ec1fb0b0f9f (patch)
tree94a8c06287e05a84a789d515d3fb0aaf45fe759a /db
parenta92d104327a34c0c64ac0443a2c39dc29749a15c (diff)
Add content hash to items
Diffstat (limited to 'db')
-rw-r--r--db/item.php40
1 files changed, 22 insertions, 18 deletions
diff --git a/db/item.php b/db/item.php
index 1ef74061e..e0d8b069b 100644
--- a/db/item.php
+++ b/db/item.php
@@ -5,8 +5,8 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Alessandro Cosentino 2012
* @copyright Bernhard Posselt 2012, 2014
*/
@@ -15,7 +15,6 @@ namespace OCA\News\Db;
use \OCP\AppFramework\Db\Entity;
-
/**
* @method integer getId()
* @method void setId(integer $value)
@@ -28,6 +27,7 @@ use \OCP\AppFramework\Db\Entity;
* @method string getAuthor()
* @method string getRtl()
* @method string getFingerprint()
+ * @method string getContentHash()
* @method integer getPubDate()
* @method void setPubDate(integer $value)
* @method string getBody()
@@ -43,12 +43,14 @@ use \OCP\AppFramework\Db\Entity;
* @method integer getLastModified()
* @method void setLastModified(integer $value)
* @method void setFingerprint(string $value)
+ * @method void setContentHash(string $value)
* @method void setSearchIndex(string $value)
*/
class Item extends Entity implements IAPI, \JsonSerializable {
use EntityJSONSerializer;
+ protected $contentHash;
protected $guidHash;
protected $guid;
protected $url;
@@ -65,7 +67,7 @@ class Item extends Entity implements IAPI, \JsonSerializable {
protected $rtl;
protected $fingerprint;
- public function __construct(){
+ public function __construct() {
$this->addType('pubDate', 'integer');
$this->addType('feedId', 'integer');
$this->addType('status', 'integer');
@@ -73,7 +75,6 @@ class Item extends Entity implements IAPI, \JsonSerializable {
$this->addType('rtl', 'boolean');
}
-
public function setRead() {
$this->markFieldUpdated('status');
$this->status &= ~StatusFlag::UNREAD;
@@ -131,7 +132,7 @@ class Item extends Entity implements IAPI, \JsonSerializable {
'lastModified' => $this->getLastModified(),
'rtl' => $this->getRtl(),
'intro' => $this->getIntro(),
- 'fingerprint' => $this->getFingerprint()
+ 'fingerprint' => $this->getFingerprint(),
];
}
@@ -152,11 +153,11 @@ class Item extends Entity implements IAPI, \JsonSerializable {
'starred' => $this->isStarred(),
'lastModified' => $this->getLastModified(),
'rtl' => $this->getRtl(),
- 'fingerprint' => $this->getFingerprint()
+ 'fingerprint' => $this->getFingerprint(),
+ 'contentHash' => $this->getContentHash()
];
}
-
public function toExport($feeds) {
return [
'guid' => $this->getGuid(),
@@ -169,12 +170,11 @@ class Item extends Entity implements IAPI, \JsonSerializable {
'enclosureLink' => $this->getEnclosureLink(),
'unread' => $this->isUnread(),
'starred' => $this->isStarred(),
- 'feedLink' => $feeds['feed'. $this->getFeedId()]->getLink(),
- 'rtl' => $this->getRtl()
+ 'feedLink' => $feeds['feed' . $this->getFeedId()]->getLink(),
+ 'rtl' => $this->getRtl(),
];
}
-
public function getIntro() {
return strip_tags($this->getBody());
}
@@ -191,12 +191,12 @@ class Item extends Entity implements IAPI, \JsonSerializable {
$item->setEnclosureMime($import['enclosureMime']);
$item->setEnclosureLink($import['enclosureLink']);
$item->setRtl($import['rtl']);
- if($import['unread']) {
+ if ($import['unread']) {
$item->setUnread();
} else {
$item->setRead();
}
- if($import['starred']) {
+ if ($import['starred']) {
$item->setStarred();
} else {
$item->setUnstarred();
@@ -205,12 +205,10 @@ class Item extends Entity implements IAPI, \JsonSerializable {
return $item;
}
-
public function setAuthor($name) {
parent::setAuthor(strip_tags($name));
}
-
public function setTitle($title) {
parent::setTitle(strip_tags($title));
}
@@ -226,21 +224,27 @@ class Item extends Entity implements IAPI, \JsonSerializable {
)
);
$this->setFingerprint($this->computeFingerprint());
+ $this->setContentHash($this->computeContentHash());
+ }
+
+ private function computeContentHash() {
+ return md5($this->getTitle() . $this->getUrl() . $this->getBody() .
+ $this->getEnclosureLink() . $this->getEnclosureMime() .
+ $this->getAuthor());
}
private function computeFingerprint() {
return md5($this->getTitle() . $this->getUrl() . $this->getBody() .
- $this->getEnclosureLink());
+ $this->getEnclosureLink());
}
public function setUrl($url) {
$url = trim($url);
- if(strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0) {
+ if (strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0) {
parent::setUrl($url);
}
}
-
public function setBody($body) {
// FIXME: this should not happen if the target="_blank" is already
// on the link