/[openfoncier]/trunk/services/outgoing/messageenqueuer.php
ViewVC logotype

Annotation of /trunk/services/outgoing/messageenqueuer.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 834 - (hide annotations)
Mon Nov 26 16:45:11 2012 UTC (12 years, 2 months ago) by mlimic
File size: 7117 byte(s)
Changement du dyn/include.inc.php et service/outgoing/messageenqueuer.php pour corriger le probleme d'includes.

1 mlimic 806 <?php
2    
3    
4 mlimic 834 require_once('vendor/autoload.php');
5 mlimic 806 use PhpAmqpLib\Connection\AMQPConnection;
6     use PhpAmqpLib\Message\AMQPMessage;
7    
8 mlimic 827 (defined("DEBUG") ? "" : define("DEBUG", EXTRA_VERBOSE_MODE));
9    
10     // pour des besoins de logging il faut setter $_SERVER["REQUEST_URI"]
11     if (!isset($_SERVER["REQUEST_URI"])) {
12     $_SERVER["REQUEST_URI"] = __FILE__;
13     }
14    
15     // Si le AMQP_DEBUG est defini a true, les messages DEBUG sont envoyes aux
16 mlimic 834 // stdout ce qui peut etre bien pour deboguer
17 mlimic 827 if (DEBUG > PRODUCTION_MODE) {
18     define('AMQP_DEBUG', true);
19     }
20    
21 mlimic 806
22 mlimic 829 class MessageEnqueuer {
23 mlimic 806
24     public static $ERP_DEMANDE_COMPLETUDE_PC = 'erpDemandeCompletudePc';
25     public static $ERP_QUALIFIE = 'erpQualifie';
26     public static $ERP_DEMANDE_QUALIFICATION_PC = 'erpDemandeQualificationPc';
27     public static $ERP_DEMANDE_INSTRUCTION_PC = 'erpDemandeInstructionPc';
28     public static $ERP_CONSULTATION_CONFORMITE = 'erpConsultationConformite';
29     public static $ERP_DEMANDE_OUVERTURE_PC = 'erpDemandeOuverturePc';
30     public static $ERP_DEPOT_DOSSIER_DAT = 'erpDepotDossierDat';
31     public static $ERP_ANNULATION_DEMANDE = 'erpAnnulationDemande';
32     public static $ERP_DEMANDE_OUVERTURE_DAT = 'erpDemandeOuvertureDat';
33     public static $ERP_DECISION_CONFORMITE_EFFECTUE = 'erpDecisionConformiteEffectue';
34 mlimic 810 public static $ERP_ARRETE_PC_EFFECTUE = 'erpArretePcEffectue';
35 mlimic 806
36     var $BAD_DATA = -2;
37     var $OK = 0;
38     var $KO = -1;
39    
40    
41     public function __construct() {
42 mlimic 834 include_once('../dyn/services.inc.php');
43 mlimic 806 $this->ret_array = array();
44     $this->ret_array['date'] = date('d/m/Y H:i');
45 mlimic 830 $this->ret_array['emetteur'] = $_SESSION['login'];
46 mlimic 806 $this->dossier_instruction = null;
47     $this->competence = null;
48     $this->contrainte_plu = null;
49 mlimic 810 $this->consultation = null;
50 mlimic 811 $this->decision = null;
51 mlimic 806
52     // les donnees de la connexion
53 mlimic 830 $this->queue = $ERP_QUEUE;
54     $this->host = $ERP_CONNECTION_HOST;
55     $this->port = $ERP_CONNECTIOn_PORT;
56     $this->user = $ERP_CONNECTION_USER;
57     $this->password = $ERP_CONNECTION_PASSWORD;
58     $this->vhost = $ERP_CONNECTION_VHOST;
59 mlimic 806 }
60    
61    
62     /**
63     * Precondition: $msg_type est egal a valeur d'une des $ERP_*
64     */
65 mlimic 829 public function enqueueMessage($method) {
66 mlimic 806 if (method_exists($this, $method)) {
67     return $this->$method();
68     }
69     return $this->KO;
70     }
71    
72    
73     private function enqueueRequest() {
74     $msg_str = json_encode($this->ret_array);
75    
76     if ($msg_str === false) {
77     return $this->KO;
78     }
79    
80     $exchange = 'router';
81     $queue = $this->queue;
82    
83     $conn = new AMQPConnection($this->host, $this->port, $this->user,
84     $this->password, $this->vhost);
85     $ch = $conn->channel();
86     if (is_null($ch)) {
87     return -1;
88     }
89    
90     $ch->queue_declare($queue, false, true, false, false);
91    
92     $ch->exchange_declare($exchange, 'direct', false, true, false);
93    
94     $ch->queue_bind($queue, $exchange);
95    
96 mlimic 811 $msg = new AMQPMessage($msg_str,
97 mlimic 806 array('content_type' => 'text/plain', 'delivery_mode' => 2));
98     $ch->basic_publish($msg, $exchange);
99    
100     $ch->close();
101     $conn->close();
102    
103 mlimic 827 // log le message qui etait mis sur la pile dans RabbitMQ
104     logger::instance()->log("Ajout du message sur pile: ".
105     json_encode($this->ret_array), EXTRA_VERBOSE_MODE);
106    
107 mlimic 806 return 0;
108     }
109    
110    
111     public function setDossierInstructionIdentifier($id) {
112     $this->dossier_instruction = $id;
113     }
114    
115    
116     public function setCompetence($competence) {
117     $this->competence = $competence;
118     }
119    
120    
121     public function setContraintePlu($contrainte_plu) {
122     $this->contrainte_plu = $contrainte_plu;
123     }
124    
125    
126 mlimic 810 public function setConsultationIdentifier($id) {
127     $this->consultation = $id;
128     }
129 mlimic 811
130    
131     public function setDecision($decision) {
132     $this->decision = $decision;
133     }
134 mlimic 810
135 mlimic 811
136     private function generic($msg_type, $contenu_keys = null) {
137     $this->ret_array["type"] = $msg_type;
138     if (is_null($this->dossier_instruction)) {
139     // manque des donnees
140     return $this->BAD_DATA;
141     }
142     $this->ret_array['date'] = date('d/m/Y H:i');
143     $this->ret_array['emetteur'] = $_SESSION['login'];
144     $this->ret_array['dossier_instruction'] = $this->dossier_instruction;
145    
146     if (!is_null($contenu_keys)) {
147 mlimic 810 $contenu = array();
148 mlimic 811 foreach ($contenu_keys as $attrib) {
149 mlimic 810 if (is_null($this->$attrib)) {
150     return $this->BAD_DATA;
151     }
152     $contenu[$attrib] = $this->$attrib;
153     }
154     $this->ret_array['contenu'] = $contenu;
155     }
156     return $this->enqueueRequest();
157 mlimic 806 }
158    
159 mlimic 811
160 mlimic 810 private function erpQualifie() {
161 mlimic 811 $contenu_keys = array('competence',
162 mlimic 810 'contrainte_plu');
163 mlimic 811 return $this->generic('ERP Qualifié',
164     $contenu_keys);
165 mlimic 810 }
166 mlimic 806
167 mlimic 810
168 mlimic 806 private function erpDemandeCompletudePc() {
169 mlimic 810 return $this->generic('Demande de complétude dossier ERP');
170 mlimic 806 }
171    
172 mlimic 810
173     private function erpDemandeQualificationPc() {
174     return $this->generic('Demande de qualification ERP');
175     }
176    
177    
178     private function erpDemandeInstructionPc() {
179     if (is_null($this->consultation)) {
180     return $this->BAD_DATA;
181     }
182 mlimic 811 //$this->ret_array['type'] = 'Demande d\'avis de dossier PC pour un ERP';
183 mlimic 810 $this->ret_array['consultation'] = $this->consultation;
184 mlimic 811 return $this->generic('Demande d\'avis de dossier PC pour un ERP');
185 mlimic 810 }
186    
187    
188     private function erpArretePcEffectue() {
189 mlimic 811 if (is_null($this->dossier_instruction)
190     || is_null($this->decision)) {
191     // manque des donnees
192     return $this->BAD_DATA;
193     }
194     return $this->generic('Arrêté PC effectué',
195     array('decision'));
196 mlimic 810 }
197    
198 mlimic 811
199     private function erpConsultationConformite() {
200     if (is_null($this->consultation)) {
201     return $this->BAD_DATA;
202     }
203     $this->ret_array['consultation'] = $this->consultation;
204     return $this->generic('Consultation ERP pour conformité');
205     }
206    
207    
208     private function erpDemandeOuverturePc() {
209     return $this->generic('Demande d\'ouverture ERP PC');
210     }
211    
212    
213     private function erpDepotDossierDat() {
214     return $this->generic('Dépôt de dossier DAT');
215     }
216    
217    
218     public function erpAnnulationDemande() {
219     return $this->generic('Annulation de la demande');
220     }
221    
222    
223     public function erpDemandeOuvertureDat() {
224     return $this->generic('Demande d\'ouverture ERP DAT');
225     }
226    
227    
228     public function erpDecisionConformiteEffectue() {
229     return $this->generic('Décision de conformité effectuée');
230     }
231 mlimic 806 }
232    
233     ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26