diff options
Diffstat (limited to 'lib/Db')
-rw-r--r-- | lib/Db/EntityJSONSerializer.php | 10 | ||||
-rw-r--r-- | lib/Db/Feed.php | 38 | ||||
-rw-r--r-- | lib/Db/FeedMapperV2.php | 2 | ||||
-rw-r--r-- | lib/Db/Folder.php | 20 | ||||
-rw-r--r-- | lib/Db/FolderMapperV2.php | 2 | ||||
-rw-r--r-- | lib/Db/Item.php | 84 | ||||
-rw-r--r-- | lib/Db/ItemMapperV2.php | 10 | ||||
-rw-r--r-- | lib/Db/NewsMapperV2.php | 3 |
8 files changed, 91 insertions, 78 deletions
diff --git a/lib/Db/EntityJSONSerializer.php b/lib/Db/EntityJSONSerializer.php index 3afc18202..2646ed97a 100644 --- a/lib/Db/EntityJSONSerializer.php +++ b/lib/Db/EntityJSONSerializer.php @@ -16,8 +16,14 @@ namespace OCA\News\Db; trait EntityJSONSerializer { - - public function serializeFields($properties) + /** + * Serialize object properties. + * + * @param array $properties Serializable properties + * + * @return array + */ + public function serializeFields(array $properties): array { $result = []; foreach ($properties as $property) { diff --git a/lib/Db/Feed.php b/lib/Db/Feed.php index ae01c3d6c..9af2f7dc2 100644 --- a/lib/Db/Feed.php +++ b/lib/Db/Feed.php @@ -95,7 +95,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getBasicAuthPassword() + public function getBasicAuthPassword(): ?string { return $this->basicAuthPassword; } @@ -103,7 +103,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getBasicAuthUser() + public function getBasicAuthUser(): ?string { return $this->basicAuthUser; } @@ -111,7 +111,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getDeletedAt() + public function getDeletedAt(): ?int { return $this->deletedAt; } @@ -119,7 +119,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getFaviconLink() + public function getFaviconLink(): ?string { return $this->faviconLink; } @@ -167,7 +167,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLastModified() + public function getLastModified(): ?string { return $this->lastModified; } @@ -175,7 +175,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLastUpdateError() + public function getLastUpdateError(): ?string { return $this->lastUpdateError; } @@ -183,7 +183,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLink() + public function getLink(): ?string { return $this->link; } @@ -191,7 +191,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLocation() + public function getLocation(): ?string { return $this->location; } @@ -321,7 +321,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param int|null $added */ - public function setAdded(int $added = null): Feed + public function setAdded(?int $added = null): Feed { if ($this->added !== $added) { $this->added = $added; @@ -347,7 +347,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $basicAuthPassword */ - public function setBasicAuthPassword(string $basicAuthPassword = null): Feed + public function setBasicAuthPassword(?string $basicAuthPassword = null): Feed { if ($this->basicAuthPassword !== $basicAuthPassword) { $this->basicAuthPassword = $basicAuthPassword; @@ -360,7 +360,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $basicAuthUser */ - public function setBasicAuthUser(string $basicAuthUser = null): Feed + public function setBasicAuthUser(?string $basicAuthUser = null): Feed { if ($this->basicAuthUser !== $basicAuthUser) { $this->basicAuthUser = $basicAuthUser; @@ -373,7 +373,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param int|null $deletedAt */ - public function setDeletedAt(int $deletedAt = null): Feed + public function setDeletedAt(?int $deletedAt = null): Feed { if ($this->deletedAt !== $deletedAt) { $this->deletedAt = $deletedAt; @@ -386,7 +386,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $faviconLink */ - public function setFaviconLink(string $faviconLink = null): Feed + public function setFaviconLink(?string $faviconLink = null): Feed { if ($this->faviconLink !== $faviconLink) { $this->faviconLink = $faviconLink; @@ -425,7 +425,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $httpEtag */ - public function setHttpEtag(string $httpEtag = null): Feed + public function setHttpEtag(?string $httpEtag = null): Feed { if ($this->httpEtag !== $httpEtag) { $this->httpEtag = $httpEtag; @@ -438,7 +438,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $httpLastModified */ - public function setHttpLastModified(string $httpLastModified = null): Feed + public function setHttpLastModified(?string $httpLastModified = null): Feed { if ($this->httpLastModified !== $httpLastModified) { $this->httpLastModified = $httpLastModified; @@ -464,7 +464,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $lastModified */ - public function setLastModified(string $lastModified = null): Feed + public function setLastModified(?string $lastModified = null): Feed { if ($this->lastModified !== $lastModified) { $this->lastModified = $lastModified; @@ -477,7 +477,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $lastUpdateError */ - public function setLastUpdateError(string $lastUpdateError = null): Feed + public function setLastUpdateError(?string $lastUpdateError = null): Feed { if ($this->lastUpdateError !== $lastUpdateError) { $this->lastUpdateError = $lastUpdateError; @@ -490,7 +490,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $link */ - public function setLink(string $link = null): Feed + public function setLink(?string $link = null): Feed { $link = trim($link); if (strpos($link, 'http') === 0 && $this->link !== $link) { @@ -504,7 +504,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $location */ - public function setLocation(string $location = null): Feed + public function setLocation(?string $location = null): Feed { if ($this->location !== $location) { $this->location = $location; diff --git a/lib/Db/FeedMapperV2.php b/lib/Db/FeedMapperV2.php index 2b4ff8f10..a7edecd88 100644 --- a/lib/Db/FeedMapperV2.php +++ b/lib/Db/FeedMapperV2.php @@ -46,7 +46,7 @@ class FeedMapperV2 extends NewsMapperV2 * * @return Entity[] */ - public function findAllFromUser(string $userId): array + public function findAllFromUser(string $userId, array $params = []): array { $builder = $this->db->getQueryBuilder(); $builder->addSelect('*') diff --git a/lib/Db/Folder.php b/lib/Db/Folder.php index 674c9fabc..eb3389546 100644 --- a/lib/Db/Folder.php +++ b/lib/Db/Folder.php @@ -37,7 +37,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getDeletedAt() + public function getDeletedAt(): ?int { return $this->deletedAt; } @@ -50,7 +50,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLastModified() + public function getLastModified(): ?string { return $this->lastModified; } @@ -68,7 +68,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getParentId() + public function getParentId(): ?int { return $this->parentId; } @@ -95,7 +95,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable ); } - public function setDeletedAt(int $deletedAt = null) + public function setDeletedAt(?int $deletedAt = null): void { if ($this->deletedAt !== $deletedAt) { $this->deletedAt = $deletedAt; @@ -103,7 +103,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setId(int $id) + public function setId(int $id): void { if ($this->id !== $id) { $this->id = $id; @@ -111,7 +111,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setLastModified(string $lastModified = null) + public function setLastModified(?string $lastModified = null): void { if ($this->lastModified !== $lastModified) { @@ -120,7 +120,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setName(string $name) + public function setName(string $name): void { if ($this->name !== $name) { $this->name = $name; @@ -128,7 +128,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setOpened(bool $opened) + public function setOpened(bool $opened): void { if ($this->opened !== $opened) { $this->opened = $opened; @@ -136,7 +136,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setParentId(int $parentId = 0) + public function setParentId(int $parentId = 0): void { if ($this->parentId !== $parentId) { $this->parentId = $parentId; @@ -144,7 +144,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setUserId(string $userId) + public function setUserId(string $userId): void { if ($this->userId !== $userId) { $this->userId = $userId; diff --git a/lib/Db/FolderMapperV2.php b/lib/Db/FolderMapperV2.php index d684e5af2..7d0536607 100644 --- a/lib/Db/FolderMapperV2.php +++ b/lib/Db/FolderMapperV2.php @@ -44,7 +44,7 @@ class FolderMapperV2 extends NewsMapperV2 * * @return Entity[] */ - public function findAllFromUser($userId): array + public function findAllFromUser(string $userId, array $params = []): array { $builder = $this->db->getQueryBuilder(); $builder->select('*') diff --git a/lib/Db/Item.php b/lib/Db/Item.php index 7d3924597..322d12fed 100644 --- a/lib/Db/Item.php +++ b/lib/Db/Item.php @@ -103,7 +103,7 @@ class Item extends Entity implements IAPI, \JsonSerializable return $item; } - public function generateSearchIndex() + public function generateSearchIndex(): void { $this->setSearchIndex( mb_strtolower( @@ -121,7 +121,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getAuthor() + public function getAuthor(): ?string { return $this->author; } @@ -129,7 +129,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getBody() + public function getBody(): ?string { return $this->body; } @@ -137,7 +137,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getContentHash() + public function getContentHash(): ?string { return $this->contentHash; } @@ -145,7 +145,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getEnclosureLink() + public function getEnclosureLink(): ?string { return $this->enclosureLink; } @@ -153,7 +153,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getMediaThumbnail() + public function getMediaThumbnail(): ?string { return $this->mediaThumbnail; } @@ -161,7 +161,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getMediaDescription() + public function getMediaDescription(): ?string { return $this->mediaDescription; } @@ -169,12 +169,12 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getEnclosureMime() + public function getEnclosureMime(): ?string { return $this->enclosureMime; } - public function getFeedId() + public function getFeedId(): string { return $this->feedId; } @@ -182,7 +182,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getFingerprint() + public function getFingerprint(): ?string { return $this->fingerprint; } @@ -197,12 +197,12 @@ class Item extends Entity implements IAPI, \JsonSerializable return $this->guidHash; } - public function getId() + public function getId(): string { return $this->id; } - public function getIntro() + public function getIntro(): string { return strip_tags($this->getBody()); } @@ -210,7 +210,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLastModified() + public function getLastModified(): ?string { return $this->lastModified; } @@ -218,7 +218,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getPubDate() + public function getPubDate(): ?int { return $this->pubDate; } @@ -231,7 +231,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getSearchIndex() + public function getSearchIndex(): ?string { return $this->searchIndex; } @@ -239,7 +239,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getTitle() + public function getTitle(): ?string { return $this->title; } @@ -247,7 +247,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getUpdatedDate() + public function getUpdatedDate(): ?int { return $this->updatedDate; } @@ -255,17 +255,17 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getUrl() + public function getUrl(): ?string { return $this->url; } - public function isStarred() + public function isStarred(): bool { return $this->starred; } - public function isUnread() + public function isUnread(): bool { return $this->unread; } @@ -299,7 +299,7 @@ class Item extends Entity implements IAPI, \JsonSerializable ]; } - public function setAuthor(string $author = null) + public function setAuthor(string $author = null): void { $author = strip_tags($author); @@ -309,7 +309,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setBody(string $body = null) + public function setBody(string $body = null): void { // FIXME: this should not happen if the target="_blank" is already // on the link @@ -321,7 +321,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setContentHash(string $contentHash = null) + public function setContentHash(string $contentHash = null): void { if ($this->contentHash !== $contentHash) { $this->contentHash = $contentHash; @@ -329,7 +329,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setEnclosureLink(string $enclosureLink = null) + public function setEnclosureLink(string $enclosureLink = null): void { if ($this->enclosureLink !== $enclosureLink) { $this->enclosureLink = $enclosureLink; @@ -337,7 +337,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setEnclosureMime(string $enclosureMime = null) + public function setEnclosureMime(string $enclosureMime = null): void { if ($this->enclosureMime !== $enclosureMime) { $this->enclosureMime = $enclosureMime; @@ -345,7 +345,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setMediaThumbnail(string $mediaThumbnail = null) + public function setMediaThumbnail(string $mediaThumbnail = null): void { if ($this->mediaThumbnail !== $mediaThumbnail) { $this->mediaThumbnail = $mediaThumbnail; @@ -353,7 +353,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setMediaDescription(string $mediaDescription = null) + public function setMediaDescription(string $mediaDescription = null): void { if ($this->mediaDescription !== $mediaDescription) { $this->mediaDescription = $mediaDescription; @@ -361,7 +361,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setFeedId(int $feedId) + public function setFeedId(int $feedId): void { if ($this->feedId !== $feedId) { $this->feedId = $feedId; @@ -369,7 +369,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setFingerprint(string $fingerprint = null) + public function setFingerprint(string $fingerprint = null): void { if ($this->fingerprint !== $fingerprint) { $this->fingerprint = $fingerprint; @@ -377,7 +377,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setGuid(string $guid) + public function setGuid(string $guid): void { if ($this->guid !== $guid) { $this->guid = $guid; @@ -385,7 +385,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setGuidHash(string $guidHash) + public function setGuidHash(string $guidHash): void { if ($this->guidHash !== $guidHash) { $this->guidHash = $guidHash; @@ -393,7 +393,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setId(int $id) + public function setId(int $id): void { if ($this->id !== $id) { $this->id = $id; @@ -401,7 +401,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setLastModified(string $lastModified = null) + public function setLastModified(string $lastModified = null): void { if ($this->lastModified !== $lastModified) { $this->lastModified = $lastModified; @@ -409,7 +409,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setPubDate(int $pubDate = null) + public function setPubDate(int $pubDate = null): void { if ($this->pubDate !== $pubDate) { $this->pubDate = $pubDate; @@ -417,7 +417,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setRtl(bool $rtl) + public function setRtl(bool $rtl): void { if ($this->rtl !== $rtl) { $this->rtl = $rtl; @@ -425,7 +425,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setSearchIndex(string $searchIndex = null) + public function setSearchIndex(string $searchIndex = null): void { if ($this->searchIndex !== $searchIndex) { $this->searchIndex = $searchIndex; @@ -433,7 +433,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setStarred(bool $starred) + public function setStarred(bool $starred): void { if ($this->starred !== $starred) { $this->starred = $starred; @@ -441,7 +441,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setTitle(string $title = null) + public function setTitle(string $title = null): void { $title = strip_tags($title); @@ -451,7 +451,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setUnread(bool $unread) + public function setUnread(bool $unread): void { if ($this->unread !== $unread) { $this->unread = $unread; @@ -459,7 +459,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setUpdatedDate(int $updatedDate = null) + public function setUpdatedDate(int $updatedDate = null): void { if ($this->updatedDate !== $updatedDate) { $this->updatedDate = $updatedDate; @@ -467,7 +467,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setUrl(string $url = null) + public function setUrl(string $url = null): void { $url = trim($url); if ((strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0) @@ -549,7 +549,7 @@ class Item extends Entity implements IAPI, \JsonSerializable * * @return boolean */ - public function isSupportedMime($mime) + public function isSupportedMime(string $mime): bool { return ( stripos($mime, 'audio/') !== false || diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php index ba840fda7..edb8ba55f 100644 --- a/lib/Db/ItemMapperV2.php +++ b/lib/Db/ItemMapperV2.php @@ -43,10 +43,11 @@ class ItemMapperV2 extends NewsMapperV2 * Find all feeds for a user. * * @param string $userId The user identifier + * @param array $params Filter parameters * * @return Entity[] */ - public function findAllFromUser($userId): array + public function findAllFromUser(string $userId, array $params = []): array { $builder = $this->db->getQueryBuilder(); $builder->select('items.*') @@ -56,6 +57,11 @@ class ItemMapperV2 extends NewsMapperV2 ->andWhere('deleted_at = 0') ->setParameter(':user_id', $userId, IQueryBuilder::PARAM_STR); + foreach ($params as $key => $value) { + $builder->andWhere("${key} = :${key}") + ->setParameter(":${key}", $value); + } + return $this->findEntities($builder); } @@ -110,7 +116,7 @@ class ItemMapperV2 extends NewsMapperV2 * * @param int $threshold Deletion threshold */ - public function deleteOverThreshold($threshold) + public function deleteOverThreshold(int $threshold) { $builder = $this->db->getQueryBuilder(); diff --git a/lib/Db/NewsMapperV2.php b/lib/Db/NewsMapperV2.php index be5695598..2896d9052 100644 --- a/lib/Db/NewsMapperV2.php +++ b/lib/Db/NewsMapperV2.php @@ -88,10 +88,11 @@ abstract class NewsMapperV2 extends QBMapper * Find all items for a user. * * @param string $userId ID of the user + * @param array $params Filter parameters * * @return Entity[] */ - abstract public function findAllFromUser(string $userId): array; + abstract public function findAllFromUser(string $userId, array $params = []): array; /** * Find item for a user. |