aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/ConfigController.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-01 14:01:13 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-22 13:13:07 +0200
commit191564b7f71d01fb4c597c9b9641e23db564278d (patch)
tree1cf81a2474d064f11663c70bd77121fc3c4c69a1 /src/Wallabag/CoreBundle/Controller/ConfigController.php
parent98efffc2a62820bad347a0f93840c48fa57f8cc3 (diff)
downloadwallabag-191564b7f71d01fb4c597c9b9641e23db564278d.tar.gz
wallabag-191564b7f71d01fb4c597c9b9641e23db564278d.tar.zst
wallabag-191564b7f71d01fb4c597c9b9641e23db564278d.zip
Add custom doctrine subscriber for SQLite
Since SQLite doesn’t handle cascade remove by default, we need to handle it manually. Also some refacto
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php41
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