From b0de88f75dead50385e80e3897dc3913a971b91e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 11 Oct 2016 21:45:43 +0200 Subject: [PATCH] Use statements & update translation --- app/config/parameters.yml.dist | 2 +- docs/en/user/parameters.rst | 1 + .../Repository/AnnotationRepository.php | 3 +- .../CoreBundle/Controller/TagController.php | 10 +++--- .../CoreBundle/Repository/EntryRepository.php | 3 +- .../CoreBundle/Repository/TagRepository.php | 33 +++++++------------ .../Resources/translations/messages.fr.yml | 10 +++--- 7 files changed, 28 insertions(+), 34 deletions(-) diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index a33ea37b..436eeeda 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -20,7 +20,7 @@ parameters: database_table_prefix: wallabag_ database_socket: null # with MySQL, use "utf8mb4" if got problem with content with emojis - database_charset: utf8 + database_charset: utf8mb4 mailer_transport: smtp mailer_host: 127.0.0.1 diff --git a/docs/en/user/parameters.rst b/docs/en/user/parameters.rst index 79c50871..c4345b74 100644 --- a/docs/en/user/parameters.rst +++ b/docs/en/user/parameters.rst @@ -12,6 +12,7 @@ What is the meaning of the parameters? "database_path", "``""%kernel.root_dir%/../data/db/wallabag.sqlite""``", "only for SQLite, define where to put the database file. Leave it for other database" "database_table_prefix", "wallabag_", "all wallabag's tables will be prefixed with that string. You can include a ``_`` for clarity" "database_socket", "null", "If your database is using a socket instead of tcp, put the path of the socket (other connection parameters will then be ignored" + "database_charset", "utf8mb4", "For PostgreSQL you should use utf8, for other use utf8mb4 which handle emoji" .. csv-table:: Configuration to send emails from wallabag :header: "name", "default", "description" diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index c81a2614..52989bcf 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -116,7 +116,8 @@ class AnnotationRepository extends EntityRepository public function removeAllByUserId($userId) { $this->getEntityManager() - ->createQuery('DELETE FROM Wallabag\AnnotationBundle\Entity\Annotation a WHERE a.user = '.$userId) + ->createQuery('DELETE FROM Wallabag\AnnotationBundle\Entity\Annotation a WHERE a.user = :userId') + ->setParameter('userId', $userId) ->execute(); } } diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 5acc6852..4542d484 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -90,15 +90,15 @@ class TagController extends Controller $flatTags = []; - foreach ($tags as $key => $tag) { + foreach ($tags as $tag) { $nbEntries = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') - ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag['id']); + ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId()); $flatTags[] = [ - 'id' => $tag['id'], - 'label' => $tag['label'], - 'slug' => $tag['slug'], + 'id' => $tag->getId(), + 'label' => $tag->getLabel(), + 'slug' => $tag->getSlug(), 'nbEntries' => $nbEntries, ]; } diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 5df5eff5..14616d88 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -339,7 +339,8 @@ class EntryRepository extends EntityRepository public function removeAllByUserId($userId) { $this->getEntityManager() - ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = '.$userId) + ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId') + ->setParameter('userId', $userId) ->execute(); } } diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 69661b12..81445989 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -34,6 +34,9 @@ class TagRepository extends EntityRepository /** * Find all tags per user. + * Instead of just left joined on the Entry table, we select only id and group by id to avoid tag multiplication in results. + * Once we have all tags id, we can safely request them one by one. + * This'll still be fastest than the previous query. * * @param int $userId * @@ -41,32 +44,20 @@ class TagRepository extends EntityRepository */ public function findAllTags($userId) { - return $this->createQueryBuilder('t') - ->select('t.slug', 't.label', 't.id') + $ids = $this->createQueryBuilder('t') + ->select('t.id') ->leftJoin('t.entries', 'e') ->where('e.user = :userId')->setParameter('userId', $userId) - ->groupBy('t.slug') - ->addGroupBy('t.label') - ->addGroupBy('t.id') + ->groupBy('t.id') ->getQuery() ->getArrayResult(); - } - /** - * Find all tags. - * - * @param int $userId - * - * @return array - */ - public function findAllTags($userId) - { - return $this->createQueryBuilder('t') - ->select('t') - ->leftJoin('t.entries', 'e') - ->where('e.user = :userId')->setParameter('userId', $userId) - ->getQuery() - ->getResult(); + $tags = []; + foreach ($ids as $id) { + $tags[] = $this->find($id); + } + + return $tags; } /** diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 7a98f133..14bdbbc7 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -91,15 +91,15 @@ config: delete: title: Supprimer mon compte (attention danger !) description: Si vous confirmez la suppression de votre compte, TOUS les articles, TOUS les tags, TOUTES les annotations et votre compte seront DÉFINITIVEMENT supprimé (c'est IRRÉVERSIBLE). Vous serez ensuite déconnecté. - confirm: Vous êtes vraiment sûr ? (C'EST IRREVERSIBLE) + confirm: Vous êtes vraiment sûr ? (C'EST IRRÉVERSIBLE) button: 'Supprimer mon compte' reset: title: Réinitialisation (attention danger !) - description: En cliquant sur les boutons ci-dessous vous avez la possibilité de supprimer certaines informations de votre compte. Attention, ces actions sont IRREVERSIBLES ! + description: En cliquant sur les boutons ci-dessous vous avez la possibilité de supprimer certaines informations de votre compte. Attention, ces actions sont IRRÉVERSIBLES ! annotations: Supprimer TOUTES les annotations tags: Supprimer TOUS les tags entries: Supprimer TOUS les articles - confirm: Êtes-vous vraiment vraiment sûr ? (C'EST IRREVERSIBLE) + confirm: Êtes-vous vraiment vraiment sûr ? (C'EST IRRÉVERSIBLE) form_password: old_password_label: 'Mot de passe actuel' new_password_label: 'Nouveau mot de passe' @@ -398,7 +398,7 @@ developer: field_grant_types: 'Type de privilège accordé' no_client: 'Aucun client pour le moment' remove: - warn_message_1: 'Vous avez la possibilité de supprimer le client %name%. Cette action est IRREVERSIBLE !' + warn_message_1: 'Vous avez la possibilité de supprimer le client %name%. Cette action est IRRÉVERSIBLE !' warn_message_2: "Si vous supprimez le client %name%, toutes les applications qui l'utilisaient ne fonctionneront plus avec votre compte wallabag." action: 'Supprimer le client %name%' client: @@ -474,7 +474,7 @@ flashes: entries_reset: Articles supprimés entry: notice: - entry_already_saved: 'Article déjà sauvergardé le %date%' + entry_already_saved: 'Article déjà sauvegardé le %date%' entry_saved: 'Article enregistré' entry_saved_failed: 'Article enregistré mais impossible de récupérer le contenu' entry_updated: 'Article mis à jour' -- 2.41.0