diff options
| author | 2022-08-08 12:04:02 +0200 | |
|---|---|---|
| committer | 2022-08-08 12:04:02 +0200 | |
| commit | 82ac1d1e676f93b1567eba608c00c6edaf401a9e (patch) | |
| tree | 1b3609df25f3eb1892aa7d359f52b82d680830a7 /app/Models/Feed.php | |
| parent | 240afa7d4dcf33de4575a1531e2db3c9f4400c1f (diff) | |
Refactor entry-to-GReader API format (#4490)
* Refactor entry to GReader API format
Some code was copied in two locations and not completely uniform.
Cleaning of related variables and functions (e.g. better types for entries and categories as objects vs. as IDs).
Usecase: I need to call the same GReader-compatible serialization from an extension
* Fixed some edge cases
* Keep summary instead of content
`summary` and `content` seems to be used interchangeably in the Google Reader API. We have been using `summary` for our client API and `content` in our export/import, so stick to that.
Diffstat (limited to 'app/Models/Feed.php')
| -rw-r--r-- | app/Models/Feed.php | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php index e39109b49..4de61167b 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -39,7 +39,9 @@ class FreshRSS_Feed extends Minz_Model { /** @var int */ private $kind = 0; /** @var int */ - private $category = 1; + private $categoryId = 1; + /** @var FreshRSS_Category|null */ + private $category; /** @var int */ private $nbEntries = -1; /** @var int */ @@ -119,9 +121,22 @@ class FreshRSS_Feed extends Minz_Model { public function hubUrl(): string { return $this->hubUrl; } - public function category(): int { + + /** + * @return FreshRSS_Category|null|false + */ + public function category() { + if ($this->category === null) { + $catDAO = FreshRSS_Factory::createCategoryDao(); + $this->category = $catDAO->searchById($this->categoryId); + } return $this->category; } + + public function categoryId(): int { + return $this->categoryId; + } + public function entries() { Minz_Log::warning(__method__ . ' is deprecated since FreshRSS 1.16.1!'); $simplePie = $this->load(false, true); @@ -253,10 +268,16 @@ class FreshRSS_Feed extends Minz_Model { $this->kind = $value; } - /** @param int $value */ - public function _category($value) { - $value = intval($value); - $this->category = $value >= 0 ? $value : 0; + /** @param FreshRSS_Category|null $cat */ + public function _category($cat) { + $this->category = $cat; + $this->categoryId = $this->category == null ? 0 : $this->category->id(); + } + + /** @param int|string $id */ + public function _categoryId($id) { + $this->category = null; + $this->categoryId = intval($id); } public function _name(string $value) { @@ -700,7 +721,7 @@ class FreshRSS_Feed extends Minz_Model { $archiving = $this->attributes('archiving'); if ($archiving == null) { $catDAO = FreshRSS_Factory::createCategoryDao(); - $category = $catDAO->searchById($this->category()); + $category = $catDAO->searchById($this->categoryId); $archiving = $category == null ? null : $category->attributes('archiving'); if ($archiving == null) { $archiving = FreshRSS_Context::$user_conf->archiving; |
