1 |
<?php |
<?php |
2 |
|
|
3 |
|
/* |
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 |
include_once ('./REST/services.php'); |
include_once ('./REST/services.php'); |
22 |
include_once('./metier/maintenancemanager.php'); |
include_once('./metier/maintenancemanager.php'); |
23 |
|
|
24 |
class maintenance extends Services { |
class maintenance extends Services { |
25 |
|
|
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 |
function __construct() { |
function __construct() { |
33 |
parent::__construct(); |
parent::__construct(); |
34 |
$this->contents['module'] = ''; |
$this->contents['module'] = ''; |
36 |
} |
} |
37 |
|
|
38 |
|
|
39 |
|
/* |
40 |
|
* Destructor |
41 |
|
* |
42 |
|
* Call's its parent's destructor. |
43 |
|
*/ |
44 |
function __destruct() { |
function __destruct() { |
45 |
parent::__destruct(); |
parent::__destruct(); |
46 |
} |
} |
47 |
|
|
48 |
|
|
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 |
function post($request_data) { |
function post($request_data) { |
65 |
|
|
66 |
if (!$this->requestValid($request_data)) { |
if (!$this->requestValid($request_data)) { |
70 |
$this->metier_manager = new MaintenanceManager(); |
$this->metier_manager = new MaintenanceManager(); |
71 |
$ret = $this->metier_manager->performMaintenance( |
$ret = $this->metier_manager->performMaintenance( |
72 |
$request_data['module'], $request_data['data']); |
$request_data['module'], $request_data['data']); |
73 |
if ($ret != 'OK') { |
|
74 |
return $this->sendHttpCode(400, $ret); |
// send the reply |
75 |
} |
return $this->sendReply($ret, 'Error when synchronizing.'); |
|
return $this->sendHttpCode(200, 'Maintenance performed successfully.'); |
|
76 |
} |
} |
77 |
|
|
78 |
|
|