| author | ymh <ymh.work@gmail.com> |
| Fri, 26 Sep 2014 10:04:40 +0200 | |
| changeset 136 | f209fcb0df6c |
| parent 38 | e48c2e503945 |
| permissions | -rwxr-xr-x |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
/* |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
* This file is part of the WikiTagBundle package. |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
* |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
* |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
* file that was distributed with this source code. |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
*/ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
namespace IRI\Bundle\WikiTagBundle\Command; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
use Symfony\Component\Console\Input\InputArgument; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
use Symfony\Component\Console\Input\InputInterface; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
use Symfony\Component\Console\Input\InputOption; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
use Symfony\Component\Console\Output\OutputInterface; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
class ReorderTagsCommand extends ContainerAwareCommand |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
protected function configure() |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
parent::configure(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
$this |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
->setName('wikitag:reorder-tags') |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
->setDescription('Reorder tags') |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
->addOption("force","f",InputOption::VALUE_NONE, "Force all reorder"); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
protected function execute(InputInterface $input, OutputInterface $output) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
$doctrine = $this->getContainer()->get('doctrine'); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
$configuration = $doctrine->getConnection()->getConfiguration(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
$configuration->setSQLLogger(null); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
$force = $input->getOption('force'); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
if($force) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
$query = $doctrine->getEntityManager()->createQuery("SELECT doc from WikiTagBundle:Document doc"); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
$querycount = $doctrine->getEntityManager()->createQuery("SELECT count(doc) from WikiTagBundle:Document doc"); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
else |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
$query = $doctrine->getEntityManager()->createQuery("SELECT doc from WikiTagBundle:Document doc WHERE doc.manualOrder = FALSE"); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
$querycount = $doctrine->getEntityManager()->createQuery("SELECT count(doc) from WikiTagBundle:Document doc WHERE doc.manualOrder = FALSE"); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
$total = $querycount->getSingleScalarResult(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
$search_service = $this->getContainer()->get('wiki_tag.search'); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
$done = 0; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
$iterable = $query->iterate(); |
|
38
e48c2e503945
add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
57 |
$doctrine->getEntityManager()->beginTransaction(); |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
while (($row = $iterable->next()) !== false) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
$done++; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
$doc = $row[0]; |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
$output->writeln("Process doc id ".$doc->getId()." $done/$total ".strval(intval(floatval($done)/floatval($total)*100.0))."%"); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
$doc->setManualOrder(false); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
$doctrine->getEntityManager()->persist($doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
$search_service->reorderTagsForDocument($doc); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
if($done%100 == 0) |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
{ |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
$doctrine->getEntityManager()->flush(); |
|
38
e48c2e503945
add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
74 |
$doctrine->getEntityManager()->commit(); |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
$doctrine->getEntityManager()->clear(); |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
76 |
$output->writeln("memory : ".strval(memory_get_usage(true))); |
|
38
e48c2e503945
add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
77 |
$doctrine->getEntityManager()->beginTransaction(); |
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
79 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
|
|
38
e48c2e503945
add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
82 |
$doctrine->getEntityManager()->commit(); |
|
e48c2e503945
add commands to purge taf=gs and query wikipedia
ymh <ymh.work@gmail.com>
parents:
34
diff
changeset
|
83 |
|
|
30
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
} |
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
|
|
d2fba1e3b94b
correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
86 |
} |