mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-27 11:31:05 +00:00
User existing service instead of getDoctrine
This commit is contained in:
parent
80784b782b
commit
25203e5081
8 changed files with 32 additions and 37 deletions
|
@ -46,7 +46,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll();
|
$users = $this->get('wallabag_user.user_repository')->findAll();
|
||||||
|
|
||||||
$output->writeln(sprintf('Cleaning through %d user accounts', count($users)));
|
$output->writeln(sprintf('Cleaning through %d user accounts', count($users)));
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
||||||
private function cleanDuplicates(User $user)
|
private function cleanDuplicates(User $user)
|
||||||
{
|
{
|
||||||
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
|
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
|
||||||
$repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
|
$repo = $this->get('wallabag_core.entry_repository');
|
||||||
|
|
||||||
$entries = $repo->getAllEntriesIdAndUrl($user->getId());
|
$entries = $repo->getAllEntriesIdAndUrl($user->getId());
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function getUser($username)
|
private function getUser($username)
|
||||||
{
|
{
|
||||||
return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
|
return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDoctrine()
|
private function getDoctrine()
|
||||||
|
|
|
@ -32,15 +32,14 @@ class ExportCommand extends ContainerAwareCommand
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$user = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($input->getArgument('username'));
|
$user = $this->get('wallabag_user.user_repository')->findOneByUserName($input->getArgument('username'));
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
$output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username')));
|
$output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username')));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries = $this->getDoctrine()
|
$entries = $this->get('wallabag_core.entry_repository')
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
|
||||||
->getBuilderForAllByUser($user->getId())
|
->getBuilderForAllByUser($user->getId())
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
|
|
|
@ -67,7 +67,7 @@ class ShowUserCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function getUser($username)
|
private function getUser($username)
|
||||||
{
|
{
|
||||||
return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
|
return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDoctrine()
|
private function getDoctrine()
|
||||||
|
|
|
@ -59,7 +59,7 @@ class TagAllCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
private function getUser($username)
|
private function getUser($username)
|
||||||
{
|
{
|
||||||
return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
|
return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDoctrine()
|
private function getDoctrine()
|
||||||
|
|
|
@ -152,8 +152,7 @@ class ConfigController extends Controller
|
||||||
],
|
],
|
||||||
'twofactor_auth' => $this->getParameter('twofactor_auth'),
|
'twofactor_auth' => $this->getParameter('twofactor_auth'),
|
||||||
'wallabag_url' => $this->getParameter('domain_name'),
|
'wallabag_url' => $this->getParameter('domain_name'),
|
||||||
'enabled_users' => $this->getDoctrine()
|
'enabled_users' => $this->get('wallabag_user.user_repository')
|
||||||
->getRepository('WallabagUserBundle:User')
|
|
||||||
->getSumEnabledUsers(),
|
->getSumEnabledUsers(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -257,9 +256,7 @@ class ConfigController extends Controller
|
||||||
// manually remove tags to avoid orphan tag
|
// manually remove tags to avoid orphan tag
|
||||||
$this->removeAllTagsByUserId($this->getUser()->getId());
|
$this->removeAllTagsByUserId($this->getUser()->getId());
|
||||||
|
|
||||||
$this->getDoctrine()
|
$this->get('wallabag_core.entry_repository')->removeAllByUserId($this->getUser()->getId());
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
|
||||||
->removeAllByUserId($this->getUser()->getId());
|
|
||||||
break;
|
break;
|
||||||
case 'archived':
|
case 'archived':
|
||||||
if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
|
if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
|
||||||
|
@ -269,9 +266,7 @@ class ConfigController extends Controller
|
||||||
// manually remove tags to avoid orphan tag
|
// manually remove tags to avoid orphan tag
|
||||||
$this->removeTagsForArchivedByUserId($this->getUser()->getId());
|
$this->removeTagsForArchivedByUserId($this->getUser()->getId());
|
||||||
|
|
||||||
$this->getDoctrine()
|
$this->get('wallabag_core.entry_repository')->removeArchivedByUserId($this->getUser()->getId());
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
|
||||||
->removeArchivedByUserId($this->getUser()->getId());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,8 +290,7 @@ class ConfigController extends Controller
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getDoctrine()
|
$this->get('wallabag_core.entry_repository')
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
|
||||||
->removeTags($userId, $tags);
|
->removeTags($userId, $tags);
|
||||||
|
|
||||||
// cleanup orphan tags
|
// cleanup orphan tags
|
||||||
|
@ -318,7 +312,7 @@ class ConfigController extends Controller
|
||||||
*/
|
*/
|
||||||
private function removeAllTagsByUserId($userId)
|
private function removeAllTagsByUserId($userId)
|
||||||
{
|
{
|
||||||
$tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId);
|
$tags = $this->get('wallabag_core.tag_repository')->findAllTags($userId);
|
||||||
$this->removeAllTagsByStatusAndUserId($tags, $userId);
|
$this->removeAllTagsByStatusAndUserId($tags, $userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +323,7 @@ class ConfigController extends Controller
|
||||||
*/
|
*/
|
||||||
private function removeTagsForArchivedByUserId($userId)
|
private function removeTagsForArchivedByUserId($userId)
|
||||||
{
|
{
|
||||||
$tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findForArchivedArticlesByUser($userId);
|
$tags = $this->get('wallabag_core.tag_repository')->findForArchivedArticlesByUser($userId);
|
||||||
$this->removeAllTagsByStatusAndUserId($tags, $userId);
|
$this->removeAllTagsByStatusAndUserId($tags, $userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,8 +387,7 @@ class ConfigController extends Controller
|
||||||
*/
|
*/
|
||||||
public function deleteAccountAction(Request $request)
|
public function deleteAccountAction(Request $request)
|
||||||
{
|
{
|
||||||
$enabledUsers = $this->getDoctrine()
|
$enabledUsers = $this->get('wallabag_user.user_repository')
|
||||||
->getRepository('WallabagUserBundle:User')
|
|
||||||
->getSumEnabledUsers();
|
->getSumEnabledUsers();
|
||||||
|
|
||||||
if ($enabledUsers <= 1) {
|
if ($enabledUsers <= 1) {
|
||||||
|
|
|
@ -57,16 +57,17 @@ class ExportController extends Controller
|
||||||
{
|
{
|
||||||
$method = ucfirst($category);
|
$method = ucfirst($category);
|
||||||
$methodBuilder = 'getBuilderFor'.$method.'ByUser';
|
$methodBuilder = 'getBuilderFor'.$method.'ByUser';
|
||||||
|
$epository = $this->get('wallabag_core.entry_repository');
|
||||||
|
|
||||||
if ($category == 'tag_entries') {
|
if ($category == 'tag_entries') {
|
||||||
$tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneBySlug($request->query->get('tag'));
|
$tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag'));
|
||||||
|
|
||||||
$entries = $this->getDoctrine()
|
$entries = $epository->findAllByTagId(
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
$this->getUser()->getId(),
|
||||||
->findAllByTagId($this->getUser()->getId(), $tag->getId());
|
$tag->getId()
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$entries = $this->getDoctrine()
|
$entries = $epository
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
|
||||||
->$methodBuilder($this->getUser()->getId())
|
->$methodBuilder($this->getUser()->getId())
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
|
|
|
@ -66,7 +66,7 @@ class RssController extends Controller
|
||||||
*/
|
*/
|
||||||
private function showEntries($type, User $user, $page = 1)
|
private function showEntries($type, User $user, $page = 1)
|
||||||
{
|
{
|
||||||
$repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
|
$repository = $this->get('wallabag_core.entry_repository');
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'starred':
|
case 'starred':
|
||||||
|
|
|
@ -84,16 +84,17 @@ class TagController extends Controller
|
||||||
*/
|
*/
|
||||||
public function showTagAction()
|
public function showTagAction()
|
||||||
{
|
{
|
||||||
$tags = $this->getDoctrine()
|
$repository = $this->get('wallabag_core.entry_repository');
|
||||||
->getRepository('WallabagCoreBundle:Tag')
|
$tags = $this->get('wallabag_core.tag_repository')
|
||||||
->findAllTags($this->getUser()->getId());
|
->findAllTags($this->getUser()->getId());
|
||||||
|
|
||||||
$flatTags = [];
|
$flatTags = [];
|
||||||
|
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$nbEntries = $this->getDoctrine()
|
$nbEntries = $repository->countAllEntriesByUserIdAndTagId(
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
$this->getUser()->getId(),
|
||||||
->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId());
|
$tag->getId()
|
||||||
|
);
|
||||||
|
|
||||||
$flatTags[] = [
|
$flatTags[] = [
|
||||||
'id' => $tag->getId(),
|
'id' => $tag->getId(),
|
||||||
|
@ -119,9 +120,10 @@ class TagController extends Controller
|
||||||
*/
|
*/
|
||||||
public function showEntriesForTagAction(Tag $tag, $page, Request $request)
|
public function showEntriesForTagAction(Tag $tag, $page, Request $request)
|
||||||
{
|
{
|
||||||
$entriesByTag = $this->getDoctrine()
|
$entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId(
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
$this->getUser()->getId(),
|
||||||
->findAllByTagId($this->getUser()->getId(), $tag->getId());
|
$tag->getId()
|
||||||
|
);
|
||||||
|
|
||||||
$pagerAdapter = new ArrayAdapter($entriesByTag);
|
$pagerAdapter = new ArrayAdapter($entriesByTag);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue