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.php76
1 files changed, 59 insertions, 17 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 907bf78e..d4170d39 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -151,9 +151,8 @@ class ConfigController extends Controller
151 'token' => $config->getRssToken(), 151 'token' => $config->getRssToken(),
152 ], 152 ],
153 'twofactor_auth' => $this->getParameter('twofactor_auth'), 153 'twofactor_auth' => $this->getParameter('twofactor_auth'),
154 'wallabag_url' => $this->get('craue_config')->get('wallabag_url'), 154 'wallabag_url' => $this->getParameter('domain_name'),
155 'enabled_users' => $this->getDoctrine() 155 'enabled_users' => $this->get('wallabag_user.user_repository')
156 ->getRepository('WallabagUserBundle:User')
157 ->getSumEnabledUsers(), 156 ->getSumEnabledUsers(),
158 ]); 157 ]);
159 } 158 }
@@ -248,18 +247,27 @@ class ConfigController extends Controller
248 break; 247 break;
249 248
250 case 'entries': 249 case 'entries':
251 // SQLite doesn't care about cascading remove, so we need to manually remove associated stuf 250 // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff
252 // otherwise they won't be removed ... 251 // otherwise they won't be removed ...
253 if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { 252 if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
254 $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); 253 $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId());
255 } 254 }
256 255
257 // manually remove tags to avoid orphan tag 256 // manually remove tags to avoid orphan tag
258 $this->removeAllTagsByUserId($this->getUser()->getId()); 257 $this->removeAllTagsByUserId($this->getUser()->getId());
259 258
260 $this->getDoctrine() 259 $this->get('wallabag_core.entry_repository')->removeAllByUserId($this->getUser()->getId());
261 ->getRepository('WallabagCoreBundle:Entry') 260 break;
262 ->removeAllByUserId($this->getUser()->getId()); 261 case 'archived':
262 if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
263 $this->removeAnnotationsForArchivedByUserId($this->getUser()->getId());
264 }
265
266 // manually remove tags to avoid orphan tag
267 $this->removeTagsForArchivedByUserId($this->getUser()->getId());
268
269 $this->get('wallabag_core.entry_repository')->removeArchivedByUserId($this->getUser()->getId());
270 break;
263 } 271 }
264 272
265 $this->get('session')->getFlashBag()->add( 273 $this->get('session')->getFlashBag()->add(
@@ -271,20 +279,18 @@ class ConfigController extends Controller
271 } 279 }
272 280
273 /** 281 /**
274 * Remove all tags for a given user and cleanup orphan tags. 282 * Remove all tags for given tags and a given user and cleanup orphan tags.
275 * 283 *
276 * @param int $userId 284 * @param array $tags
285 * @param int $userId
277 */ 286 */
278 private function removeAllTagsByUserId($userId) 287 private function removeAllTagsByStatusAndUserId($tags, $userId)
279 { 288 {
280 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId);
281
282 if (empty($tags)) { 289 if (empty($tags)) {
283 return; 290 return;
284 } 291 }
285 292
286 $this->getDoctrine() 293 $this->get('wallabag_core.entry_repository')
287 ->getRepository('WallabagCoreBundle:Entry')
288 ->removeTags($userId, $tags); 294 ->removeTags($userId, $tags);
289 295
290 // cleanup orphan tags 296 // cleanup orphan tags
@@ -300,6 +306,43 @@ class ConfigController extends Controller
300 } 306 }
301 307
302 /** 308 /**
309 * Remove all tags for a given user and cleanup orphan tags.
310 *
311 * @param int $userId
312 */
313 private function removeAllTagsByUserId($userId)
314 {
315 $tags = $this->get('wallabag_core.tag_repository')->findAllTags($userId);
316 $this->removeAllTagsByStatusAndUserId($tags, $userId);
317 }
318
319 /**
320 * Remove all tags for a given user and cleanup orphan tags.
321 *
322 * @param int $userId
323 */
324 private function removeTagsForArchivedByUserId($userId)
325 {
326 $tags = $this->get('wallabag_core.tag_repository')->findForArchivedArticlesByUser($userId);
327 $this->removeAllTagsByStatusAndUserId($tags, $userId);
328 }
329
330 private function removeAnnotationsForArchivedByUserId($userId)
331 {
332 $em = $this->getDoctrine()->getManager();
333
334 $archivedEntriesAnnotations = $this->getDoctrine()
335 ->getRepository('WallabagAnnotationBundle:Annotation')
336 ->findAllArchivedEntriesByUser($userId);
337
338 foreach ($archivedEntriesAnnotations as $archivedEntriesAnnotation) {
339 $em->remove($archivedEntriesAnnotation);
340 }
341
342 $em->flush();
343 }
344
345 /**
303 * Validate that a rule can be edited/deleted by the current user. 346 * Validate that a rule can be edited/deleted by the current user.
304 * 347 *
305 * @param TaggingRule $rule 348 * @param TaggingRule $rule
@@ -344,8 +387,7 @@ class ConfigController extends Controller
344 */ 387 */
345 public function deleteAccountAction(Request $request) 388 public function deleteAccountAction(Request $request)
346 { 389 {
347 $enabledUsers = $this->getDoctrine() 390 $enabledUsers = $this->get('wallabag_user.user_repository')
348 ->getRepository('WallabagUserBundle:User')
349 ->getSumEnabledUsers(); 391 ->getSumEnabledUsers();
350 392
351 if ($enabledUsers <= 1) { 393 if ($enabledUsers <= 1) {