equal
deleted
inserted
replaced
2 |
2 |
3 namespace Application\Migrations; |
3 namespace Application\Migrations; |
4 |
4 |
5 use Doctrine\DBAL\Migrations\AbstractMigration, |
5 use Doctrine\DBAL\Migrations\AbstractMigration, |
6 Doctrine\DBAL\Schema\Schema, |
6 Doctrine\DBAL\Schema\Schema, |
7 IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
7 IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils, |
|
8 IRI\Bundle\WikiTagBundle\Listener\DocumentListener; |
8 |
9 |
9 /** |
10 /** |
10 * Migration for WikiTagBundle <= V00.13 |
11 * Migration for WikiTagBundle <= V00.13 |
11 * This migration takes every tag label and search the REAL dbpedia uri associated to this label. |
12 * 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 * Before, the dbpedia uri was manually generated by http://dbpedia.org/resource/ + english_label. |
23 |
24 |
24 // First we get all tags. |
25 // First we get all tags. |
25 $em = $GLOBALS["kernel"]->getContainer()->get( 'doctrine.orm.entity_manager' ); |
26 $em = $GLOBALS["kernel"]->getContainer()->get( 'doctrine.orm.entity_manager' ); |
26 // Avoid php annoying memory leaks |
27 // Avoid php annoying memory leaks |
27 $em->getConnection()->getConfiguration()->setSQLLogger(null); |
28 $em->getConnection()->getConfiguration()->setSQLLogger(null); |
|
29 |
|
30 // remove event listener to avoid useless sql queries. Only WikiTag's Tags are modified |
|
31 $listenerInst = null; |
|
32 foreach ($em->getEventManager()->getListeners() as $event => $listeners) { |
|
33 foreach ($listeners as $hash => $listener) { |
|
34 if ($listener instanceof DocumentListener) { |
|
35 $listenerInst = $listener; |
|
36 break 2; |
|
37 } |
|
38 } |
|
39 } |
|
40 $listenerInst || die('Listener is not registered in the event manager'); |
|
41 $evm = $em->getEventManager(); |
|
42 $evm->removeEventListener(array('onFlush', 'preRemove', 'postPersist', 'postUpdate', 'postRemove'), $listenerInst); |
28 |
43 |
29 // First step : we populate the dbpedia uris thanks to the dbpedia-owl:wikiPageID |
44 // First step : we populate the dbpedia uris thanks to the dbpedia-owl:wikiPageID |
30 echo "\nFIRST STEP"; |
45 echo "\nFIRST STEP"; |
31 $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE t.wikipediaPageId IS NOT NULL ORDER BY t.label ASC');//->setMaxResults(240)->setFirstResult(500); |
46 $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE t.wikipediaPageId IS NOT NULL ORDER BY t.label ASC');//->setMaxResults(240)->setFirstResult(500); |
32 $tags = $query->getResult(); |
47 $tags = $query->getResult(); |