diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index ccbf550a..faa85d16 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -237,25 +237,26 @@ class ConfigController extends Controller | |||
237 | 237 | ||
238 | switch ($type) { | 238 | switch ($type) { |
239 | case 'annotations': | 239 | case 'annotations': |
240 | $em->createQuery('DELETE FROM Wallabag\AnnotationBundle\Entity\Annotation a WHERE a.user = '.$this->getUser()->getId()) | 240 | $this->getDoctrine() |
241 | ->execute(); | 241 | ->getRepository('WallabagAnnotationBundle:Annotation') |
242 | ->removeAllByUserId($this->getUser()->getId()); | ||
242 | break; | 243 | break; |
243 | 244 | ||
244 | case 'tags': | 245 | case 'tags': |
245 | $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($this->getUser()->getId()); | 246 | $this->removeAllTagsByUserId($this->getUser()->getId()); |
247 | break; | ||
246 | 248 | ||
247 | if (empty($tags)) { | 249 | case 'entries': |
248 | break; | 250 | // SQLite doesn't care about cascading remove, so we need to manually remove associated stuf |
251 | // otherwise they won't be removed ... | ||
252 | if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { | ||
253 | $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); | ||
254 | $this->removeAllTagsByUserId($this->getUser()->getId()); | ||
249 | } | 255 | } |
250 | 256 | ||
251 | $this->getDoctrine() | 257 | $this->getDoctrine() |
252 | ->getRepository('WallabagCoreBundle:Entry') | 258 | ->getRepository('WallabagCoreBundle:Entry') |
253 | ->removeTags($this->getUser()->getId(), $tags); | 259 | ->removeAllByUserId($this->getUser()->getId()); |
254 | break; | ||
255 | |||
256 | case 'entries': | ||
257 | $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = '.$this->getUser()->getId()) | ||
258 | ->execute(); | ||
259 | } | 260 | } |
260 | 261 | ||
261 | $this->get('session')->getFlashBag()->add( | 262 | $this->get('session')->getFlashBag()->add( |
@@ -267,6 +268,24 @@ class ConfigController extends Controller | |||
267 | } | 268 | } |
268 | 269 | ||
269 | /** | 270 | /** |
271 | * Remove all tags for a given user. | ||
272 | * | ||
273 | * @param int $userId | ||
274 | */ | ||
275 | private function removeAllTagsByUserId($userId) | ||
276 | { | ||
277 | $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); | ||
278 | |||
279 | if (empty($tags)) { | ||
280 | return; | ||
281 | } | ||
282 | |||
283 | $this->getDoctrine() | ||
284 | ->getRepository('WallabagCoreBundle:Entry') | ||
285 | ->removeTags($userId, $tags); | ||
286 | } | ||
287 | |||
288 | /** | ||
270 | * Validate that a rule can be edited/deleted by the current user. | 289 | * Validate that a rule can be edited/deleted by the current user. |
271 | * | 290 | * |
272 | * @param TaggingRule $rule | 291 | * @param TaggingRule $rule |