1 | <?php |
---|
2 | |
---|
3 | class indexSolrTask extends sfBaseTask |
---|
4 | { |
---|
5 | private $file_conf; |
---|
6 | |
---|
7 | private function writeState() |
---|
8 | { |
---|
9 | $fh = fopen($this->file_conf, 'w'); |
---|
10 | fwrite($fh, serialize($this->state)); |
---|
11 | fclose($fh); |
---|
12 | } |
---|
13 | |
---|
14 | protected function configure() |
---|
15 | { |
---|
16 | $this->namespace = 'index'; |
---|
17 | $this->name = 'Solr'; |
---|
18 | $this->briefDescription = 'Index db value on solr'; |
---|
19 | $this->addOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'test'); |
---|
20 | $this->addOption('app', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'frontend'); |
---|
21 | |
---|
22 | $this->file_conf = sys_get_temp_dir().DIRECTORY_SEPARATOR."reindex_slor.db"; |
---|
23 | $this->state = array(); |
---|
24 | if (file_exists($this->file_conf)) { |
---|
25 | $this->state = unserialize(file_get_contents($this->file_conf)); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | protected function execute($arguments = array(), $options = array()) |
---|
30 | { |
---|
31 | $dir = dirname(__FILE__).'/../../batch/commission/out/'; |
---|
32 | $manager = new sfDatabaseManager($this->configuration); |
---|
33 | |
---|
34 | $solr = new SolrConnector(); |
---|
35 | |
---|
36 | foreach(array("Parlementaire", "Commentaire", "QuestionEcrite", "Amendement", "Intervention") as $table) { |
---|
37 | while (1) { |
---|
38 | $q = Doctrine::getTable($table) |
---|
39 | ->createQuery('o') |
---|
40 | ->orderBy('o.id ASC'); |
---|
41 | if ($this->state[$table]) { |
---|
42 | $q->where('o.id > ?', $this->state[$table]); |
---|
43 | } |
---|
44 | $q->limit(100); |
---|
45 | if (!$q->count()) { |
---|
46 | echo "Count DONE\n"; |
---|
47 | break; |
---|
48 | } |
---|
49 | |
---|
50 | foreach($q->execute() as $o) { |
---|
51 | echo get_class($o).' '.$o->id."\n"; |
---|
52 | $o->Save(); |
---|
53 | $this->state[$table] = $o->id; |
---|
54 | } |
---|
55 | $solr->updateFromCommands(); |
---|
56 | $this->writeState(); |
---|
57 | } |
---|
58 | } |
---|
59 | unlink($this->file_conf); |
---|
60 | } |
---|
61 | |
---|
62 | } |
---|