Work on the proposal sync for push - from the sender's side

pull/304/merge
iglocska 2014-08-13 10:47:39 +02:00
parent 9799c1d9dd
commit 0a10844dec
1 changed files with 25 additions and 18 deletions

View File

@ -451,35 +451,42 @@ class Server extends AppModel {
'contain' => 'ShadowAttribute',
'fields' => array('Event.uuid')
));
$fails = 0;
$success = 0;
$unchanged = array();
foreach ($events as $k => &$event) {
if (!empty($event['ShadowAttribute'])) {
foreach ($event['ShadowAttribute'] as &$sa) {
$sa['data'] = $saModel->base64EncodeAttachment($sa);
unset($sa['id']);
unset($sa['old_id']);
unset($sa['category_order']);
unset($sa['value1']);
unset($sa['value2']);
}
}
$data = json_encode($event);
$request = array(
'header' => array(
'Authorization' => $server['Server']['authkey'],
'Accept' => 'application/json',
'Content-Type' => 'application/json',
)
);
$uri = $server['Server']['url'] . '/events/pushProposals/' . $event['Event']['uuid'];
$response = $HttpSocket->post($uri, $data, $request);
if ($response->code == '200') {
$uuidList = json_decode($response->body());
} else {
return false;
$data = json_encode($event['ShadowAttribute']);
$request = array(
'header' => array(
'Authorization' => $server['Server']['authkey'],
'Accept' => 'application/json',
'Content-Type' => 'application/json',
)
);
$uri = $server['Server']['url'] . '/events/pushProposals/' . $event['Event']['uuid'];
$response = $HttpSocket->post($uri, $data, $request);
if ($response->code == '200') {
$result = json_decode($response->body());
if ($result->success) {
$success += intval($result->counter);
} else {
$fails++;
}
} else {
$fails++;
}
}
}
debug($events);
} else {
// connect to checkuuid($uuid)