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.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index abd35c02..8d391917 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -225,6 +225,80 @@ class ConfigController extends Controller
225 } 225 }
226 226
227 /** 227 /**
228 * Remove all annotations OR tags OR entries for the current user.
229 *
230 * @Route("/reset/{type}", requirements={"id" = "annotations|tags|entries"}, name="config_reset")
231 *
232 * @return RedirectResponse
233 */
234 public function resetAction($type)
235 {
236 $em = $this->getDoctrine()->getManager();
237
238 switch ($type) {
239 case 'annotations':
240 $this->getDoctrine()
241 ->getRepository('WallabagAnnotationBundle:Annotation')
242 ->removeAllByUserId($this->getUser()->getId());
243 break;
244
245 case 'tags':
246 $this->removeAllTagsByUserId($this->getUser()->getId());
247 break;
248
249 case 'entries':
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 }
255
256 // manually remove tags to avoid orphan tag
257 $this->removeAllTagsByUserId($this->getUser()->getId());
258
259 $this->getDoctrine()
260 ->getRepository('WallabagCoreBundle:Entry')
261 ->removeAllByUserId($this->getUser()->getId());
262 }
263
264 $this->get('session')->getFlashBag()->add(
265 'notice',
266 'flashes.config.notice.'.$type.'_reset'
267 );
268
269 return $this->redirect($this->generateUrl('config').'#set3');
270 }
271
272 /**
273 * Remove all tags for a given user and cleanup orphan tags.
274 *
275 * @param int $userId
276 */
277 private function removeAllTagsByUserId($userId)
278 {
279 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId);
280
281 if (empty($tags)) {
282 return;
283 }
284
285 $this->getDoctrine()
286 ->getRepository('WallabagCoreBundle:Entry')
287 ->removeTags($userId, $tags);
288
289 // cleanup orphan tags
290 $em = $this->getDoctrine()->getManager();
291
292 foreach ($tags as $tag) {
293 if (count($tag->getEntries()) === 0) {
294 $em->remove($tag);
295 }
296 }
297
298 $em->flush();
299 }
300
301 /**
228 * Validate that a rule can be edited/deleted by the current user. 302 * Validate that a rule can be edited/deleted by the current user.
229 * 303 *
230 * @param TaggingRule $rule 304 * @param TaggingRule $rule