/[openfoncier]/trunk/services/metier/maintenancemanager.php
ViewVC logotype

Contents of /trunk/services/metier/maintenancemanager.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 559 - (show annotations)
Tue Oct 30 17:05:34 2012 UTC (12 years, 3 months ago) by mlimic
File size: 5069 byte(s)
save of services files
1 <?php
2
3 /*
4 * Processes requests received via services which are meant to initiate a
5 * synchronization.
6 *
7 * @author Mirna Limic <[email protected]>
8 * Date: 18/10/2012
9 *
10 * Follow-up:
11 * Bugs:
12 */
13
14 require_once ("./metier/metiermanager.php");
15 //require_once('./REST/amqp_publisher.php');
16
17 class MaintenanceManager extends MetierManager {
18
19 /*
20 * @var mixed Array containing function pointers (i.e. function names)
21 * that are (dereferenced and) called to perform the synchronization tasks.
22 */
23 var $fptrs = array('user' => 'synchronizeUsers',
24 'consultation' => 'updateConsultationsStates'); // 'UserManager'
25
26
27 /*
28 * Constructor.
29 *
30 * Calls its parent's constructor.
31 */
32 public function __construct() {
33 parent::__construct();
34 }
35
36
37 /*
38 * Destructor.
39 *
40 * Calls its parent's destructor.
41 */
42 public function __destruct() {
43 parent::__destruct();
44 }
45
46
47 /*
48 * Starts a synchronization process by calling
49 * one of the functions in the fptrs array.
50 *
51 * @param string $module The key to be used in order to retreive the name
52 * of the function that should be called.
53 * @param mixed $data The data that was received as a part of the request.
54 * @return string The result of processing.
55 */
56 public function performMaintenance($module, $data) {
57
58 // check that the known module is called
59 if (!in_array($module, array_keys($this->fptrs))) {
60 return 'Unknown module in request.';
61 }
62
63 $ret = call_user_func(array($this, $this->fptrs[$module]), $data);
64 return $ret;
65 }
66
67
68 /*
69 * Synchronizes the users data in a DB with the user's data from the
70 * directory services that communicate via LDAP.
71 *
72 * @param mixed $data The data that was received as a part of the request.
73 * @return string The result of processing.
74 */
75 public function synchronizeUsers($data) {
76 // depending on what is in the data do the treatement
77 // currently only user synchronization with ldap is supported
78 $keys = array_keys($data);
79 if (in_array('userToAdd', $keys)
80 || in_array('userToDelete', $keys)
81 || in_array('userToUpdate', $keys)) {
82 //$this->f->synchronizeUsers($data);
83 }
84 return $this->OK;
85 }
86
87
88 /*
89 * Sets to favorable the avis (evaluation) of consultations whose limit
90 * date has passed without there being a return (from an external service).
91 * @param mixed $data The data passed in with the REST call
92 * @return OK on success or not applicable, KO on DB error
93 */
94 public function updateConsultationsStates($data) {
95 $table_name = 'consultation';
96 $sql = "SELECT consultation FROM $table_name WHERE ".
97 " date_limite < DATE '". date('Y-m-d', time()) .
98 "' AND date_retour IS NULL AND avis_consultation IS NULL";
99
100 $res = $this->db->query($sql);
101 // In case of error
102 if ($this->checkDBError($res, 'Erreur lors de mise à jour')) {
103 return $this->KO;
104 }
105
106 $ids = array();
107 while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) {
108 $ids[] = $row[0];
109 }
110 $res->free();
111
112 // if there are no consultations that need to have
113 // their state set to Favorable, return OK
114 if (count($ids) == 0) {
115 $this->setMessage("Aucune mise à jour");
116 return $this->NA;
117 }
118
119 // get the idenfier of the evaluation: 'Favorable'
120 $sql = "SELECT avis_consultation FROM avis_consultation WHERE ".
121 "libelle = 'Tacite'";
122 $res = $this->db->query($sql);
123 if ($this->checkDBError($res, 'Erreur lors de mise à jour')) {
124 return $this->KO;
125 }
126
127 $favorable = -1;
128 while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) {
129 $favorable = $row[0];
130 }
131 $res->free();
132
133 // if we did not find the evaluation 'Favorable', return error
134 if ($favorable < 0) {
135 $this->setMessage("'Favorable' n'est pas présent ".
136 "dans la columne : avis_consultation.libelle");
137 return $this->KO;
138 }
139
140 // update the consultation table to set the 'Favorable' evaluation for
141 // the pertinent consultations
142 $fields = array('avis_consultation' => $favorable);
143 $res = $this->db->autoExecute($table_name, $fields, DB_AUTOQUERY_UPDATE,
144 'consultation IN ('.implode(',', $ids).')');
145 if ($this->checkDBError($res, 'Erreur lors de mise à jour')) {
146 return $this->KO;
147 }
148
149 // $res->getDebugInfo(), $res->getMessage()
150 $this->setMessage('Il y a eu '.count($ids).' demandes de consultations dont '.
151 'l\'avis été passé à Tacite');
152 return $this->OK;
153 }
154
155 }
156
157
158
159 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26