1 |
mlimic |
515 |
<?php |
2 |
|
|
|
3 |
mlimic |
523 |
/* |
4 |
|
|
* Treats requests that demand a synchronization. |
5 |
|
|
* |
6 |
|
|
* @author: Mirna Limic <[email protected]> |
7 |
|
|
* @uses ./restler The RESTLER framework. When using PUT and POST http methods |
8 |
|
|
* the function receiving the incomming data MUST contain a parameter called |
9 |
|
|
* request_data. The RESTLER framework stores the incoming JSON string converted |
10 |
|
|
* into an array in the request_data parameter. |
11 |
|
|
* |
12 |
|
|
* @todo Finish the synchronization of user module. Add support for the |
13 |
|
|
* synchronization of additional modules. |
14 |
|
|
* |
15 |
|
|
* Date: 18/10/2012 |
16 |
|
|
* Follow-up: |
17 |
|
|
* Bugs: Unknown |
18 |
|
|
* |
19 |
|
|
*/ |
20 |
|
|
|
21 |
mlimic |
515 |
include_once ('./REST/services.php'); |
22 |
|
|
include_once('./metier/maintenancemanager.php'); |
23 |
|
|
|
24 |
|
|
class maintenance extends Services { |
25 |
mlimic |
523 |
|
26 |
|
|
/* |
27 |
|
|
* Constructor |
28 |
|
|
* |
29 |
|
|
* Calls its parent's constructor and fills the contents array with the |
30 |
|
|
* keys that are to be searched for in the incoming JSON data. |
31 |
|
|
*/ |
32 |
mlimic |
515 |
function __construct() { |
33 |
|
|
parent::__construct(); |
34 |
|
|
$this->contents['module'] = ''; |
35 |
|
|
$this->contents['data'] = ''; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
|
39 |
mlimic |
523 |
/* |
40 |
|
|
* Destructor |
41 |
|
|
* |
42 |
|
|
* Call's its parent's destructor. |
43 |
|
|
*/ |
44 |
mlimic |
515 |
function __destruct() { |
45 |
|
|
parent::__destruct(); |
46 |
|
|
} |
47 |
|
|
|
48 |
mlimic |
523 |
|
49 |
|
|
/* |
50 |
|
|
* Called when a POST http request is made to initiate a |
51 |
|
|
* synchronization process. |
52 |
|
|
* |
53 |
|
|
* Checks the validity of the format, and the presence of |
54 |
|
|
* content (if mandatory) of the data received with the request. |
55 |
|
|
* Calls an matier/xxxManager to do the processing of the |
56 |
|
|
* request data. |
57 |
|
|
* @param mixed $request_data The incoming JSON data as an array. |
58 |
|
|
* Note: the parameter has to be named this way due to RESTLER's |
59 |
|
|
* parameter mapping of JSON data onto $request_data. |
60 |
|
|
* @return mixed The array contining the return code. Where |
61 |
|
|
* 400 is sent on error. |
62 |
|
|
* 200 is sent on success. |
63 |
|
|
*/ |
64 |
mlimic |
515 |
function post($request_data) { |
65 |
|
|
|
66 |
|
|
if (!$this->requestValid($request_data)) { |
67 |
|
|
return $this->sendHttpCode(400, 'Missing mandatory data.'); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
$this->metier_manager = new MaintenanceManager(); |
71 |
|
|
$ret = $this->metier_manager->performMaintenance( |
72 |
|
|
$request_data['module'], $request_data['data']); |
73 |
mlimic |
523 |
|
74 |
|
|
// send the reply |
75 |
|
|
return $this->sendReply($ret, 'Error when synchronizing.'); |
76 |
mlimic |
515 |
} |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
?> |