$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());
'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(),
*/
public function resetAction($type)
{
- $em = $this->getDoctrine()->getManager();
-
switch ($type) {
case 'annotations':
$this->getDoctrine()
// 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());
}
/**
- * 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)
{
$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();
}
/**
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'));
+ }
}