9 */ |
9 */ |
10 namespace IRI\Bundle\WikiTagBundle\Command; |
10 namespace IRI\Bundle\WikiTagBundle\Command; |
11 |
11 |
12 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
12 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
13 |
13 |
|
14 use IRI\Bundle\WikiTagBundle\Model\Tag; |
14 use Doctrine\ORM\QueryBuilder; |
15 use Doctrine\ORM\QueryBuilder; |
15 use Symfony\Component\Console\Input\InputArgument; |
16 use Symfony\Component\Console\Input\InputArgument; |
16 use Symfony\Component\Console\Input\InputInterface; |
17 use Symfony\Component\Console\Input\InputInterface; |
17 use Symfony\Component\Console\Input\InputOption; |
18 use Symfony\Component\Console\Input\InputOption; |
18 use Symfony\Component\Console\Output\OutputInterface; |
19 use Symfony\Component\Console\Output\OutputInterface; |
39 |
40 |
40 $this |
41 $this |
41 ->setName('wikitag:query-wikipedia') |
42 ->setName('wikitag:query-wikipedia') |
42 ->setDescription('Query wikipedia for tags.') |
43 ->setDescription('Query wikipedia for tags.') |
43 ->addOption("force","f",InputOption::VALUE_NONE, "Force remove tags") |
44 ->addOption("force","f",InputOption::VALUE_NONE, "Force remove tags") |
44 ->addOption("all","a",InputOption::VALUE_NONE, "Force remove tags") |
45 ->addOption("all","a",InputOption::VALUE_NONE, "all") |
|
46 ->addOption("redirection",null,InputOption::VALUE_NONE, "Treat redirections") |
45 ->addOption("random","r",InputOption::VALUE_NONE, "randomize query on tags") |
47 ->addOption("random","r",InputOption::VALUE_NONE, "randomize query on tags") |
46 ->addOption("site","S",InputOption::VALUE_OPTIONAL, "the url for the wikipedia site", "http://fr.wikipedia.org/w/api.php") |
48 ->addOption("site","S",InputOption::VALUE_OPTIONAL, "the url for the wikipedia site", "http://fr.wikipedia.org/w/api.php") |
47 ->addOption("limit","l",InputOption::VALUE_OPTIONAL, "number of tag to process", -1) |
49 ->addOption("limit","l",InputOption::VALUE_OPTIONAL, "number of tag to process", -1) |
48 ->addOption("start",null,InputOption::VALUE_OPTIONAL, "number of tag to ignore", 0); |
50 ->addOption("start",null,InputOption::VALUE_OPTIONAL, "number of tag to ignore", 0); |
49 } |
51 } |
52 { |
54 { |
53 |
55 |
54 $force = $input->getOption('force'); |
56 $force = $input->getOption('force'); |
55 $all = $input->getOption('all'); |
57 $all = $input->getOption('all'); |
56 $random = $input->getOption('random'); |
58 $random = $input->getOption('random'); |
|
59 $redirection = $input->getOption('redirection'); |
57 $site = $input->getOption('site'); |
60 $site = $input->getOption('site'); |
58 $limit = intval($input->getOption('limit')); |
61 $limit = intval($input->getOption('limit')); |
59 $start = intval($input->getOption('start')); |
62 $start = intval($input->getOption('start')); |
60 |
63 |
61 $doctrine = $this->getContainer()->get('doctrine'); |
64 $doctrine = $this->getContainer()->get('doctrine'); |
83 |
91 |
84 $qb_count->select("t.id"); |
92 $qb_count->select("t.id"); |
85 |
93 |
86 $count = count($qb_count->getQuery()->getScalarResult()); |
94 $count = count($qb_count->getQuery()->getScalarResult()); |
87 $doctrine->getEntityManager()->clear(); |
95 $doctrine->getEntityManager()->clear(); |
|
96 |
|
97 if($count === 0) |
|
98 { |
|
99 $output->writeln("No tag to process, exit."); |
|
100 return; |
|
101 } |
88 |
102 |
89 if(! $force && $input->isInteractive()) |
103 if(! $force && $input->isInteractive()) |
90 { |
104 { |
91 $dialog = $this->getHelper('dialog'); |
105 $dialog = $this->getHelper('dialog'); |
92 if (!$dialog->askConfirmation($output, "<question>This command will process $count tag(s). Continue ? (y/N) : </question>", false)) { |
106 if (!$dialog->askConfirmation($output, "<question>This command will process $count tag(s). Continue ? (y/N) : </question>", false)) { |