DoctrineMigrations/Version20140129151724.php
changeset 116 a023e0185a02
child 117 5771052a647a
equal deleted inserted replaced
115:085ea4dbfeee 116:a023e0185a02
       
     1 <?php
       
     2 
       
     3 namespace Application\Migrations;
       
     4 
       
     5 use Doctrine\DBAL\Migrations\AbstractMigration,
       
     6     Doctrine\DBAL\Schema\Schema,
       
     7 	IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
       
     8 
       
     9 /**
       
    10  * Migration for WikiTagBundle <= V00.13
       
    11  * This migration takes every tag label and search the REAL dbpedia uri associated to this label.
       
    12  * Before, the dbpedia uri was manually generated by http://dbpedia.org/resource/ + english_label.
       
    13  * Now we get the dbpedia uri by requesting http://LANG_CODE.dbpedia.org/sparql with the current label.
       
    14  * 
       
    15  */
       
    16 class Version20140129151724 extends AbstractMigration
       
    17 {
       
    18     public function up(Schema $schema)
       
    19     {
       
    20         // this up() migration is autogenerated, please modify it to your needs
       
    21         $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
       
    22         
       
    23         // First we get all tags.
       
    24         $em = $GLOBALS["kernel"]->getContainer()->get( 'doctrine.orm.entity_manager' );
       
    25         $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t ORDER BY t.label ASC');//->setMaxResults(40)->setFirstResult(5000);
       
    26         $tags = $query->getResult();
       
    27         
       
    28         $i = 1;
       
    29         foreach($tags as $tag){
       
    30         	$l = $tag->getLabel();
       
    31         	$uri = WikiTagUtils::getDbpediaUri($tag->getLabel(), [], false);
       
    32         	$tag->setDbpediaUri($uri);
       
    33         	$em->persist($tag);
       
    34         	if( $i % 50 == 0 ){
       
    35         		$em->flush();
       
    36         		echo "\n    FLUSH";
       
    37         	}
       
    38         	$i++;
       
    39         	echo "\n$i : $l \t\t: $uri";
       
    40         }
       
    41         $em->flush();
       
    42     }
       
    43 
       
    44     public function down(Schema $schema)
       
    45     {
       
    46         // this down() migration is autogenerated, please modify it to your needs
       
    47         $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
       
    48     }
       
    49 }