Command/QueryWikipediaCommand.php
author cavaliet
Mon, 28 Nov 2011 10:34:24 +0100
changeset 46 6f643fc1de26
parent 38 e48c2e503945
child 42 0e57c730bb18
permissions -rwxr-xr-x
commit changes before update.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/*
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * This file is part of the WikiTagBundle package.
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * (c) IRI <http://www.iri.centrepompidou.fr/>
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * For the full copyright and license information, please view the LICENSE
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * file that was distributed with this source code.
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
namespace IRI\Bundle\WikiTagBundle\Command;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
use Doctrine\ORM\QueryBuilder;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
use Symfony\Component\Console\Input\InputArgument;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
use Symfony\Component\Console\Input\InputInterface;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
use Symfony\Component\Console\Input\InputOption;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
use Symfony\Component\Console\Output\OutputInterface;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
class QueryWikipediaCommand extends ContainerAwareCommand
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
{
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    private function showProgress(OutputInterface $output, $current, $total, $label, $width)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
        $percent = (floatval($current)/floatval($total)) * 100.0;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        $marks = intval(floor(floatval($width) * ($percent / 100.0) ));
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
        $spaces = $width - $marks;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
        $status_bar="\r[";
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
        $status_bar.=str_repeat("=", $marks);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
        if($marks<$width){
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
            $status_bar.=">";
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
            $status_bar.=str_repeat(" ", $spaces);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        } else {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
            $status_bar.="=";
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        $disp=str_pad(number_format($percent, 0),3, " ", STR_PAD_LEFT);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
        $label = str_pad(substr($label,0,50), 50, " ");
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
        $current_str = str_pad($current, strlen("$total"), " ", STR_PAD_LEFT);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
        $status_bar.="] $disp%  $current_str/$total : $label";
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
        $output->write("$status_bar  ");
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
        if($current == $total) {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
            $output->writeln("");
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
    private function processTag($tag, $em)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
    {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
        $tag_label_normalized = WikiTagUtils::normalizeTag($tag->getLabel());
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        $new_label = $wp_response['new_label'];
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
        $status = $wp_response['status'];
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
        $url = $wp_response['wikipedia_url'];
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        $pageid = $wp_response['pageid'];
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
        $dbpedia_uri = $wp_response["dbpedia_uri"];
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
        $wikipedia_revision_id = $wp_response['revision_id'];
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
        # We save the datas
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
        if($new_label!=null){
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
            $tag->setLabel($new_label);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
        if($status!=null){
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
            $tag->setUrlStatus($status);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
        $tag->setWikipediaUrl($url);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
        $tag->setWikipediaPageId($pageid);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
        $tag->setDbpediaUri($dbpedia_uri);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
        // Save datas.
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
        $em->persist($tag);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
    
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
          
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    protected function configure()
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
    {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        parent::configure();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
        $this
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
            ->setName('wikitag:query-wikipedia')
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
            ->setDescription('Query wikipedia for tags.')
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
            ->addOption("force","f",InputOption::VALUE_NONE, "Force remove tags")
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
            ->addOption("all","a",InputOption::VALUE_NONE, "Force remove tags")
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
            ->addOption("random","r",InputOption::VALUE_NONE, "randomize query on tags")
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
            ->addOption("site","S",InputOption::VALUE_OPTIONAL, "the url for the wikipedia site", "http://fr.wikipedia.org/w/api.php")
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
            ->addOption("limit","l",InputOption::VALUE_OPTIONAL, "number of tag to process", -1)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
            ->addOption("start",null,InputOption::VALUE_OPTIONAL, "number of tag to ignore", 0);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
    }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
    protected function execute(InputInterface $input, OutputInterface $output)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
    {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
        $force = $input->getOption('force');
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
        $all = $input->getOption('all');
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
        $random = $input->getOption('random');
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
        $site = $input->getOption('site');
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        $limit = intval($input->getOption('limit'));
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
        $start = intval($input->getOption('start'));
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
        $doctrine = $this->getContainer()->get('doctrine');
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
        $qb = $doctrine->getEntityManager()->createQueryBuilder();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
        $qb->from('WikiTagBundle:Tag','t');
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
        if(!$all)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
        {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
            $qb->where($qb->expr()->isNull("t.urlStatus"));
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
        if($start > 0)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
        {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
            $qb->setFirstResult($start);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
        if($limit>=0)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
        {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
            $qb->setMaxResults($limit);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
        $qb_count = clone $qb;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
        $qb_count->select("t.id");
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
        $count = count($qb_count->getQuery()->getScalarResult());
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
        $doctrine->getEntityManager()->clear();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
        if(! $force && $input->isInteractive())
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
        {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
            $dialog = $this->getHelper('dialog');
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
            if (!$dialog->askConfirmation($output, "<question>This command will process $count tag(s). Continue ? (y/N) : </question>", false)) {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
                return;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
            }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
        $qb->select("t");
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
        $done = 0;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
        $iterable = $qb->getQuery()->iterate();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
        $doctrine->getEntityManager()->beginTransaction();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
        while (($row = $iterable->next()) !== false)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
        {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
            $done++;
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
            $tag = $row[0];
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
            
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
            $this->showProgress($output, $done, $count, $tag->getLabel(), 50);
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
            
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
            // process tag
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
            $this->processTag($tag, $doctrine->getEntityManager());
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
                        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
            if($done%100 == 0)
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
            {
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
                $doctrine->getEntityManager()->flush();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
                $doctrine->getEntityManager()->commit();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
                $doctrine->getEntityManager()->clear();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
                $doctrine->getEntityManager()->beginTransaction();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
            }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
        }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
        $doctrine->getEntityManager()->flush();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
        $doctrine->getEntityManager()->commit();
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
        
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
    }
e48c2e503945 add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
}