sender_email: %twofactor_sender%
digits: 6
template: WallabagUserBundle:Authentication:form.html.twig
+
+kphoen_rulerz:
+ executors:
+ doctrine: true
"scheb/two-factor-bundle": "~1.4",
"grandt/phpepub": "~4.0",
"wallabag/php-mobi": "~1.0.0",
- "kphoen/rulerz-bundle": "~0.7,>=0.7.2"
+ "kphoen/rulerz-bundle": "~0.7,>=0.7.3"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "~2.2.0",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "8719c5ec3c13338ff792ce5ed8d12926",
- "content-hash": "3f28af906ef3d4eaac41583bfcc5bd85",
+ "hash": "a1f0e0b886031d96a9756de581d7d557",
+ "content-hash": "d0a24cdd93bd431af386715f24e3e389",
"packages": [
{
"name": "doctrine/annotations",
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Command;
+
+use Doctrine\ORM\NoResultException;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class TagAllCommand extends ContainerAwareCommand
+{
+ protected function configure()
+ {
+ $this
+ ->setName('wallabag:tag:all')
+ ->setDescription('Tag all entries using the tagging rules.')
+ ->addArgument(
+ 'username',
+ InputArgument::REQUIRED,
+ 'User to tag entries for.'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ try {
+ $user = $this->getUser($input->getArgument('username'));
+ } catch (NoResultException $e) {
+ $output->writeln(sprintf('<error>User %s not found.</error>', $input->getArgument('username')));
+
+ return 1;
+ }
+ $tagger = $this->getContainer()->get('wallabag_core.rule_based_tagger');
+
+ $output->write(sprintf('Tagging entries for user « <info>%s</info> »... ', $user->getUserName()));
+
+ $entries = $tagger->tagAllForUser($user);
+
+ $em = $this->getDoctrine()->getManager();
+ foreach ($entries as $entry) {
+ $em->persist($entry);
+ }
+ $em->flush();
+
+ $output->writeln('<info>Done.</info>');
+ }
+
+ /**
+ * Fetches a user from its username.
+ *
+ * @param string $username
+ *
+ * @return \Wallabag\UserBundle\Entity\User
+ */
+ private function getUser($username)
+ {
+ return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
+ }
+
+ private function getDoctrine()
+ {
+ return $this->getContainer()->get('doctrine');
+ }
+}
*/
public function addTag(Tag $tag)
{
+ if ($this->tags->contains($tag)) {
+ return;
+ }
+
$this->tags[] = $tag;
$tag->addEntry($this);
}
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
+use Wallabag\CoreBundle\Repository\EntryRepository;
use Wallabag\CoreBundle\Repository\TagRepository;
use Wallabag\UserBundle\Entity\User;
{
private $rulerz;
private $tagRepository;
+ private $entryRepository;
- public function __construct(RulerZ $rulerz, TagRepository $tagRepository)
+ public function __construct(RulerZ $rulerz, TagRepository $tagRepository, EntryRepository $entryRepository)
{
- $this->rulerz = $rulerz;
- $this->tagRepository = $tagRepository;
+ $this->rulerz = $rulerz;
+ $this->tagRepository = $tagRepository;
+ $this->entryRepository = $entryRepository;
}
/**
}
}
+ /**
+ * Apply all the tagging rules defined by a user on its entries.
+ *
+ * @param User $user
+ *
+ * @return array<Entry> A list of modified entries.
+ */
+ public function tagAllForUser(User $user)
+ {
+ $rules = $this->getRulesForUser($user);
+ $entries = array();
+
+ foreach ($rules as $rule) {
+ $qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
+ $entries = $this->rulerz->filter($qb, $rule->getRule());
+
+ foreach ($entries as $entry) {
+ foreach ($rule->getTags() as $label) {
+ $tag = $this->getTag($user, $label);
+
+ $entry->addTag($tag);
+ $entries[] = $entry;
+ }
+ }
+ }
+
+ return $entries;
+ }
+
/**
* Fetch a tag for a user.
*
arguments:
- @rulerz
- @wallabag_core.tag_repository
+ - @wallabag_core.entry_repository
+
+ wallabag_core.entry_repository:
+ class: Wallabag\CoreBundle\Repository\EntryRepository
+ factory_service: doctrine.orm.default_entity_manager
+ factory_method: getRepository
+ arguments:
+ - WallabagCoreBundle:Entry
wallabag_core.tag_repository:
class: Wallabag\CoreBundle\Repository\TagRepository
class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
{
private $rulerz;
- private $repository;
+ private $tagRepository;
+ private $entryRepository;
private $tagger;
public function setUp()
{
- $this->rulerz = $this->getRulerZMock();
- $this->repository = $this->getTagRepositoryMock();
+ $this->rulerz = $this->getRulerZMock();
+ $this->tagRepository = $this->getTagRepositoryMock();
+ $this->entryRepository = $this->getEntryRepositoryMock();
- $this->tagger = new RuleBasedTagger($this->rulerz, $this->repository);
+ $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository);
}
public function testTagWithNoRule()
->with($entry, 'rule as string')
->willReturn(true);
- $this->repository
+ $this->tagRepository
->expects($this->once())
->method('findOneByLabelAndUserId')
->willReturn($tag);
->disableOriginalConstructor()
->getMock();
}
+
+ private function getEntryRepositoryMock()
+ {
+ return $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
}
->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();
+ }
}