| author | cavaliet |
| Wed, 02 Apr 2014 14:35:17 +0200 | |
| changeset 113 | e4f8c2479e78 |
| parent 71 | b01e36991488 |
| permissions | -rw-r--r-- |
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
|
71
b01e36991488
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
40
diff
changeset
|
2 |
/* |
|
b01e36991488
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
40
diff
changeset
|
3 |
* This file is part of the WikiTagBundle package. |
|
b01e36991488
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
40
diff
changeset
|
4 |
* |
|
b01e36991488
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
40
diff
changeset
|
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
b01e36991488
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
40
diff
changeset
|
6 |
* |
|
b01e36991488
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
40
diff
changeset
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
b01e36991488
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
40
diff
changeset
|
8 |
* file that was distributed with this source code. |
|
b01e36991488
add headers for public repository release
ymh <ymh.work@gmail.com>
parents:
40
diff
changeset
|
9 |
*/ |
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
namespace Application\Migrations; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
|
| 40 | 13 |
use Doctrine\DBAL\Migrations\OutputWriter; |
14 |
||
15 |
use Doctrine\DBAL\Migrations\AbstractMigration; |
|
16 |
use Doctrine\DBAL\Schema\Schema; |
|
17 |
use Doctrine\Common\EventManager; |
|
18 |
use Doctrine\ORM\EntityManager; |
|
19 |
use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
|
20 |
use IRI\Bundle\WikiTagBundle\Entity\Tag; |
|
21 |
||
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
/** |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
* Auto-generated Migration: Please modify to your need! |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
*/ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
class Version20111125175224 extends AbstractMigration |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
{ |
| 40 | 28 |
|
29 |
private function showProgress($current, $total, $label, $width) |
|
30 |
{ |
|
31 |
$percent = (floatval($current)/floatval($total)) * 100.0; |
|
32 |
$marks = intval(floor(floatval($width) * ($percent / 100.0) )); |
|
33 |
$spaces = $width - $marks; |
|
34 |
||
35 |
$status_bar="\r["; |
|
36 |
$status_bar.=str_repeat("=", $marks); |
|
37 |
if($marks<$width){ |
|
38 |
$status_bar.=">"; |
|
39 |
$status_bar.=str_repeat(" ", $spaces); |
|
40 |
} else { |
|
41 |
$status_bar.="="; |
|
42 |
} |
|
43 |
||
44 |
$disp=str_pad(number_format($percent, 0),3, " ", STR_PAD_LEFT); |
|
45 |
||
46 |
$label = str_pad(substr($label,0,50), 50, " "); |
|
47 |
$current_str = str_pad($current, strlen("$total"), " ", STR_PAD_LEFT); |
|
48 |
||
49 |
$status_bar.="] $disp% $current_str/$total : $label"; |
|
50 |
||
51 |
$this->write("$status_bar "); |
|
52 |
||
53 |
if($current == $total) { |
|
54 |
$this->write("\n"); |
|
55 |
} |
|
56 |
} |
|
57 |
||
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
public function up(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
// this up() migration is autogenerated, please modify it to your needs |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
$this->addSql("ALTER TABLE wikitag_document ADD CONSTRAINT FK_256601059F75D7B0 FOREIGN KEY (external_id) REFERENCES Document(id)"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
$this->addSql("ALTER TABLE wikitag_document_tag CHANGE wikipedia_revision_id wikipedia_revision_id BIGINT DEFAULT NULL"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
$this->addSql("ALTER TABLE wikitag_tag ADD alternative_label VARCHAR(1024) DEFAULT NULL, ADD wikipedia_alternative_url VARCHAR(2048) DEFAULT NULL, ADD alternative_wikipedia_pageid BIGINT DEFAULT NULL, CHANGE normalized_pageid wikipedia_pageid BIGINT DEFAULT NULL"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
public function postUp(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
{ |
| 40 | 70 |
$doctrine = $GLOBALS["application"]->getKernel()->getContainer()->get('doctrine'); |
71 |
$em = $doctrine->getEntityManager(); |
|
72 |
||
73 |
$this->skipIf($this->version->isMigrated() !== true, 'postUp can only apply if migration completes.'); |
|
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
//select all tags with redirect and alternative label null |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
76 |
$query = $em->createQuery("SELECT t FROM WikiTagBundle:Tag t WHERE t.urlStatus = :url_status AND t.alternativeLabel IS NULL"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
77 |
$query->setParameter("url_status", Tag::$TAG_URL_STATUS_DICT['redirection']); |
| 40 | 78 |
|
79 |
$querycount = $em->createQuery("SELECT count(t) FROM WikiTagBundle:Tag t WHERE t.urlStatus = :url_status AND t.alternativeLabel IS NULL"); |
|
80 |
$querycount->setParameter("url_status", Tag::$TAG_URL_STATUS_DICT['redirection']); |
|
81 |
||
82 |
||
83 |
$total = $querycount->getSingleScalarResult(); |
|
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
$iterableResult = $query->iterate(); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
$i = 0; |
| 40 | 86 |
$em->beginTransaction(); |
87 |
foreach($iterableResult as $row) { |
|
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
$i++; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
89 |
$tag = $row[0]; |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
|
| 40 | 91 |
$memory = ((($i%10)==0)?" - mem: ".strval(memory_get_usage(true)):""); |
92 |
$this->showProgress($i, $total, "tag : ".$tag->getLabel()."$memory", 50); |
|
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
//process $tag |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
94 |
$wk_info = WikiTagUtils::getWikipediaInfo($tag->getNormalizedLabel()); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
$tag->setWikipediaInfo($wk_info); |
| 40 | 97 |
|
98 |
$em->persist($tag); |
|
99 |
||
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
if (($i % 100) == 0) { |
| 40 | 101 |
$em->flush(); |
102 |
$em->commit(); |
|
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
103 |
$em->clear(); // Detaches all objects from Doctrine! |
| 40 | 104 |
$em->beginTransaction(); |
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
105 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |
} |
| 40 | 107 |
|
108 |
$em->flush(); // Executes all updates. |
|
109 |
$em->commit(); |
|
110 |
$em->clear(); // Detaches all objects from Doctrine! |
|
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
111 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
112 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
113 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
114 |
public function down(Schema $schema) |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
115 |
{ |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
116 |
// this down() migration is autogenerated, please modify it to your needs |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
117 |
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
118 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
119 |
$this->addSql("ALTER TABLE wikitag_document DROP FOREIGN KEY FK_256601059F75D7B0"); |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
120 |
$this->addSql("ALTER TABLE wikitag_document_tag CHANGE wikipedia_revision_id wikipedia_revision_id BIGINT NOT NULL"); |
| 40 | 121 |
$this->addSql("ALTER TABLE wikitag_tag DROP alternative_label, DROP wikipedia_alternative_url, DROP alternative_wikipedia_pageid, CHANGE wikipedia_pageid normalized_pageid BIGINT DEFAULT NULL"); |
|
39
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
122 |
} |
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
123 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
124 |
|
|
03b14b0fe101
Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
125 |
} |