From 6da1aebc946e6448dd0d5080ee88e79c2bae4666 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 30 Mar 2017 16:24:59 +0200 Subject: Allow to remove all archived entries Since we still support fucking SQLite, we need to retrieve all tags & annotations for archived entries before deleting them. Signed-off-by: Thomas Citharel --- .../CoreBundle/Controller/ConfigController.php | 59 +++++++++++++++++++++- .../CoreBundle/Repository/EntryRepository.php | 8 +++ .../CoreBundle/Repository/TagRepository.php | 20 ++++++++ .../Resources/translations/messages.da.yml | 2 + .../Resources/translations/messages.de.yml | 2 + .../Resources/translations/messages.en.yml | 2 + .../Resources/translations/messages.es.yml | 2 + .../Resources/translations/messages.fa.yml | 2 + .../Resources/translations/messages.fr.yml | 2 + .../Resources/translations/messages.it.yml | 2 + .../Resources/translations/messages.oc.yml | 2 + .../Resources/translations/messages.pl.yml | 2 + .../Resources/translations/messages.pt.yml | 2 + .../Resources/translations/messages.ro.yml | 2 + .../Resources/translations/messages.tr.yml | 2 + .../views/themes/material/Config/index.html.twig | 3 ++ 16 files changed, 113 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 907bf78e..7dbe3f18 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -248,7 +248,7 @@ class ConfigController extends Controller break; case 'entries': - // SQLite doesn't care about cascading remove, so we need to manually remove associated stuf + // 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()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); @@ -260,6 +260,19 @@ class ConfigController extends Controller $this->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') ->removeAllByUserId($this->getUser()->getId()); + break; + case 'archived': + if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { + $this->removeAnnotationsForArchivedByUserId($this->getUser()->getId()); + } + + // manually remove tags to avoid orphan tag + $this->removeTagsForArchivedByUserId($this->getUser()->getId()); + + $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->removeArchivedByUserId($this->getUser()->getId()); + break; } $this->get('session')->getFlashBag()->add( @@ -299,6 +312,50 @@ class ConfigController extends Controller $em->flush(); } + /** + * Remove all tags for a given user and cleanup orphan tags. + * + * @param int $userId + */ + private function removeTagsForArchivedByUserId($userId) + { + $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId); + + if (empty($tags)) { + return; + } + + $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->removeTags($userId, $tags); + + // cleanup orphan tags + $em = $this->getDoctrine()->getManager(); + + foreach ($tags as $tag) { + if (count($tag->getEntries()) === 0) { + $em->remove($tag); + } + } + + $em->flush(); + } + + private function removeAnnotationsForArchivedByUserId($userId) + { + $em = $this->getDoctrine()->getManager(); + + $archivedEntriesAnnotations = $this->getDoctrine() + ->getRepository('WallabagAnnotationBundle:Annotation') + ->findAllByArchivedEntriesAndUserId($userId); + + foreach ($archivedEntriesAnnotations as $archivedEntriesAnnotation) { + $em->remove($archivedEntriesAnnotation); + } + + $em->flush(); + } + /** * Validate that a rule can be edited/deleted by the current user. * diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 9325d261..1f22e901 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -371,4 +371,12 @@ class EntryRepository extends EntityRepository ->setParameter('userId', $userId) ->execute(); } + + public function removeArchivedByUserId($userId) + { + $this->getEntityManager() + ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId AND e.isArchived = TRUE') + ->setParameter('userId', $userId) + ->execute(); + } } diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 2182df25..b78e244e 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -76,4 +76,24 @@ class TagRepository extends EntityRepository ->getQuery() ->getSingleResult(); } + + public function findTagsForArchivedArticles($userId) + { + $ids = $this->createQueryBuilder('t') + ->select('t.id') + ->leftJoin('t.entries', 'e') + ->where('e.user = :userId')->setParameter('userId', $userId) + ->andWhere('e.isArchived = true') + ->groupBy('t.id') + ->orderBy('t.slug') + ->getQuery() + ->getArrayResult(); + + $tags = []; + foreach ($ids as $id) { + $tags[] = $this->find($id); + } + + return $tags; + } } diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 5d9e85e4..dfac7a65 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -110,6 +110,7 @@ config: # annotations: Remove ALL annotations # tags: Remove ALL tags # entries: Remove ALL entries + # archived: Remove ALL archived entries # confirm: Are you really really sure? (THIS CAN'T BE UNDONE) form_password: # description: "You can change your password here. Your new password should by at least 8 characters long." @@ -528,6 +529,7 @@ flashes: # annotations_reset: Annotations reset # tags_reset: Tags reset # entries_reset: Entries reset + # archived_reset: Archived entries deleted entry: notice: # entry_already_saved: 'Entry already saved on %date%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index f1952a3e..0b9df325 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -110,6 +110,7 @@ config: annotations: Entferne ALLE Annotationen tags: Entferne ALLE Tags entries: Entferne ALLE Einträge + # archived: Remove ALL archived entries confirm: Bist du wirklich sicher? (DIES KANN NICHT RÜCKGÄNGIG GEMACHT WERDEN) form_password: description: "Hier kannst du dein Kennwort ändern. Dieses sollte mindestens acht Zeichen enthalten." @@ -528,6 +529,7 @@ flashes: annotations_reset: Anmerkungen zurücksetzen tags_reset: Tags zurücksetzen entries_reset: Einträge zurücksetzen + # archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'Eintrag bereits am %date% gespeichert' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 8e7e3c2c..2fa3192e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -110,6 +110,7 @@ config: annotations: Remove ALL annotations tags: Remove ALL tags entries: Remove ALL entries + archived: Remove ALL archived entries confirm: Are you really sure? (THIS CAN'T BE UNDONE) form_password: description: "You can change your password here. Your new password should by at least 8 characters long." @@ -528,6 +529,7 @@ flashes: annotations_reset: Annotations reset tags_reset: Tags reset entries_reset: Entries reset + archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'Entry already saved on %date%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 3d65c311..ce581d89 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -110,6 +110,7 @@ config: annotations: Eliminar TODAS las anotaciones tags: Eliminar TODAS las etiquetas entries: Eliminar TODOS los artículos + # archived: Remove ALL archived entries confirm: ¿Estás completamente seguro? (NO SE PUEDE DESHACER) form_password: description: "Puedes cambiar la contraseña aquí. Tu nueva contraseña debe tener al menos 8 caracteres." @@ -528,6 +529,7 @@ flashes: annotations_reset: Anotaciones reiniciadas tags_reset: Etiquetas reiniciadas entries_reset: Artículos reiniciados + # archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'Artículo ya guardado el %fecha%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 80500d19..3e3ee12c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -110,6 +110,7 @@ config: # annotations: Remove ALL annotations # tags: Remove ALL tags # entries: Remove ALL entries + # archived: Remove ALL archived entries # confirm: Are you really really sure? (THIS CAN'T BE UNDONE) form_password: # description: "You can change your password here. Your new password should by at least 8 characters long." @@ -528,6 +529,7 @@ flashes: # annotations_reset: Annotations reset # tags_reset: Tags reset # entries_reset: Entries reset + # archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'این مقاله در تاریخ %date% ذخیره شده بود' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 4f49f777..074593a6 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -110,6 +110,7 @@ config: annotations: Supprimer TOUTES les annotations tags: Supprimer TOUS les tags entries: Supprimer TOUS les articles + archived: Supprimer TOUS les articles archivés confirm: Êtes-vous vraiment vraiment sûr ? (C'EST IRRÉVERSIBLE) form_password: description: "Vous pouvez changer ici votre mot de passe. Le mot de passe doit contenir au moins 8 caractères." @@ -528,6 +529,7 @@ flashes: annotations_reset: Annotations supprimées tags_reset: Tags supprimés entries_reset: Articles supprimés + archived_reset: Articles archivés supprimés entry: notice: entry_already_saved: "Article déjà sauvegardé le %date%" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 992ff71c..0d86756a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -110,6 +110,7 @@ config: # annotations: Remove ALL annotations # tags: Remove ALL tags # entries: Remove ALL entries + # archived: Remove ALL archived entries # confirm: Are you really really sure? (THIS CAN'T BE UNDONE) form_password: # description: "You can change your password here. Your new password should by at least 8 characters long." @@ -528,6 +529,7 @@ flashes: # annotations_reset: Annotations reset # tags_reset: Tags reset # entries_reset: Entries reset + # archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'Contenuto già salvato in data %date%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index f6488565..d2949c50 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -110,6 +110,7 @@ config: annotations: Levar TOTAS las anotacions tags: Levar TOTAS las etiquetas entries: Levar TOTES los articles + # archived: Remove ALL archived entries confirm: Sètz vertadièrament segur ? (ES IRREVERSIBLE) form_password: description: "Podètz cambiar vòstre senhal aquí. Vòstre senhal deu èsser long d'almens 8 caractèrs." @@ -528,6 +529,7 @@ flashes: annotations_reset: Anotacions levadas tags_reset: Etiquetas levadas entries_reset: Articles levats + # archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'Article ja salvargardat lo %date%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index eda9bbbf..1f512942 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -110,6 +110,7 @@ config: annotations: Usuń WSZYSTKIE adnotacje tags: Usuń WSZYSTKIE tagi entries: usuń WSZYTSTKIE wpisy + # archived: Remove ALL archived entries confirm: Jesteś pewien? (tej operacji NIE MOŻNA cofnąć) form_password: description: "Tutaj możesz zmienić swoje hasło. Twoje nowe hasło powinno mieć conajmniej 8 znaków." @@ -528,6 +529,7 @@ flashes: annotations_reset: Zresetuj adnotacje tags_reset: Zresetuj tagi entries_reset: Zresetuj wpisy + # archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'Wpis już został dodany %date%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index 8a7cc6f8..2e815230 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -110,6 +110,7 @@ config: # annotations: Remove ALL annotations # tags: Remove ALL tags # entries: Remove ALL entries + # archived: Remove ALL archived entries # confirm: Are you really really sure? (THIS CAN'T BE UNDONE) form_password: # description: "You can change your password here. Your new password should by at least 8 characters long." @@ -528,6 +529,7 @@ flashes: # annotations_reset: Annotations reset # tags_reset: Tags reset # entries_reset: Entries reset + # archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'Entrada já foi salva em %date%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 52b6414f..16401efd 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -110,6 +110,7 @@ config: # annotations: Remove ALL annotations # tags: Remove ALL tags # entries: Remove ALL entries + # archived: Remove ALL archived entries # confirm: Are you really really sure? (THIS CAN'T BE UNDONE) form_password: # description: "You can change your password here. Your new password should by at least 8 characters long." @@ -528,6 +529,7 @@ flashes: # annotations_reset: Annotations reset # tags_reset: Tags reset # entries_reset: Entries reset + # archived_reset: Archived entries deleted entry: notice: # entry_already_saved: 'Entry already saved on %date%' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index bfb7e206..a4bf7dfe 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -110,6 +110,7 @@ config: # annotations: Remove ALL annotations # tags: Remove ALL tags # entries: Remove ALL entries + # archived: Remove ALL archived entries # confirm: Are you really really sure? (THIS CAN'T BE UNDONE) form_password: # description: "You can change your password here. Your new password should by at least 8 characters long." @@ -528,6 +529,7 @@ flashes: # annotations_reset: Annotations reset # tags_reset: Tags reset # entries_reset: Entries reset + # archived_reset: Archived entries deleted entry: notice: entry_already_saved: 'Entry already saved on %date%' diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 5d411fdd..708ff951 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -229,6 +229,9 @@ {{ 'config.reset.tags'|trans }} + + {{ 'config.reset.archived'|trans }} + {{ 'config.reset.entries'|trans }} -- cgit v1.2.3 From 9102851f59d960869b210bb26ab0e9c266781c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 Mar 2017 10:53:23 +0200 Subject: Added delete button on Baggy theme --- .../CoreBundle/Resources/views/themes/baggy/Config/index.html.twig | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/Wallabag/CoreBundle') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig index 3548f590..01f63a7b 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig @@ -199,6 +199,11 @@ {{ 'config.reset.tags'|trans }} +
  • + + {{ 'config.reset.archived'|trans }} + +
  • {{ 'config.reset.entries'|trans }} -- cgit v1.2.3 From e682a70f88338af66b8d47bfe078e32fd9c6520c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 Mar 2017 11:04:18 +0200 Subject: Refactored code --- .../CoreBundle/Controller/ConfigController.php | 40 +++++++++------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/Wallabag/CoreBundle') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 7dbe3f18..b2814ade 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -284,14 +284,13 @@ class ConfigController extends Controller } /** - * Remove all tags for a given user and cleanup orphan tags. + * Remove all tags for given tags and a given user and cleanup orphan tags. * - * @param int $userId + * @param array $tags + * @param int $userId */ - private function removeAllTagsByUserId($userId) + private function removeAllTagsByStatusAndUserId($tags, $userId) { - $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); - if (empty($tags)) { return; } @@ -312,6 +311,17 @@ class ConfigController extends Controller $em->flush(); } + /** + * Remove all tags for a given user and cleanup orphan tags. + * + * @param int $userId + */ + private function removeAllTagsByUserId($userId) + { + $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); + $this->removeAllTagsByStatusAndUserId($tags, $userId); + } + /** * Remove all tags for a given user and cleanup orphan tags. * @@ -320,25 +330,7 @@ class ConfigController extends Controller private function removeTagsForArchivedByUserId($userId) { $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId); - - if (empty($tags)) { - return; - } - - $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->removeTags($userId, $tags); - - // cleanup orphan tags - $em = $this->getDoctrine()->getManager(); - - foreach ($tags as $tag) { - if (count($tag->getEntries()) === 0) { - $em->remove($tag); - } - } - - $em->flush(); + $this->removeAllTagsByStatusAndUserId($tags, $userId); } private function removeAnnotationsForArchivedByUserId($userId) -- cgit v1.2.3 From 13a592a1288d7deb49211838368583c0109a5fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 Mar 2017 17:03:08 +0200 Subject: Renamed methods --- src/Wallabag/CoreBundle/Controller/ConfigController.php | 4 ++-- src/Wallabag/CoreBundle/Repository/TagRepository.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index b2814ade..1a80cc1a 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -329,7 +329,7 @@ class ConfigController extends Controller */ private function removeTagsForArchivedByUserId($userId) { - $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId); + $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findForArchivedArticlesByUser($userId); $this->removeAllTagsByStatusAndUserId($tags, $userId); } @@ -339,7 +339,7 @@ class ConfigController extends Controller $archivedEntriesAnnotations = $this->getDoctrine() ->getRepository('WallabagAnnotationBundle:Annotation') - ->findAllByArchivedEntriesAndUserId($userId); + ->findAllArchivedEntriesByUser($userId); foreach ($archivedEntriesAnnotations as $archivedEntriesAnnotation) { $em->remove($archivedEntriesAnnotation); diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index b78e244e..6c63a6a2 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -77,7 +77,7 @@ class TagRepository extends EntityRepository ->getSingleResult(); } - public function findTagsForArchivedArticles($userId) + public function findForArchivedArticlesByUser($userId) { $ids = $this->createQueryBuilder('t') ->select('t.id') -- cgit v1.2.3