1 | <?php |
---|
2 | |
---|
3 | class fixTypeQuestionsTask extends sfBaseTask { |
---|
4 | |
---|
5 | protected function configure() { |
---|
6 | $this->namespace = 'fix'; |
---|
7 | $this->name = 'TypeQuestions'; |
---|
8 | $this->briefDescription = 'Set à question au lieu de loi le type des interventions appartenant a une section de questions'; |
---|
9 | $this->addOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'test'); |
---|
10 | $this->addOption('app', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'frontend'); |
---|
11 | } |
---|
12 | |
---|
13 | protected function execute($arguments = array(), $options = array()) { |
---|
14 | $manager = new sfDatabaseManager($this->configuration); |
---|
15 | $intervs = Doctrine::getTable('Intervention')->createQuery('i') |
---|
16 | ->leftJoin('i.Section s') |
---|
17 | ->where('s.titre_complet LIKE ?', "question%") |
---|
18 | ->andWhere('i.type = ?', "loi") |
---|
19 | ->orderBy('i.seance_id') |
---|
20 | ->execute(); |
---|
21 | echo count($intervs)."\n"; |
---|
22 | |
---|
23 | $seance = -1; |
---|
24 | foreach ($intervs as $itv) { |
---|
25 | if ($seance != $itv->seance_id) { |
---|
26 | $seance = $itv->seance_id; |
---|
27 | echo "Séance N°$seance : http://www.nosdeputes.fr/seance/$seance\n"; |
---|
28 | } |
---|
29 | if (preg_match('/^question/i', $itv->Section->titre_complet) && $itv->type != "question") { |
---|
30 | $itv->type = "question"; |
---|
31 | $itv->save(); |
---|
32 | } |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | } |
---|
37 | |
---|