RESTfull sync

redone delete attribute and add that to the sync.
pull/61/head
noud 2012-12-11 10:33:32 +01:00
parent 718691a627
commit 6f4b72f214
3 changed files with 35 additions and 11 deletions

View File

@ -456,6 +456,11 @@ class AttributesController extends AppController {
$result = $this->Attribute->find('first', array('conditions' => array('Attribute.uuid' => $uuid)));
$id = $result['Attribute']['id'];
// TODO private and delete .. bring up ..
//if (true == $result['Attribute']['private']) { // never upload private attributes
// return "Attribute is private and non exportable";
//}
// make sure we have all the data of the Attribute
$this->Attribute->id = $id;
$this->Attribute->recursive = 1;
@ -472,7 +477,7 @@ class AttributesController extends AppController {
App::uses('HttpSocket', 'Network/Http');
$HttpSocket = new HttpSocket();
foreach ($servers as &$server) {
$this->Attribute->deleteAttributeFromServer($this->Attribute->data, $server, $HttpSocket);
$this->Attribute->deleteAttributeFromServer($this->Attribute->data['Attribute']['uuid'], $server, $HttpSocket);
}
}

View File

@ -762,12 +762,7 @@ IF (Attribute.category="External analysis", "j", "k"))))))))))'); // TODO hardc
*
* @return bool true if success, error message if failed
*/
public function deleteAttributeFromServer($attribute, $server, $HttpSocket=null) {
// TODO private and delete
if (true == $attribute['Attribute']['private']) { // never upload private attributes
return "Attribute is private and non exportable";
}
public function deleteAttributeFromServer($uuid, $server, $HttpSocket = null) {
$url = $server['Server']['url'];
$authkey = $server['Server']['authkey'];
if (null == $HttpSocket) {
@ -782,7 +777,7 @@ IF (Attribute.category="External analysis", "j", "k"))))))))))'); // TODO hardc
//'Connection' => 'keep-alive' // LATER followup cakephp ticket 2854 about this problem http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/2854
)
);
$uri = $url . '/attributes/0?uuid=' . $attribute['Attribute']['uuid'];
$uri = $url . '/attributes/0?uuid=' . $uuid;
// LATER validate HTTPS SSL certificate
$this->Dns = ClassRegistry::init('Dns');

View File

@ -1,5 +1,7 @@
<?php
App::uses('AppModel', 'Model');
App::import('Controller', 'Attributes');
/**
* Event Model
*
@ -235,7 +237,28 @@ class Event extends AppModel {
public function uploadEventToServer($event, $server, $HttpSocket=null) {
$newLocation = $this->RESTfullEventToServer($event, $server, null, $HttpSocket);
if (is_string($newLocation)) { // HTTP/1.1 302 Found and Location: http://<newLocation>
$this->RESTfullEventToServer($event, $server, $newLocation, $HttpSocket);
$newTextBody = $this->RESTfullEventToServer($event, $server, $newLocation, $HttpSocket);
// now if save() i.s.o. saveAssociates()
// do the add attributes here
// get the new attribute uuids in an array
$newerUuids = array();
foreach ($event['Attribute'] as $attribute) {
$newerUuids[$attribute['id']] = $attribute['uuid'];
}
// get the already existing attributes and delete the ones that are not there
$xml = Xml::build($newTextBody);
foreach ($xml->Event->Attribute as $attribute) {
foreach ($attribute as $key => $value) {
if ($key == 'uuid') {
if (!in_array((string)$value, $newerUuids)) {
$anAttr = ClassRegistry::init('Attribute');
$anAttr->deleteAttributeFromServer((string)$value, $server, $HttpSocket);
}
}
}
}
}
return true;
}
@ -307,7 +330,7 @@ class Event extends AppModel {
switch ($response->code) {
case '200': // 200 (OK) + entity-action-result
if ($response->isOk()) {
return true;
return isset($urlPath) ? $response->body() : true;
} else {
try {
// parse the XML response and keep the reason why it failed
@ -323,7 +346,8 @@ class Event extends AppModel {
}
break;
case '302': // Found
return $response->headers['Location'];
case '404': // Not Found
return isset($urlPath) ? $response->body() : $response->headers['Location'];
break;
}
}