Version negotiation

pull/762/head
Iglocska 2015-04-26 10:55:39 +02:00
parent 62094989c9
commit ee3e2b0007
2 changed files with 35 additions and 0 deletions

View File

@ -757,4 +757,18 @@ class ServersController extends AppController {
}
}
}
// The server responds with its current version
public function getVersion() {
if (!$this->Auth->user('Role')['perm_sync']) throw new MethodNotAllowedException('Only accessible by sync users');
App::uses('Folder', 'Utility');
$file = new File (ROOT . DS . 'VERSION.json', true);
$version_json = $file->read();
$file->close();
return new CakeResponse(array('body'=> $version_json));
}
public function checkVersionCompatibility($id) {
debug($this->Server->checkVersionCompatibility($id));
}
}

View File

@ -1189,4 +1189,25 @@ class Server extends AppModel {
return array('status' => 3);
}
}
public function checkVersionCompatibility($id, $HttpSocket = false) {
App::uses('Folder', 'Utility');
$file = new File (ROOT . DS . 'VERSION.json', true);
$version_array = json_decode($file->read());
$file->close();
$server = $this->find('first', array('conditions' => array('Server.id' => $id)));
if (!$HttpSocket) {
App::uses('SyncTool', 'Tools');
$syncTool = new SyncTool();
$HttpSocket = $syncTool->setupHttpSocket($server);
}
$uri = $server['Server']['url'] . '/servers/getVersion';
try {
$response = $HttpSocket->get($uri);
} catch (Exception $e) {
return false;
}
return (json_decode($response));
}
}