aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2017-03-31 11:04:18 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2017-03-31 11:04:18 +0200
commite682a70f88338af66b8d47bfe078e32fd9c6520c (patch)
treea65a4d8ee32dc591e3815cc53d402ca7d81115f6 /src
parent9102851f59d960869b210bb26ab0e9c266781c4f (diff)
downloadwallabag-e682a70f88338af66b8d47bfe078e32fd9c6520c.tar.gz
wallabag-e682a70f88338af66b8d47bfe078e32fd9c6520c.tar.zst
wallabag-e682a70f88338af66b8d47bfe078e32fd9c6520c.zip
Refactored code
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 7dbe3f18..b2814ade 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -284,14 +284,13 @@ class ConfigController extends Controller
284 } 284 }
285 285
286 /** 286 /**
287 * Remove all tags for a given user and cleanup orphan tags. 287 * Remove all tags for given tags and a given user and cleanup orphan tags.
288 * 288 *
289 * @param int $userId 289 * @param array $tags
290 * @param int $userId
290 */ 291 */
291 private function removeAllTagsByUserId($userId) 292 private function removeAllTagsByStatusAndUserId($tags, $userId)
292 { 293 {
293 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId);
294
295 if (empty($tags)) { 294 if (empty($tags)) {
296 return; 295 return;
297 } 296 }
@@ -317,28 +316,21 @@ class ConfigController extends Controller
317 * 316 *
318 * @param int $userId 317 * @param int $userId
319 */ 318 */
319 private function removeAllTagsByUserId($userId)
320 {
321 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId);
322 $this->removeAllTagsByStatusAndUserId($tags, $userId);
323 }
324
325 /**
326 * Remove all tags for a given user and cleanup orphan tags.
327 *
328 * @param int $userId
329 */
320 private function removeTagsForArchivedByUserId($userId) 330 private function removeTagsForArchivedByUserId($userId)
321 { 331 {
322 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId); 332 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId);
323 333 $this->removeAllTagsByStatusAndUserId($tags, $userId);
324 if (empty($tags)) {
325 return;
326 }
327
328 $this->getDoctrine()
329 ->getRepository('WallabagCoreBundle:Entry')
330 ->removeTags($userId, $tags);
331
332 // cleanup orphan tags
333 $em = $this->getDoctrine()->getManager();
334
335 foreach ($tags as $tag) {
336 if (count($tag->getEntries()) === 0) {
337 $em->remove($tag);
338 }
339 }
340
341 $em->flush();
342 } 334 }
343 335
344 private function removeAnnotationsForArchivedByUserId($userId) 336 private function removeAnnotationsForArchivedByUserId($userId)