aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2019-05-12 00:00:00 +0200
committerKevin Decherf <kevin@kdecherf.com>2019-05-18 18:11:08 +0200
commit2c290747cb0d235392f6e5d22205a706c6474168 (patch)
treefdf67f203aca096e8b61bd245b387d05cc38e20b /src/Wallabag/CoreBundle
parentde1162b91a205a98a3f8ed01bd80285793b18380 (diff)
downloadwallabag-2c290747cb0d235392f6e5d22205a706c6474168.tar.gz
wallabag-2c290747cb0d235392f6e5d22205a706c6474168.tar.zst
wallabag-2c290747cb0d235392f6e5d22205a706c6474168.zip
api/entries: add parameter detail to exclude or include content in response
detail=metadata will nullify the content field of entries in order to make smaller responses. detail=full keeps the former behavior, it sends the content of entries. It's the default, for backward compatibility. Fixes #2817 Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index f5089729..3990932e 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -139,15 +139,30 @@ class EntryRepository extends EntityRepository
139 * @param string $order 139 * @param string $order
140 * @param int $since 140 * @param int $since
141 * @param string $tags 141 * @param string $tags
142 * @param string $detail 'metadata' or 'full'. Include content field if 'full'
143 *
144 * @todo Breaking change: replace default detail=full by detail=metadata in a future version
142 * 145 *
143 * @return Pagerfanta 146 * @return Pagerfanta
144 */ 147 */
145 public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'asc', $since = 0, $tags = '') 148 public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'asc', $since = 0, $tags = '', $detail = 'full')
146 { 149 {
150 if (!\in_array(strtolower($detail), ['full', 'metadata'], true)) {
151 throw new \Exception('Detail "' . $detail . '" parameter is wrong, allowed: full or metadata');
152 }
153
147 $qb = $this->createQueryBuilder('e') 154 $qb = $this->createQueryBuilder('e')
148 ->leftJoin('e.tags', 't') 155 ->leftJoin('e.tags', 't')
149 ->where('e.user = :userId')->setParameter('userId', $userId); 156 ->where('e.user = :userId')->setParameter('userId', $userId);
150 157
158 if ('metadata' === $detail) {
159 $fieldNames = $this->getClassMetadata()->getFieldNames();
160 $fields = array_filter($fieldNames, function ($k) {
161 return 'content' !== $k;
162 });
163 $qb->select(sprintf('partial e.{%s}', implode(',', $fields)));
164 }
165
151 if (null !== $isArchived) { 166 if (null !== $isArchived) {
152 $qb->andWhere('e.isArchived = :isArchived')->setParameter('isArchived', (bool) $isArchived); 167 $qb->andWhere('e.isArchived = :isArchived')->setParameter('isArchived', (bool) $isArchived);
153 } 168 }