forked from wallabag/wallabag
Move User repository to Core
This commit is contained in:
@ -12,7 +12,7 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
class CleanDuplicatesCommand extends Command
|
||||
{
|
||||
|
||||
@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Wallabag\CoreBundle\Helper\EntriesExport;
|
||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
class ExportCommand extends Command
|
||||
{
|
||||
|
||||
@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Helper\UrlHasher;
|
||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
class GenerateUrlHashesCommand extends Command
|
||||
{
|
||||
|
||||
@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
class ListUserCommand extends Command
|
||||
{
|
||||
|
||||
@ -14,7 +14,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Wallabag\CoreBundle\Event\EntrySavedEvent;
|
||||
use Wallabag\CoreBundle\Helper\ContentProxy;
|
||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
class ReloadEntryCommand extends Command
|
||||
{
|
||||
|
||||
@ -9,7 +9,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
class ShowUserCommand extends Command
|
||||
{
|
||||
|
||||
@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Helper\RuleBasedTagger;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
class TagAllCommand extends Command
|
||||
{
|
||||
|
||||
@ -39,8 +39,8 @@ use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\CoreBundle\Repository\IgnoreOriginUserRuleRepository;
|
||||
use Wallabag\CoreBundle\Repository\TaggingRuleRepository;
|
||||
use Wallabag\CoreBundle\Repository\TagRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Tools\Utils;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
|
||||
class ConfigController extends AbstractController
|
||||
{
|
||||
|
||||
@ -18,10 +18,10 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
use Wallabag\UserBundle\Form\NewUserType;
|
||||
use Wallabag\UserBundle\Form\SearchUserType;
|
||||
use Wallabag\UserBundle\Form\UserType;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
|
||||
/**
|
||||
* User controller.
|
||||
|
||||
@ -21,7 +21,7 @@ use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
|
||||
* User.
|
||||
*
|
||||
* @XmlRoot("user")
|
||||
* @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository")
|
||||
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
|
||||
* @ORM\Table(name="`user`")
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
*
|
||||
|
||||
@ -8,7 +8,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInte
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
use Wallabag\UserBundle\Repository\UserRepository;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
/**
|
||||
* ParamConverter used in the Feed controller to retrieve the right user according to
|
||||
|
||||
92
src/Wallabag/CoreBundle/Repository/UserRepository.php
Normal file
92
src/Wallabag/CoreBundle/Repository/UserRepository.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Repository;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* @method User|null findOneById(int $id)
|
||||
*/
|
||||
class UserRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a user by its username and Feed token.
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $feedToken
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function findOneByUsernameAndFeedtoken($username, $feedToken)
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->leftJoin('u.config', 'c')
|
||||
->where('c.feedToken = :feed_token')->setParameter('feed_token', $feedToken)
|
||||
->andWhere('u.username = :username')->setParameter('username', $username)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a user by its username.
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function findOneByUserName($username)
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->andWhere('u.username = :username')->setParameter('username', $username)
|
||||
->getQuery()
|
||||
->getSingleResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many users are enabled.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSumEnabledUsers()
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->select('count(u)')
|
||||
->andWhere('u.enabled = true')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many users are existing.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSumUsers()
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->select('count(u)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves users filtered with a search term.
|
||||
*
|
||||
* @param string $term
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getQueryBuilderForSearch($term)
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%' . $term . '%');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user