diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/Feed.php | 653 | ||||
-rw-r--r-- | lib/Db/Folder.php | 158 | ||||
-rw-r--r-- | lib/Db/Item.php | 497 | ||||
-rw-r--r-- | lib/Service/FeedService.php | 6 | ||||
-rw-r--r-- | lib/Utility/OPMLExporter.php | 10 |
5 files changed, 1033 insertions, 291 deletions
diff --git a/lib/Db/Feed.php b/lib/Db/Feed.php index 7541ac545..898a93718 100644 --- a/lib/Db/Feed.php +++ b/lib/Db/Feed.php @@ -13,110 +13,268 @@ namespace OCA\News\Db; -use \OCP\AppFramework\Db\Entity; +use OCP\AppFramework\Db\Entity; -/** - * @method integer getId() - * @method void setId(integer $value) - * @method string getUserId() - * @method void setUserId(string $value) - * @method int getOrdering() - * @method void setOrdering(integer $value) - * @method string getUrlHash() - * @method void setUrlHash(string $value) - * @method string getLocation() - * @method void setLocation(string $value) - * @method string getUrl() - * @method string getTitle() - * @method void setTitle(string $value) - * @method string getLastModified() - * @method void setLastModified(string $value) - * @method string getHttpLastModified() - * @method void setHttpLastModified(string $value) - * @method string getHttpEtag() - * @method void setHttpEtag(string $value) - * @method string getFaviconLink() - * @method void setFaviconLink(string $value) - * @method integer getAdded() - * @method void setAdded(integer $value) - * @method boolean getPinned() - * @method void setPinned(boolean $value) - * @method integer getFolderId() - * @method void setFolderId(integer $value) - * @method integer getFullTextEnabled() - * @method void setFullTextEnabled(bool $value) - * @method integer getUnreadCount() - * @method void setUnreadCount(integer $value) - * @method string getLink() - * @method boolean getPreventUpdate() - * @method void setPreventUpdate(boolean $value) - * @method integer getDeletedAt() - * @method void setDeletedAt(integer $value) - * @method integer getArticlesPerUpdate() - * @method void setArticlesPerUpdate(integer $value) - * @method integer getUpdateErrorCount() - * @method void setUpdateErrorCount(integer $value) - * @method string getLastUpdateError() - * @method void setLastUpdateError(string $value) - * @method string getBasicAuthUser() - * @method void setBasicAuthUser(string $value) - * @method string getBasicAuthPassword() - * @method void setBasicAuthPassword(string $value) - */ class Feed extends Entity implements IAPI, \JsonSerializable { use EntityJSONSerializer; - protected $userId; + /** @var string */ + protected $userId = ''; + /** @var string */ protected $urlHash; + /** @var string */ protected $url; + /** @var string */ protected $title; - protected $faviconLink; - protected $added; + /** @var string|null */ + protected $faviconLink = null; + /** @var int|null */ + protected $added = 0; + /** @var int */ protected $folderId; + /** @var int */ protected $unreadCount; - protected $link; - protected $preventUpdate; - protected $deletedAt; - protected $articlesPerUpdate; - protected $httpLastModified; - protected $lastModified; - protected $httpEtag; - protected $location; - protected $ordering; - protected $fullTextEnabled; - protected $pinned; - protected $updateMode; - protected $updateErrorCount; - protected $lastUpdateError; - protected $basicAuthUser; - protected $basicAuthPassword; - - public function __construct() - { - $this->addType('parentId', 'integer'); - $this->addType('added', 'integer'); - $this->addType('folderId', 'integer'); - $this->addType('unreadCount', 'integer'); - $this->addType('preventUpdate', 'boolean'); - $this->addType('pinned', 'boolean'); - $this->addType('deletedAt', 'integer'); - $this->addType('articlesPerUpdate', 'integer'); - $this->addType('ordering', 'integer'); - $this->addType('fullTextEnabled', 'boolean'); - $this->addType('updateMode', 'integer'); - $this->addType('updateErrorCount', 'integer'); - } - - - /** - * Turns entitie attributes into an array - */ - public function jsonSerialize() - { - $serialized = $this->serializeFields( - [ + /** @var string|null */ + protected $link = null; + /** @var bool */ + protected $preventUpdate = false; + /** @var int|null */ + protected $deletedAt = 0; + /** @var int */ + protected $articlesPerUpdate = 0; + /** @var string|null */ + protected $httpLastModified = null; + /** @var int|null */ + protected $lastModified = 0; + /** @var string|null */ + protected $httpEtag = null; + /** @var string|null */ + protected $location = null; + /** @var int */ + protected $ordering = 0; + /** @var bool */ + protected $fullTextEnabled = false; + /** @var bool */ + protected $pinned = false; + /** @var int */ + protected $updateMode = 0; + /** @var int */ + protected $updateErrorCount = 0; + /** @var string|null */ + protected $lastUpdateError = ''; + /** @var string|null */ + protected $basicAuthUser = ''; + /** @var string|null */ + protected $basicAuthPassword = ''; + + /** + * @return int|null + */ + public function getAdded() + { + return $this->added; + } + + /** + * @return int + */ + public function getArticlesPerUpdate(): int + { + return $this->articlesPerUpdate; + } + + /** + * @return string|null + */ + public function getBasicAuthPassword() + { + return $this->basicAuthPassword; + } + + /** + * @return string|null + */ + public function getBasicAuthUser() + { + return $this->basicAuthUser; + } + + /** + * @return int|null + */ + public function getDeletedAt() + { + return $this->deletedAt; + } + + /** + * @return string|null + */ + public function getFaviconLink() + { + return $this->faviconLink; + } + + /** + * @return int + */ + public function getFolderId(): int + { + return $this->folderId; + } + + /** + * @return bool + */ + public function getFullTextEnabled(): bool + { + return $this->fullTextEnabled; + } + + /** + * @return string|null + */ + public function getHttpEtag() + { + return $this->httpEtag; + } + + /** + * @return string|null + */ + public function getHttpLastModified() + { + return $this->httpLastModified; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return int|null + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * @return string|null + */ + public function getLastUpdateError() + { + return $this->lastUpdateError; + } + + /** + * @return string|null + */ + public function getLink() + { + return $this->link; + } + + /** + * @return string|null + */ + public function getLocation() + { + return $this->location; + } + + /** + * @return int + */ + public function getOrdering(): int + { + return $this->ordering; + } + + /** + * @return bool + */ + public function getPinned(): bool + { + return $this->pinned; + } + + /** + * @return bool + */ + public function getPreventUpdate(): bool + { + return $this->preventUpdate; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return int + */ + public function getUnreadCount(): int + { + return $this->unreadCount; + } + + /** + * @return int + */ + public function getUpdateErrorCount(): int + { + return $this->updateErrorCount; + } + + /** + * @return int + */ + public function getUpdateMode(): int + { + return $this->updateMode; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @return string + */ + public function getUrlHash(): string + { + return $this->urlHash; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * Turns entity attributes into an array + */ + public function jsonSerialize(): array + { + $serialized = $this->serializeFields([ 'id', 'userId', 'urlHash', @@ -139,8 +297,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable 'lastUpdateError', 'basicAuthUser', 'basicAuthPassword' - ] - ); + ]); $url = parse_url($this->link, PHP_URL_HOST); @@ -154,45 +311,301 @@ class Feed extends Entity implements IAPI, \JsonSerializable return $serialized; } + /** + * @param int|null $added + */ + public function setAdded(int $added = null) + { + if ($this->added !== $added) { + $this->added = $added; + $this->markFieldUpdated('added'); + } + } - public function toAPI() + /** + * @param int $articlesPerUpdate + */ + public function setArticlesPerUpdate(int $articlesPerUpdate) { - return $this->serializeFields( - [ - 'id', - 'url', - 'title', - 'faviconLink', - 'added', - 'folderId', - 'unreadCount', - 'ordering', - 'link', - 'pinned', - 'updateErrorCount', - 'lastUpdateError' - ] - ); + if ($this->articlesPerUpdate !== $articlesPerUpdate) { + $this->articlesPerUpdate = $articlesPerUpdate; + $this->markFieldUpdated('articlesPerUpdate'); + } } + /** + * @param string|null $basicAuthPassword + */ + public function setBasicAuthPassword(string $basicAuthPassword = null) + { + if ($this->basicAuthPassword !== $basicAuthPassword) { + $this->basicAuthPassword = $basicAuthPassword; + $this->markFieldUpdated('basicAuthPassword'); + } + } - public function setUrl($url) + /** + * @param string|null $basicAuthUser + */ + public function setBasicAuthUser(string $basicAuthUser = null) { - $url = trim($url); - if(strpos($url, 'http') === 0) { - parent::setUrl($url); - $this->setUrlHash(md5($url)); + if ($this->basicAuthUser !== $basicAuthUser) { + $this->basicAuthUser = $basicAuthUser; + $this->markFieldUpdated('basicAuthUser'); + } + } + + /** + * @param int|null $deletedAt + */ + public function setDeletedAt(int $deletedAt = null) + { + if ($this->deletedAt !== $deletedAt) { + $this->deletedAt = $deletedAt; + $this->markFieldUpdated('deletedAt'); + } + } + + /** + * @param string|null $faviconLink + */ + public function setFaviconLink(string $faviconLink = null) + { + if ($this->faviconLink !== $faviconLink) { + $this->faviconLink = $faviconLink; + $this->markFieldUpdated('faviconLink'); + } + } + + /** + * @param int $folderId + */ + public function setFolderId(int $folderId) + { + if ($this->folderId !== $folderId) { + $this->folderId = $folderId; + $this->markFieldUpdated('folderId'); + } + } + + /** + * @param bool $fullTextEnabled + */ + public function setFullTextEnabled(bool $fullTextEnabled) + { + if ($this->fullTextEnabled !== $fullTextEnabled) { + $this->fullTextEnabled = $fullTextEnabled; + $this->markFieldUpdated('fullTextEnabled'); + } + } + + /** + * @param string|null $httpEtag + */ + public function setHttpEtag(string $httpEtag = null) + { + if ($this->httpEtag !== $httpEtag) { + $this->httpEtag = $httpEtag; + $this->markFieldUpdated('httpEtag'); + } + } + + /** + * @param string|null $httpLastModified + */ + public function setHttpLastModified(string $httpLastModified = null) + { + if ($this->httpLastModified !== $httpLastModified) { + $this->httpLastModified = $httpLastModified; + $this->markFieldUpdated('httpLastModified'); + } + } + + /** + * @param int $id + */ + public function setId(int $id) + { + if ($this->id !== $id) { + $this->id = $id; + $this->markFieldUpdated('id'); + } + } + + /** + * @param int|null $lastModified + */ + public function setLastModified(int $lastModified = null) + { + if ($this->lastModified !== $lastModified) { + $this->lastModified = $lastModified; + $this->markFieldUpdated('lastModified'); + } + } + + /** + * @param string|null $lastUpdateError + */ + public function setLastUpdateError(string $lastUpdateError = null) + { + if ($this->lastUpdateError !== $lastUpdateError) { + $this->lastUpdateError = $lastUpdateError; + $this->markFieldUpdated('lastUpdateError'); } } + /** + * @param string|null $link + */ + public function setLink(string $link = null) + { + $link = trim($link); + if (strpos($link, 'http') === 0 && $this->link !== $link) { + $this->link = $link; + $this->markFieldUpdated('link'); + } + } - public function setLink($url) + /** + * @param string|null $location + */ + public function setLocation(string $location = null) + { + if ($this->location !== $location) { + $this->location = $location; + $this->markFieldUpdated('location'); + } + } + + /** + * @param int $ordering + */ + public function setOrdering(int $ordering) + { + if ($this->ordering !== $ordering) { + $this->ordering = $ordering; + $this->markFieldUpdated('ordering'); + } + } + + /** + * @param bool $pinned + */ + public function setPinned(bool $pinned) + { + if ($this->pinned !== $pinned) { + $this->pinned = $pinned; + $this->markFieldUpdated('pinned'); + } + } + + /** + * @param bool $preventUpdate + */ + public function setPreventUpdate(bool $preventUpdate) + { + if ($this->preventUpdate !== $preventUpdate) { + $this->preventUpdate = $preventUpdate; + $this->markFieldUpdated('preventUpdate'); + } + } + + /** + * @param string $title + */ + public function setTitle(string $title) + { + if ($this->title !== $title) { + $this->title = $title; + $this->markFieldUpdated('title'); + } + } + + /** + * @param int $unreadCount + */ + public function setUnreadCount(int $unreadCount) + { + if ($this->unreadCount !== $unreadCount) { + $this->unreadCount = $unreadCount; + $this->markFieldUpdated('unreadCount'); + } + } + + /** + * @param int $updateErrorCount + */ + public function setUpdateErrorCount(int $updateErrorCount) + { + if ($this->updateErrorCount !== $updateErrorCount) { + $this->updateErrorCount = $updateErrorCount; + $this->markFieldUpdated('updateErrorCount'); + } + } + + /** + * @param int $updateMode + */ + public function setUpdateMode(int $updateMode) + { + if ($this->updateMode !== $updateMode) { + $this->updateMode = $updateMode; + $this->markFieldUpdated('updateMode'); + } + } + + /** + * @param string $url + */ + public function setUrl(string $url) { $url = trim($url); - if(strpos($url, 'http') === 0) { - parent::setLink($url); + if (strpos($url, 'http') === 0 && $this->url !== $url) { + $this->url = $url; + $this->setUrlHash(md5($url)); + $this->markFieldUpdated('url'); } } + /** + * @param string $urlHash + */ + public function setUrlHash(string $urlHash) + { + if ($this->urlHash !== $urlHash) { + $this->urlHash = $urlHash; + $this->markFieldUpdated('urlHash'); + } + } + + /** + * @param string $userId + */ + public function setUserId(string $userId) + { + if ($this->userId !== $userId) { + $this->userId = $userId; + $this->markFieldUpdated('userId'); + } + } + public function toAPI(): array + { + return $this->serializeFields( + [ + 'id', + 'url', + 'title', + 'faviconLink', + 'added', + 'folderId', + 'unreadCount', + 'ordering', + 'link', + 'pinned', + 'updateErrorCount', + 'lastUpdateError' + ] + ); + } } diff --git a/lib/Db/Folder.php b/lib/Db/Folder.php index 4a6ec8ba1..07fa7b369 100644 --- a/lib/Db/Folder.php +++ b/lib/Db/Folder.php @@ -13,67 +13,151 @@ namespace OCA\News\Db; -use \OCP\AppFramework\Db\Entity; +use OCP\AppFramework\Db\Entity; -/** - * @method integer getId() - * @method void setId(integer $value) - * @method string getUserId() - * @method void setUserId(string $value) - * @method string getName() - * @method void setName(string $value) - * @method integer getParentId() - * @method void setParentId(integer $value) - * @method boolean getOpened() - * @method void setOpened(boolean $value) - * @method integer getDeletedAt() - * @method void setDeletedAt(integer $value) - * @method string getLastModified() - * @method void setLastModified(string $value) - */ class Folder extends Entity implements IAPI, \JsonSerializable { use EntityJSONSerializer; + /** @var int|null */ protected $parentId; + /** @var string */ protected $name; - protected $userId; - protected $opened; - protected $deletedAt; - protected $lastModified; + /** @var string */ + protected $userId = ''; + /** @var bool */ + protected $opened = true; + /** @var int|null */ + protected $deletedAt = 0; + /** @var int|null */ + protected $lastModified = 0; + + /** + * @return int|null + */ + public function getDeletedAt() + { + return $this->deletedAt; + } + + public function getId(): int + { + return $this->id; + } + + /** + * @return int|null + */ + public function getLastModified() + { + return $this->lastModified; + } + + public function getName(): string + { + return $this->name; + } + + public function getOpened(): bool + { + return $this->opened; + } + + /** + * @return int|null + */ + public function getParentId() + { + return $this->parentId; + } - public function __construct() + public function getUserId(): string { - $this->addType('parentId', 'integer'); - $this->addType('opened', 'boolean'); - $this->addType('deletedAt', 'integer'); + return $this->userId; } /** - * Turns entitie attributes into an array + * Turns entity attributes into an array */ - public function jsonSerialize() + public function jsonSerialize(): array { return $this->serializeFields( [ - 'id', - 'parentId', - 'name', - 'userId', - 'opened', - 'deletedAt', + 'id', + 'parentId', + 'name', + 'userId', + 'opened', + 'deletedAt', ] ); } - public function toAPI() + public function setDeletedAt(int $deletedAt = null) + { + if ($this->deletedAt !== $deletedAt) { + $this->deletedAt = $deletedAt; + $this->markFieldUpdated('deletedAt'); + } + } + + public function setId(int $id) + { + if ($this->id !== $id) { + $this->id = $id; + $this->markFieldUpdated('id'); + } + } + + public function setLastModified(int $lastModified = null) + { + + if ($this->lastModified !== $lastModified) { + $this->lastModified = $lastModified; + $this->markFieldUpdated('lastModified'); + } + } + + public function setName(string $name) + { + if ($this->name !== $name) { + $this->name = $name; + $this->markFieldUpdated('name'); + } + } + + public function setOpened(bool $opened) + { + if ($this->opened !== $opened) { + $this->opened = $opened; + $this->markFieldUpdated('opened'); + } + } + + public function setParentId(int $parentId = null) + { + if ($this->parentId !== $parentId) { + $this->parentId = $parentId; + $this->markFieldUpdated('parentId'); + } + } + + public function setUserId(string $userId) + { + if ($this->userId !== $userId) { + $this->userId = $userId; + $this->markFieldUpdated('userId'); + } + } + + public function toAPI(): array { return $this->serializeFields( [ - 'id', - 'name' + 'id', + 'name' ] ); } -}
\ No newline at end of file +} diff --git a/lib/Db/Item.php b/lib/Db/Item.php index 1c31f9d70..91c79e44b 100644 --- a/lib/Db/Item.php +++ b/lib/Db/Item.php @@ -13,88 +13,240 @@ namespace OCA\News\Db; -use \OCP\AppFramework\Db\Entity; +use OCP\AppFramework\Db\Entity; -/** - * @method integer getId() - * @method void setId(integer $value) - * @method string getGuid() - * @method void setGuid(string $value) - * @method string getGuidHash() - * @method void setGuidHash(string $value) - * @method string getUrl() - * @method string getTitle() - * @method string getAuthor() - * @method string getRtl() - * @method string getFingerprint() - * @method string getContentHash() - * @method integer getPubDate() - * @method void setPubDate(integer $value) - * @method string getBody() - * @method string getEnclosureMime() - * @method void setEnclosureMime(string $value) - * @method string getEnclosureLink() - * @method void setEnclosureLink(string $value) - * @method integer getFeedId() - * @method void setFeedId(integer $value) - * @method void setRtl(boolean $value) - * @method string getLastModified() - * @method void setLastModified(string $value) - * @method void setFingerprint(string $value) - * @method void setContentHash(string $value) - * @method void setSearchIndex(string $value) - * @method void setUnread(bool $value) - * @method void setStarred(bool $value) - */ class Item extends Entity implements IAPI, \JsonSerializable { use EntityJSONSerializer; + /** @var string|null */ protected $contentHash; + /** @var string */ protected $guidHash; + /** @var string */ protected $guid; + /** @var string|null */ protected $url; + /** @var string|null */ protected $title; + /** @var string|null */ protected $author; + /** @var int|null */ protected $pubDate; + /** @var int|null */ protected $updatedDate; + /** @var string|null */ protected $body; + /** @var string|null */ protected $enclosureMime; + /** @var string|null */ protected $enclosureLink; + /** @var int */ protected $feedId; + /** @var int */ protected $status = 0; - protected $lastModified; + /** @var int|null */ + protected $lastModified = 0; + /** @var string|null */ protected $searchIndex; - protected $rtl; + /** @var bool */ + protected $rtl = false; + /** @var string|null */ protected $fingerprint; + /** @var bool */ protected $unread = false; + /** @var bool */ protected $starred = false; - public function __construct() + /** + * @return int + */ + public function cropApiLastModified(): int { - $this->addType('pubDate', 'integer'); - $this->addType('updatedDate', 'integer'); - $this->addType('feedId', 'integer'); - $this->addType('rtl', 'boolean'); - $this->addType('unread', 'boolean'); - $this->addType('starred', 'boolean'); + $lastModified = $this->getLastModified(); + if (strlen((string)$lastModified) > 10) { + return (int)substr($lastModified, 0, -6); + } else { + return (int)$lastModified; + } } - public function isUnread() + public static function fromImport($import): Item { - return $this->unread; + $item = new static(); + $item->setGuid($import['guid']); + $item->setGuidHash($import['guid']); + $item->setUrl($import['url']); + $item->setTitle($import['title']); + $item->setAuthor($import['author']); + $item->setPubDate($import['pubDate']); + $item->setUpdatedDate($import['updatedDate']); + $item->setBody($import['body']); + $item->setEnclosureMime($import['enclosureMime']); + $item->setEnclosureLink($import['enclosureLink']); + $item->setRtl($import['rtl']); + $item->setUnread($import['unread']); + $item->setStarred($import['starred']); + + return $item; + } + + public function generateSearchIndex() + { + $this->setSearchIndex( + mb_strtolower( + html_entity_decode(strip_tags($this->getBody())) . + html_entity_decode($this->getAuthor()) . + html_entity_decode($this->getTitle()) . + $this->getUrl(), + 'UTF-8' + ) + ); + $this->setFingerprint($this->computeFingerprint()); + $this->setContentHash($this->computeContentHash()); + } + + /** + * @return null|string + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @return null|string + */ + public function getBody() + { + return $this->body; + } + + /** + * @return null|string + */ + public function getContentHash() + { + return $this->contentHash; + } + + /** + * @return null|string + */ + public function getEnclosureLink() + { + return $this->enclosureLink; + } + + /** + * @return null|string + */ |