]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/ConfigController.php
Merge pull request #2677 from wallabag/add-wallabag_user.de.yml
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ConfigController.php
index faa85d1686919b15bfb7d064e4cfc22889770389..68f30f6e65e07dd6cc040136b72e0bb32a303e9a 100644 (file)
@@ -39,6 +39,8 @@ class ConfigController extends Controller
             $em->persist($config);
             $em->flush();
 
+            $request->getSession()->set('_locale', $config->getLanguage());
+
             // switch active theme
             $activeTheme = $this->get('liip_theme.active_theme');
             $activeTheme->setName($config->getTheme());
@@ -149,6 +151,7 @@ class ConfigController extends Controller
                 'token' => $config->getRssToken(),
             ],
             'twofactor_auth' => $this->getParameter('twofactor_auth'),
+            'wallabag_url' => $this->get('craue_config')->get('wallabag_url'),
             'enabled_users' => $this->getDoctrine()
                 ->getRepository('WallabagUserBundle:User')
                 ->getSumEnabledUsers(),
@@ -233,8 +236,6 @@ class ConfigController extends Controller
      */
     public function resetAction($type)
     {
-        $em = $this->getDoctrine()->getManager();
-
         switch ($type) {
             case 'annotations':
                 $this->getDoctrine()
@@ -251,9 +252,11 @@ class ConfigController extends Controller
                 // otherwise they won't be removed ...
                 if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
                     $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId());
-                    $this->removeAllTagsByUserId($this->getUser()->getId());
                 }
 
+                // manually remove tags to avoid orphan tag
+                $this->removeAllTagsByUserId($this->getUser()->getId());
+
                 $this->getDoctrine()
                     ->getRepository('WallabagCoreBundle:Entry')
                     ->removeAllByUserId($this->getUser()->getId());
@@ -268,9 +271,9 @@ class ConfigController extends Controller
     }
 
     /**
-     * Remove all tags for a given user.
+     * Remove all tags for a given user and cleanup orphan tags.
      *
-     * @param  int $userId
+     * @param int $userId
      */
     private function removeAllTagsByUserId($userId)
     {
@@ -283,6 +286,17 @@ class ConfigController extends Controller
         $this->getDoctrine()
             ->getRepository('WallabagCoreBundle:Entry')
             ->removeTags($userId, $tags);
+
+        // cleanup orphan tags
+        $em = $this->getDoctrine()->getManager();
+
+        foreach ($tags as $tag) {
+            if (count($tag->getEntries()) === 0) {
+                $em->remove($tag);
+            }
+        }
+
+        $em->flush();
     }
 
     /**
@@ -349,4 +363,25 @@ class ConfigController extends Controller
 
         return $this->redirect($this->generateUrl('fos_user_security_login'));
     }
+
+    /**
+     * Switch view mode for current user.
+     *
+     * @Route("/config/view-mode", name="switch_view_mode")
+     *
+     * @param Request $request
+     *
+     * @return \Symfony\Component\HttpFoundation\RedirectResponse
+     */
+    public function changeViewModeAction(Request $request)
+    {
+        $user = $this->getUser();
+        $user->getConfig()->setListMode(!$user->getConfig()->getListMode());
+
+        $em = $this->getDoctrine()->getManager();
+        $em->persist($user);
+        $em->flush();
+
+        return $this->redirect($request->headers->get('referer'));
+    }
 }