aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/ConfigController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php61
1 files changed, 55 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 907bf78e..1a80cc1a 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -248,7 +248,7 @@ class ConfigController extends Controller
248 break; 248 break;
249 249
250 case 'entries': 250 case 'entries':
251 // SQLite doesn't care about cascading remove, so we need to manually remove associated stuf 251 // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff
252 // otherwise they won't be removed ... 252 // otherwise they won't be removed ...
253 if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { 253 if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
254 $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); 254 $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId());
@@ -260,6 +260,19 @@ class ConfigController extends Controller
260 $this->getDoctrine() 260 $this->getDoctrine()
261 ->getRepository('WallabagCoreBundle:Entry') 261 ->getRepository('WallabagCoreBundle:Entry')
262 ->removeAllByUserId($this->getUser()->getId()); 262 ->removeAllByUserId($this->getUser()->getId());
263 break;
264 case 'archived':
265 if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
266 $this->removeAnnotationsForArchivedByUserId($this->getUser()->getId());
267 }
268
269 // manually remove tags to avoid orphan tag
270 $this->removeTagsForArchivedByUserId($this->getUser()->getId());
271
272 $this->getDoctrine()
273 ->getRepository('WallabagCoreBundle:Entry')
274 ->removeArchivedByUserId($this->getUser()->getId());
275 break;
263 } 276 }
264 277
265 $this->get('session')->getFlashBag()->add( 278 $this->get('session')->getFlashBag()->add(
@@ -271,14 +284,13 @@ class ConfigController extends Controller
271 } 284 }
272 285
273 /** 286 /**
274 * 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.
275 * 288 *
276 * @param int $userId 289 * @param array $tags
290 * @param int $userId
277 */ 291 */
278 private function removeAllTagsByUserId($userId) 292 private function removeAllTagsByStatusAndUserId($tags, $userId)
279 { 293 {
280 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId);
281
282 if (empty($tags)) { 294 if (empty($tags)) {
283 return; 295 return;
284 } 296 }
@@ -300,6 +312,43 @@ class ConfigController extends Controller
300 } 312 }
301 313
302 /** 314 /**
315 * Remove all tags for a given user and cleanup orphan tags.
316 *
317 * @param int $userId
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 */
330 private function removeTagsForArchivedByUserId($userId)
331 {
332 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findForArchivedArticlesByUser($userId);
333 $this->removeAllTagsByStatusAndUserId($tags, $userId);
334 }
335
336 private function removeAnnotationsForArchivedByUserId($userId)
337 {
338 $em = $this->getDoctrine()->getManager();
339
340 $archivedEntriesAnnotations = $this->getDoctrine()
341 ->getRepository('WallabagAnnotationBundle:Annotation')
342 ->findAllArchivedEntriesByUser($userId);
343
344 foreach ($archivedEntriesAnnotations as $archivedEntriesAnnotation) {
345 $em->remove($archivedEntriesAnnotation);
346 }
347
348 $em->flush();
349 }
350
351 /**
303 * Validate that a rule can be edited/deleted by the current user. 352 * Validate that a rule can be edited/deleted by the current user.
304 * 353 *
305 * @param TaggingRule $rule 354 * @param TaggingRule $rule