Command/QueryWikipediaCommand.php
changeset 42 0e57c730bb18
parent 38 e48c2e503945
child 43 54f204bceb28
--- a/Command/QueryWikipediaCommand.php	Fri Nov 18 17:54:30 2011 +0100
+++ b/Command/QueryWikipediaCommand.php	Fri Nov 25 18:55:42 2011 +0100
@@ -12,67 +12,20 @@
 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
 
 use Doctrine\ORM\QueryBuilder;
-use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
-class QueryWikipediaCommand extends ContainerAwareCommand
+class QueryWikipediaCommand extends ProgressContainerAwareCommand
 {
 
-    private function showProgress(OutputInterface $output, $current, $total, $label, $width)
-    {
-        $percent = (floatval($current)/floatval($total)) * 100.0;
-        $marks = intval(floor(floatval($width) * ($percent / 100.0) ));
-        $spaces = $width - $marks;
-        
-        $status_bar="\r[";
-        $status_bar.=str_repeat("=", $marks);
-        if($marks<$width){
-            $status_bar.=">";
-            $status_bar.=str_repeat(" ", $spaces);
-        } else {
-            $status_bar.="=";
-        }
-        
-        $disp=str_pad(number_format($percent, 0),3, " ", STR_PAD_LEFT);
-        
-        $label = str_pad(substr($label,0,50), 50, " ");
-        $current_str = str_pad($current, strlen("$total"), " ", STR_PAD_LEFT);
-        
-        $status_bar.="] $disp%  $current_str/$total : $label";
-        
-        $output->write("$status_bar  ");
-        
-        if($current == $total) {
-            $output->writeln("");
-        }
-        
-    }
-    
     private function processTag($tag, $em)
     {
         $tag_label_normalized = WikiTagUtils::normalizeTag($tag->getLabel());
         $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
         
-        $new_label = $wp_response['new_label'];
-        $status = $wp_response['status'];
-        $url = $wp_response['wikipedia_url'];
-        $pageid = $wp_response['pageid'];
-        $dbpedia_uri = $wp_response["dbpedia_uri"];
-        $wikipedia_revision_id = $wp_response['revision_id'];
-        
-        # We save the datas
-        if($new_label!=null){
-            $tag->setLabel($new_label);
-        }
-        if($status!=null){
-            $tag->setUrlStatus($status);
-        }
-        $tag->setWikipediaUrl($url);
-        $tag->setWikipediaPageId($pageid);
-        $tag->setDbpediaUri($dbpedia_uri);
+        $tag->setWikipediaInfo($wp_response);
         
         // Save datas.
         $em->persist($tag);