1: <?php
2:
3: namespace Himedia\Padocc\Task;
4:
5: use Himedia\Padocc\AttributeProperties;
6: use Himedia\Padocc\Task;
7: use Himedia\Padocc\Task\Extended\TwengaServers;
8:
9: /**
10: * Couche permettant aux tâches l'implémentant d'importer des propriétés issues de fichiers de configuration INI,
11: * de fichiers de configuration shell ou encore de la liste des groupes de serveurs Twenga.
12: * Ces propriétés seront ensuite accessibles via $this->oProperties, instance de PropertiesInterface.
13: *
14: * Toute tâche dérivant Task_WithProperties se voit ainsi dotée de trois attributs XML optionnels et
15: * cumulables : 'loadtwengaservers', 'propertyshellfile' et 'propertyinifile'.
16: * Les voici illustrés dans l'ordre dans lequel ils sont traités si présents au sein de la même tâche :
17: * - 'loadtwengaservers', "true" ou "false" (défaut), chargera la liste des groupes de serveurs Twenga
18: * - 'propertyshellfile', chemin système, par ex. "/path/to/shell_file.cfg", importera en tant que propriétés
19: * les variables du fichier de configuration shell
20: * - 'propertyinifile', chemin système, par ex. "/path/to/config.ini", importera en tant que propriétés
21: * les variables du fichier .INI
22: *
23: * Voir TwengaServers et PropertiesInterface pour plus de détails.
24: *
25: * @author Geoffroy AUBRY <gaubry@hi-media.com>
26: */
27: abstract class WithProperties extends Task
28: {
29: /**
30: * Tâche de chargement des listes de serveurs Twenga sous-jacente.
31: * @var TwengaServers
32: */
33: private $oTwengaServersTask;
34:
35: /**
36: * {@inheritdoc}
37: */
38: protected function init()
39: {
40: parent::init();
41:
42: $this->aAttrProperties = array(
43: 'loadtwengaservers' => AttributeProperties::BOOLEAN,
44: 'propertyshellfile' => AttributeProperties::SRC_PATH,
45: 'propertyinifile' => AttributeProperties::SRC_PATH
46: );
47:
48: // Création de la tâche de chargement des listes de serveurs Twenga sous-jacente :
49: if (! empty($this->aAttValues['loadtwengaservers']) && $this->aAttValues['loadtwengaservers'] == 'true') {
50: $this->oNumbering->addCounterDivision();
51: $this->oTwengaServersTask = TwengaServers::getNewInstance(array(), $this->oProject, $this->oDIContainer);
52: $this->oNumbering->removeCounterDivision();
53: } else {
54: $this->oTwengaServersTask = null;
55: }
56: }
57:
58: /**
59: * Lors de l'exécution de la tâche, charge les propriétés des éventuels fichiers de configuration INI,
60: * fichiers de configuration shell ou encore la liste des groupes de serveurs Twenga.
61: */
62: private function loadProperties ()
63: {
64: if (! empty($this->aAttValues['loadtwengaservers']) && $this->aAttValues['loadtwengaservers'] == 'true') {
65: $this->oTwengaServersTask->execute();
66: }
67: if (! empty($this->aAttValues['propertyshellfile'])) {
68: $this->getLogger()->info('Load shell properties: ' . $this->aAttValues['propertyshellfile'] . '+++');
69: $this->oProperties->loadConfigShellFile($this->aAttValues['propertyshellfile']);
70: $this->getLogger()->info('---');
71: }
72: if (! empty($this->aAttValues['propertyinifile'])) {
73: $this->getLogger()->info('Load ini properties: ' . $this->aAttValues['propertyinifile']);
74: $this->oProperties->loadConfigIniFile($this->aAttValues['propertyinifile']);
75: }
76: }
77:
78: /**
79: * Prépare la tâche avant exécution : vérifications basiques, analyse des serveurs concernés...
80: */
81: public function setUp ()
82: {
83: parent::setUp();
84: if ($this->oTwengaServersTask !== null) {
85: $this->getLogger()->info('+++');
86: $this->oTwengaServersTask->setUp();
87: $this->getLogger()->info('---');
88: }
89: }
90:
91: /**
92: * Phase de pré-traitements de l'exécution de la tâche.
93: * Elle devrait systématiquement commencer par "parent::preExecute();".
94: * Appelé par execute().
95: * @see execute()
96: */
97: protected function preExecute ()
98: {
99: parent::preExecute();
100: $this->getLogger()->info('+++');
101: $this->loadProperties();
102: $this->getLogger()->info('---');
103: }
104: }
105: