1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

Migrate getRepository with entities

This commit is contained in:
Yassine Guedidi 2022-08-25 21:37:10 +02:00
parent 50a941d8b4
commit 8b7b4975d6
38 changed files with 226 additions and 202 deletions

View file

@ -24,7 +24,7 @@ class WallabagAnnotationController extends AbstractFOSRestController
{
$annotationRows = $this
->getDoctrine()
->getRepository('WallabagAnnotationBundle:Annotation')
->getRepository(Annotation::class)
->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId());
$total = \count($annotationRows);
$annotations = ['total' => $total, 'rows' => $annotationRows];

View file

@ -19,7 +19,7 @@ class DeveloperController extends Controller
*/
public function indexAction()
{
$clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findByUser($this->getUser()->getId());
$clients = $this->getDoctrine()->getRepository(Client::class)->findByUser($this->getUser()->getId());
return $this->render('@WallabagCore/themes/common/Developer/index.html.twig', [
'clients' => $clients,

View file

@ -44,7 +44,7 @@ class EntryRestController extends WallabagRestController
public function getEntriesExistsAction(Request $request)
{
$this->validateAuthentication();
$repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
$repo = $this->getDoctrine()->getRepository(Entry::class);
$returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id');
@ -753,7 +753,7 @@ class EntryRestController extends WallabagRestController
$label = trim($label);
$tag = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Tag')
->getRepository(Tag::class)
->findOneByLabel($label);
if (false !== $tag) {

View file

@ -22,7 +22,7 @@ class TagRestController extends WallabagRestController
$this->validateAuthentication();
$tags = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Tag')
->getRepository(Tag::class)
->findAllTags($this->getUser()->getId());
$json = $this->get('jms_serializer')->serialize($tags, 'json');
@ -46,7 +46,7 @@ class TagRestController extends WallabagRestController
$this->validateAuthentication();
$label = $request->get('tag', '');
$tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findByLabelsAndUser([$label], $this->getUser()->getId());
$tags = $this->getDoctrine()->getRepository(Tag::class)->findByLabelsAndUser([$label], $this->getUser()->getId());
if (empty($tags)) {
throw $this->createNotFoundException('Tag not found');
@ -55,7 +55,7 @@ class TagRestController extends WallabagRestController
$tag = $tags[0];
$this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->removeTag($this->getUser()->getId(), $tag);
$this->cleanOrphanTag($tag);
@ -82,14 +82,14 @@ class TagRestController extends WallabagRestController
$tagsLabels = $request->get('tags', '');
$tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findByLabelsAndUser(explode(',', $tagsLabels), $this->getUser()->getId());
$tags = $this->getDoctrine()->getRepository(Tag::class)->findByLabelsAndUser(explode(',', $tagsLabels), $this->getUser()->getId());
if (empty($tags)) {
throw $this->createNotFoundException('Tags not found');
}
$this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->removeTags($this->getUser()->getId(), $tags);
$this->cleanOrphanTag($tags);
@ -114,14 +114,14 @@ class TagRestController extends WallabagRestController
{
$this->validateAuthentication();
$tagFromDb = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findByLabelsAndUser([$tag->getLabel()], $this->getUser()->getId());
$tagFromDb = $this->getDoctrine()->getRepository(Tag::class)->findByLabelsAndUser([$tag->getLabel()], $this->getUser()->getId());
if (empty($tagFromDb)) {
throw $this->createNotFoundException('Tag not found');
}
$this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->removeTag($this->getUser()->getId(), $tag);
$this->cleanOrphanTag($tag);

View file

@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Helper\UrlHasher;
use Wallabag\UserBundle\Entity\User;
@ -40,7 +41,7 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
return 1;
}
} else {
$users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll();
$users = $this->getDoctrine()->getRepository(User::class)->findAll();
$output->writeln(sprintf('Generating hashed urls for "%d" users', \count($users)));
@ -57,7 +58,7 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
private function generateHashedUrls(User $user)
{
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
$repo = $this->getDoctrine()->getRepository(Entry::class);
$entries = $repo->findByEmptyHashedUrlAndUserId($user->getId());
@ -86,7 +87,7 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
*/
private function getUser($username)
{
return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
return $this->getDoctrine()->getRepository(User::class)->findOneByUserName($username);
}
private function getDoctrine()

View file

@ -13,6 +13,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint;
use Wallabag\AnnotationBundle\Entity\Annotation;
use Wallabag\CoreBundle\Entity\Config;
use Wallabag\CoreBundle\Entity\IgnoreOriginUserRule;
use Wallabag\CoreBundle\Entity\RuleInterface;
@ -132,7 +133,7 @@ class ConfigController extends Controller
if ($request->query->has('tagging-rule')) {
$taggingRule = $this->getDoctrine()
->getRepository('WallabagCoreBundle:TaggingRule')
->getRepository(TaggingRule::class)
->find($request->query->get('tagging-rule'));
if ($this->getUser()->getId() !== $taggingRule->getConfig()->getUser()->getId()) {
@ -195,7 +196,7 @@ class ConfigController extends Controller
if ($request->query->has('ignore-origin-user-rule')) {
$ignoreOriginUserRule = $this->getDoctrine()
->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
->getRepository(IgnoreOriginUserRule::class)
->find($request->query->get('ignore-origin-user-rule'));
if ($this->getUser()->getId() !== $ignoreOriginUserRule->getConfig()->getUser()->getId()) {
@ -548,7 +549,7 @@ class ConfigController extends Controller
switch ($type) {
case 'annotations':
$this->getDoctrine()
->getRepository('WallabagAnnotationBundle:Annotation')
->getRepository(Annotation::class)
->removeAllByUserId($this->getUser()->getId());
break;
case 'tags':
@ -558,7 +559,7 @@ class ConfigController extends Controller
// SQLite doesn't care about cascading remove, so we need to manually remove associated stuff
// otherwise they won't be removed ...
if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
$this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId());
$this->getDoctrine()->getRepository(Annotation::class)->removeAllByUserId($this->getUser()->getId());
}
// manually remove tags to avoid orphan tag
@ -735,7 +736,7 @@ class ConfigController extends Controller
$em = $this->getDoctrine()->getManager();
$archivedEntriesAnnotations = $this->getDoctrine()
->getRepository('WallabagAnnotationBundle:Annotation')
->getRepository(Annotation::class)
->findAllArchivedEntriesByUser($userId);
foreach ($archivedEntriesAnnotations as $archivedEntriesAnnotation) {
@ -764,7 +765,7 @@ class ConfigController extends Controller
private function getConfig()
{
$config = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Config')
->getRepository(Config::class)
->findOneByUser($this->getUser());
// should NEVER HAPPEN ...

View file

@ -17,6 +17,7 @@ use Wallabag\ImportBundle\Import\PinboardImport;
use Wallabag\ImportBundle\Import\ReadabilityImport;
use Wallabag\ImportBundle\Import\WallabagV1Import;
use Wallabag\ImportBundle\Import\WallabagV2Import;
use Wallabag\UserBundle\Entity\User;
class ImportCommand extends ContainerAwareCommand
{
@ -47,9 +48,9 @@ class ImportCommand extends ContainerAwareCommand
$em->getConnection()->getConfiguration()->setSQLLogger(null);
if ($input->getOption('useUserId')) {
$entityUser = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username'));
$entityUser = $em->getRepository(User::class)->findOneById($input->getArgument('username'));
} else {
$entityUser = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username'));
$entityUser = $em->getRepository(User::class)->findOneByUsername($input->getArgument('username'));
}
if (!\is_object($entityUser)) {

View file

@ -108,7 +108,7 @@ abstract class BrowserImport extends AbstractImport
$url = \array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
$existingEntry = $this->em
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId($url, $this->user->getId());
if (false !== $existingEntry) {

View file

@ -98,7 +98,7 @@ class DeliciousImport extends AbstractImport
public function parseEntry(array $importedEntry)
{
$existingEntry = $this->em
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
if (false !== $existingEntry) {

View file

@ -126,7 +126,7 @@ class InstapaperImport extends AbstractImport
public function parseEntry(array $importedEntry)
{
$existingEntry = $this->em
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
if (false !== $existingEntry) {

View file

@ -98,7 +98,7 @@ class PinboardImport extends AbstractImport
public function parseEntry(array $importedEntry)
{
$existingEntry = $this->em
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId($importedEntry['href'], $this->user->getId());
if (false !== $existingEntry) {

View file

@ -179,7 +179,7 @@ class PocketImport extends AbstractImport
$url = isset($importedEntry['resolved_url']) && '' !== $importedEntry['resolved_url'] ? $importedEntry['resolved_url'] : $importedEntry['given_url'];
$existingEntry = $this->em
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId($url, $this->user->getId());
if (false !== $existingEntry) {

View file

@ -98,7 +98,7 @@ class ReadabilityImport extends AbstractImport
public function parseEntry(array $importedEntry)
{
$existingEntry = $this->em
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId($importedEntry['article__url'], $this->user->getId());
if (false !== $existingEntry) {

View file

@ -104,7 +104,7 @@ abstract class WallabagImport extends AbstractImport
public function parseEntry(array $importedEntry)
{
$existingEntry = $this->em
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
if (false !== $existingEntry) {

View file

@ -139,7 +139,7 @@ class ManageController extends Controller
public function searchFormAction(Request $request, $page = 1)
{
$em = $this->getDoctrine()->getManager();
$qb = $em->getRepository('WallabagUserBundle:User')->createQueryBuilder('u');
$qb = $em->getRepository(User::class)->createQueryBuilder('u');
$form = $this->createForm(SearchUserType::class);
$form->handleRequest($request);
@ -147,7 +147,7 @@ class ManageController extends Controller
if ($form->isSubmitted() && $form->isValid()) {
$searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : '');
$qb = $em->getRepository('WallabagUserBundle:User')->getQueryBuilderForSearch($searchTerm);
$qb = $em->getRepository(User::class)->getQueryBuilderForSearch($searchTerm);
}
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);