diff options
| author | 2023-09-04 10:09:37 +0200 | |
|---|---|---|
| committer | 2023-09-04 10:09:37 +0200 | |
| commit | 1c7c1016f4a5147003ed1c438b8a386a63a53cab (patch) | |
| tree | a0639042ac205cd20863cd24496e79ddae3f562e /app/Models | |
| parent | da405ceee628dca739a12b234a6094a8ebae9c94 (diff) | |
Fix JSON export/import (#5626)
* Fix import with empty content
fix https://github.com/FreshRSS/FreshRSS/issues/5622
Cherry picks on https://github.com/FreshRSS/FreshRSS/pull/5584
* Fix export of tags / labels
Article-defined tags were wrongly exported as user-defined labels.
* Fix export of tags / labels
Article-defined tags were wrongly exported as user-defined labels.
* Fix bug with many labels
* Better typing
* Comments
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/Entry.php | 9 | ||||
| -rw-r--r-- | app/Models/TagDAO.php | 13 |
2 files changed, 15 insertions, 7 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 7da27e409..b70e7e2ab 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -846,12 +846,12 @@ HTML; /** * N.B.: To avoid expensive lookups, ensure to set `$entry->_feed($feed)` before calling this function. - * N.B.: You might have to populate `$entry->_tags()` prior to calling this function. * @param string $mode Set to `'compat'` to use an alternative Unicode representation for problematic HTML special characters not decoded by some clients; * set to `'freshrss'` for using FreshRSS additions for internal use (e.g. export/import). + * @param array<string> $labels List of labels associated to this entry. * @return array<string,mixed> A representation of this entry in a format compatible with Google Reader API */ - public function toGReader(string $mode = ''): array { + public function toGReader(string $mode = '', array $labels = []): array { $feed = $this->feed(); $category = $feed == null ? null : $feed->category(); @@ -935,8 +935,11 @@ HTML; if ($this->isFavorite()) { $item['categories'][] = 'user/-/state/com.google/starred'; } + foreach ($labels as $labelName) { + $item['categories'][] = 'user/-/label/' . htmlspecialchars_decode($labelName, ENT_QUOTES); + } foreach ($this->tags() as $tagName) { - $item['categories'][] = 'user/-/label/' . htmlspecialchars_decode($tagName, ENT_QUOTES); + $item['categories'][] = htmlspecialchars_decode($tagName, ENT_QUOTES); } return $item; } diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index 0704fd9f7..80a0e7688 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -383,7 +383,11 @@ SQL; // Split a query with too many variables parameters $idsChunks = array_chunk($entries, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER); foreach ($idsChunks as $idsChunk) { - $values += $this->getTagsForEntries($idsChunk); + $valuesChunk = $this->getTagsForEntries($idsChunk); + if (!is_array($valuesChunk)) { + return false; + } + $values = array_merge($values, $valuesChunk); } return $values; } @@ -419,9 +423,10 @@ SQL; } /** - * For API - * @param array<FreshRSS_Entry|numeric-string> $entries - * @return array<string,array<string>> + * Produces an array: for each entry ID (prefixed by `e_`), associate a list of labels. + * Used by API and by JSON export, to speed up queries (would be very expensive to perform a label look-up on each entry individually). + * @param array<FreshRSS_Entry|numeric-string> $entries the list of entries for which to retrieve the labels. + * @return array<string,array<string>> An array of the shape `[e_id_entry => ["label 1", "label 2"]]` */ public function getEntryIdsTagNames(array $entries): array { $result = []; |
