| author | ymh <ymh.work@gmail.com> |
| Fri, 04 Nov 2011 15:53:59 +0100 | |
| changeset 24 | cd389bf882f1 |
| parent 23 | b435f8055cb4 |
| child 27 | 8551d844b4f3 |
| permissions | -rwxr-xr-x |
| 6 | 1 |
<?php |
2 |
/* |
|
3 |
* This file is part of the WikiTagBundle package. |
|
4 |
* |
|
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
6 |
* |
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
8 |
* file that was distributed with this source code. |
|
9 |
*/ |
|
10 |
||
11 |
namespace IRI\Bundle\WikiTagBundle\Command; |
|
12 |
||
13 |
use Doctrine\ORM\Query; |
|
14 |
||
15 |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
16 |
use Symfony\Component\Console\Input\InputArgument; |
|
17 |
use Symfony\Component\Console\Input\InputInterface; |
|
18 |
use Symfony\Component\Console\Input\InputOption; |
|
19 |
use Symfony\Component\Console\Output\OutputInterface; |
|
20 |
||
21 |
class SyncDocumentsCommand extends ContainerAwareCommand |
|
22 |
{ |
|
23 |
protected function configure() |
|
24 |
{ |
|
25 |
parent::configure(); |
|
26 |
||
27 |
$this |
|
28 |
->setName('wikitag:sync-doc') |
|
29 |
->setDescription('Synchronize and index document class') |
|
30 |
->addOption('clear', 'c', InputOption::VALUE_NONE, "clear all docs"); |
|
31 |
} |
|
32 |
||
33 |
protected function execute(InputInterface $input, OutputInterface $output) |
|
34 |
{ |
|
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
6
diff
changeset
|
35 |
$class = $this->getContainer()->getParameter('wiki_tag.document_class'); |
| 6 | 36 |
$clear = $input->getOption('clear'); |
37 |
||
38 |
||
39 |
$doctrine = $this->getContainer()->get('doctrine'); |
|
40 |
||
41 |
$docrep = $doctrine->getRepository('WikiTagBundle:Document'); |
|
42 |
$rep = $doctrine->getRepository($class); |
|
43 |
||
44 |
if(is_null($rep)) { |
|
45 |
//TODO : translate |
|
46 |
$output->writeln("$class does not have a repository : exiting."); |
|
47 |
return ; |
|
48 |
} |
|
49 |
||
50 |
//TODO : check class to implement DocumentInterface |
|
51 |
//TODO : write progress |
|
52 |
$doclist = $rep->findAll(); |
|
| 24 | 53 |
$total = count($doclist); |
54 |
$done = 0; |
|
| 6 | 55 |
foreach ($doclist as $doc) { |
| 24 | 56 |
$done++; |
57 |
$output->writeln("Process doc id ".$doc->getId()." $done/$total ".strval(intval(floatval($done)/floatval($total)*100.0))."%"); |
|
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
6
diff
changeset
|
58 |
$docrep->writeDocument($doc, $this->getContainer()->getParameter('wiki_tag.document_id_column'), $this->getContainer()->getParameter('wiki_tag.fields')); |
| 6 | 59 |
} |
60 |
$doctrine->getEntityManager()->flush(); |
|
61 |
||
62 |
if($clear) { |
|
63 |
||
|
23
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
6
diff
changeset
|
64 |
$req = $doctrine->getEntityManager()->createQuery("DELETE WikiTagBundle:Document wtdoc WHERE wtdoc.externalId NOT IN (SELECT doc FROM $class doc)"); |
|
b435f8055cb4
improve dynamic docs. create and lad class dynamically
ymh <ymh.work@gmail.com>
parents:
6
diff
changeset
|
65 |
$req->getResult(); |
| 6 | 66 |
$doctrine->getEntityManager()->flush(); |
67 |
} |
|
68 |
||
69 |
$output->writeln(strval(count($doclist)) ." documents imported."); |
|
70 |
} |
|
71 |
} |