Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Modest PHP class to manage OpenERP Json query.
Code maturity
-------------

Early working alpha. Comments welcome. Although it was tested against OpenERP version 6.1 and 7.0.
Early working alpha. Comments welcome. Although it was tested against OpenERP version 6.1, 7.0 and 8.0.


Features
Expand All @@ -35,6 +35,7 @@ Features
- Ability to resume an open session (and thus login in openerp) with a
saved ``session_id`` and HTTP ``cookie_id`` (without ``$login`` and
``$password``)
- Backwards compatiblity for Odoo 7.0 and prior with the legacy mode


Usage
Expand Down
33 changes: 23 additions & 10 deletions src/OpenERP.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class OpenERP {
var $urls = array('read' => "/web/dataset/search_read",
'authenticate' => "/web/session/authenticate",
'get_session_info' => "/web/session/get_session_info",
'destroy' => "/web/session/destroy");
'destroy' => "/web/session/destroy",
'get_version_info' => "/web/webclient/version_info");

function __construct($url, $db) {
$this->base = $url;
Expand All @@ -34,17 +35,29 @@ function __construct($url, $db) {
*/
public function login($login, $password) {
$this->cookie = False; // will ask for a new cookie.
$req = $this->authenticate(array(
'base_location' => $this->base,
'db' => $this->db,
'login' => $login,
'password' => $password,
'session_id' => "",
));
$data = array(
'base_location' => $this->base,
'db' => $this->db,
'login' => $login,
'password' => $password
);

$req = $this->authenticate($data);
$this->session_id = $req['session_id'];
$this->authenticated = $req["uid"] !== False;
$this->uid = $req["uid"];


//Get Odoo version
$req = $this->get_version_info();
if (floatval($req["server_serie"]) <= 7.0)
{
$this->legacy = true;
}
else
{
$this->legacy = false;
}

return $this->authenticated;
}

Expand Down Expand Up @@ -101,7 +114,7 @@ function __call($method, $params) {
$params = array();
else
$params = $params[0];
if (!array_key_exists("session_id", $params) && isset($this->session_id))
if ($this->legacy == true && !array_key_exists("session_id", $params) && isset($this->session_id))
$params["session_id"] = $this->session_id;
return $this->json($this->base . $url, $params);
}
Expand Down