From ae865ea844445f1fd865e212dbe828c58382bddd Mon Sep 17 00:00:00 2001 From: Natinusala Date: Wed, 14 Oct 2015 10:57:19 +0000 Subject: [PATCH 1/5] Added legacy mode for Odoo 7.0 and prior --- src/OpenERP.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/OpenERP.php b/src/OpenERP.php index 4dc3da3..835c7e6 100644 --- a/src/OpenERP.php +++ b/src/OpenERP.php @@ -22,9 +22,10 @@ class OpenERP { 'get_session_info' => "/web/session/get_session_info", 'destroy' => "/web/session/destroy"); - function __construct($url, $db) { + function __construct($url, $db, $legacy = false) { $this->base = $url; $this->db = $db; + $this->legacy = $legacy; $this->cookie = False; } @@ -34,13 +35,17 @@ 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 + ); + + if ($this->legacy == true) + $data["session_id"] = ""; + + $req = $this->authenticate($data); $this->session_id = $req['session_id']; $this->authenticated = $req["uid"] !== False; $this->uid = $req["uid"]; @@ -101,7 +106,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); } From 0f4dfc9ddeaa69553be04e24408fad92c6ea8946 Mon Sep 17 00:00:00 2001 From: "Nathan S." Date: Wed, 14 Oct 2015 13:00:55 +0200 Subject: [PATCH 2/5] Added legacy mode to the README --- README.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 9935dcf..9ecf265 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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 @@ -46,7 +47,7 @@ sample PHP code:: require_once 'openerp.php'; - $oe = new PhpOeJson\OpenERP("http://localhost:8069", "test_json"); + $oe = new PhpOeJson\OpenERP("http://localhost:8069", "test_json", false /*set this to true for Odoo 7.0-*/); $oe->login("admin", "xxxxxx"); echo "Logged in (session id: " . $oe->session_id . ")"; From 95f20589dc20e59dcfffb75e47c7d045f0016436 Mon Sep 17 00:00:00 2001 From: Natinusala Date: Thu, 15 Oct 2015 07:49:14 +0000 Subject: [PATCH 3/5] Added automated Odoo version detection for legacy mode --- src/OpenERP.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/OpenERP.php b/src/OpenERP.php index 835c7e6..b6ff83f 100644 --- a/src/OpenERP.php +++ b/src/OpenERP.php @@ -20,12 +20,12 @@ 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, $legacy = false) { + function __construct($url, $db) { $this->base = $url; $this->db = $db; - $this->legacy = $legacy; $this->cookie = False; } @@ -42,13 +42,23 @@ public function login($login, $password) { 'password' => $password ); - if ($this->legacy == true) - $data["session_id"] = ""; - $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; + } + + var_dump($this->legacy); return $this->authenticated; } From 43645bc727bb9b9d2b5c7a853e52e9fa2f8d9fd6 Mon Sep 17 00:00:00 2001 From: Natinusala Date: Thu, 15 Oct 2015 07:52:07 +0000 Subject: [PATCH 4/5] Code cleanup --- src/OpenERP.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenERP.php b/src/OpenERP.php index b6ff83f..20e9bd9 100644 --- a/src/OpenERP.php +++ b/src/OpenERP.php @@ -58,8 +58,6 @@ public function login($login, $password) { $this->legacy = false; } - var_dump($this->legacy); - return $this->authenticated; } From 1934b99abd12dac63953f4ba46b0b87cf6d213b3 Mon Sep 17 00:00:00 2001 From: Natinusala Date: Thu, 15 Oct 2015 07:53:13 +0000 Subject: [PATCH 5/5] Removed the legacy mode boolean from README --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 9ecf265..e573025 100644 --- a/README.rst +++ b/README.rst @@ -47,7 +47,7 @@ sample PHP code:: require_once 'openerp.php'; - $oe = new PhpOeJson\OpenERP("http://localhost:8069", "test_json", false /*set this to true for Odoo 7.0-*/); + $oe = new PhpOeJson\OpenERP("http://localhost:8069", "test_json"); $oe->login("admin", "xxxxxx"); echo "Logged in (session id: " . $oe->session_id . ")";