mirror of
https://github.com/wallabag/wallabag.git
synced 2024-10-31 22:28:54 +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;
|
||||
}
|
||||
} 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)));
|
||||
|
||||
|
@ -66,7 +66,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
|||
private function cleanDuplicates(User $user)
|
||||
{
|
||||
$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());
|
||||
|
||||
|
@ -109,7 +109,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
|
|||
*/
|
||||
private function getUser($username)
|
||||
{
|
||||
return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
|
||||
return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
|
||||
}
|
||||
|
||||
private function getDoctrine()
|
||||
|
|
|
@ -32,15 +32,14 @@ class ExportCommand extends ContainerAwareCommand
|
|||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
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) {
|
||||
$output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username')));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$entries = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
$entries = $this->get('wallabag_core.entry_repository')
|
||||
->getBuilderForAllByUser($user->getId())
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
|
|
@ -67,7 +67,7 @@ class ShowUserCommand extends ContainerAwareCommand
|
|||
*/
|
||||
private function getUser($username)
|
||||
{
|
||||
return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
|
||||
return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
|
||||
}
|
||||
|
||||
private function getDoctrine()
|
||||
|
|
|
@ -59,7 +59,7 @@ class TagAllCommand extends ContainerAwareCommand
|
|||
*/
|
||||
private function getUser($username)
|
||||
{
|
||||
return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
|
||||
return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
|
||||
}
|
||||
|
||||
private function getDoctrine()
|
||||
|
|
|
@ -152,8 +152,7 @@ class ConfigController extends Controller
|
|||
],
|
||||
'twofactor_auth' => $this->getParameter('twofactor_auth'),
|
||||
'wallabag_url' => $this->getParameter('domain_name'),
|
||||
'enabled_users' => $this->getDoctrine()
|
||||
->getRepository('WallabagUserBundle:User')
|
||||
'enabled_users' => $this->get('wallabag_user.user_repository')
|
||||
->getSumEnabledUsers(),
|
||||
]);
|
||||
}
|
||||
|
@ -257,9 +256,7 @@ class ConfigController extends Controller
|
|||
// manually remove tags to avoid orphan tag
|
||||
$this->removeAllTagsByUserId($this->getUser()->getId());
|
||||
|
||||
$this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->removeAllByUserId($this->getUser()->getId());
|
||||
$this->get('wallabag_core.entry_repository')->removeAllByUserId($this->getUser()->getId());
|
||||
break;
|
||||
case 'archived':
|
||||
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
|
||||
$this->removeTagsForArchivedByUserId($this->getUser()->getId());
|
||||
|
||||
$this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->removeArchivedByUserId($this->getUser()->getId());
|
||||
$this->get('wallabag_core.entry_repository')->removeArchivedByUserId($this->getUser()->getId());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -295,8 +290,7 @@ class ConfigController extends Controller
|
|||
return;
|
||||
}
|
||||
|
||||
$this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
$this->get('wallabag_core.entry_repository')
|
||||
->removeTags($userId, $tags);
|
||||
|
||||
// cleanup orphan tags
|
||||
|
@ -318,7 +312,7 @@ class ConfigController extends Controller
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -329,7 +323,7 @@ class ConfigController extends Controller
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -393,8 +387,7 @@ class ConfigController extends Controller
|
|||
*/
|
||||
public function deleteAccountAction(Request $request)
|
||||
{
|
||||
$enabledUsers = $this->getDoctrine()
|
||||
->getRepository('WallabagUserBundle:User')
|
||||
$enabledUsers = $this->get('wallabag_user.user_repository')
|
||||
->getSumEnabledUsers();
|
||||
|
||||
if ($enabledUsers <= 1) {
|
||||
|
|
|
@ -57,16 +57,17 @@ class ExportController extends Controller
|
|||
{
|
||||
$method = ucfirst($category);
|
||||
$methodBuilder = 'getBuilderFor'.$method.'ByUser';
|
||||
$epository = $this->get('wallabag_core.entry_repository');
|
||||
|
||||
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()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findAllByTagId($this->getUser()->getId(), $tag->getId());
|
||||
$entries = $epository->findAllByTagId(
|
||||
$this->getUser()->getId(),
|
||||
$tag->getId()
|
||||
);
|
||||
} else {
|
||||
$entries = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
$entries = $epository
|
||||
->$methodBuilder($this->getUser()->getId())
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
|
|
@ -66,7 +66,7 @@ class RssController extends Controller
|
|||
*/
|
||||
private function showEntries($type, User $user, $page = 1)
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
|
||||
$repository = $this->get('wallabag_core.entry_repository');
|
||||
|
||||
switch ($type) {
|
||||
case 'starred':
|
||||
|
|
|
@ -84,16 +84,17 @@ class TagController extends Controller
|
|||
*/
|
||||
public function showTagAction()
|
||||
{
|
||||
$tags = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Tag')
|
||||
$repository = $this->get('wallabag_core.entry_repository');
|
||||
$tags = $this->get('wallabag_core.tag_repository')
|
||||
->findAllTags($this->getUser()->getId());
|
||||
|
||||
$flatTags = [];
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$nbEntries = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId());
|
||||
$nbEntries = $repository->countAllEntriesByUserIdAndTagId(
|
||||
$this->getUser()->getId(),
|
||||
$tag->getId()
|
||||
);
|
||||
|
||||
$flatTags[] = [
|
||||
'id' => $tag->getId(),
|
||||
|
@ -119,9 +120,10 @@ class TagController extends Controller
|
|||
*/
|
||||
public function showEntriesForTagAction(Tag $tag, $page, Request $request)
|
||||
{
|
||||
$entriesByTag = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findAllByTagId($this->getUser()->getId(), $tag->getId());
|
||||
$entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId(
|
||||
$this->getUser()->getId(),
|
||||
$tag->getId()
|
||||
);
|
||||
|
||||
$pagerAdapter = new ArrayAdapter($entriesByTag);
|
||||
|
||||
|
|
Loading…
Reference in a new issue