From d0abed98d19cea155dfc08a0670f10e4228d25d0 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 16 Sep 2014 16:09:20 +0300 Subject: [PATCH] jsonObject more --- application/Espo/Entities/Integration.php | 40 +++++++++++-------- .../metadata/entityDefs/ExternalAccount.json | 2 +- .../metadata/entityDefs/Integration.json | 2 +- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/application/Espo/Entities/Integration.php b/application/Espo/Entities/Integration.php index 011b58cce1..0471893328 100644 --- a/application/Espo/Entities/Integration.php +++ b/application/Espo/Entities/Integration.php @@ -36,12 +36,12 @@ class Integration extends \Espo\Core\ORM\Entity } } else { if ($this->get('data')) { - $data = json_decode($this->get('data'), true); + $data = $this->get('data'); } else { - $data = array(); + $data = new \stdClass(); } - if (isset($data[$name])) { - return $data[$name]; + if (isset($data->$name)) { + return $data->$name; } } return null; @@ -51,12 +51,12 @@ class Integration extends \Espo\Core\ORM\Entity { parent::clear($name); - $data = json_decode($this->get('data'), true); + $data = $this->get('data'); if (empty($data)) { - $data = array(); + $data = new \stdClass(); } - unset($data[$name]); - $this->set('data', json_encode($data)); + unset($data->$name); + $this->set('data', $data); } public function set($p1, $p2) @@ -83,12 +83,12 @@ class Integration extends \Espo\Core\ORM\Entity if (!$this->get('enabled')) { return; } - $data = json_decode($this->get('data'), true); + $data = $this->get('data'); if (empty($data)) { - $data = array(); + $data = new \stdClass(); } - $data[$name] = $value; - $this->set('data', json_encode($data)); + $data->$name = $value; + $this->set('data', $data); } } @@ -100,7 +100,7 @@ class Integration extends \Espo\Core\ORM\Entity foreach ($arr as $field => $value) { if (is_string($field)) { - if (is_array($value)) { + if (is_array($value) || ($value instanceof \stdClass)) { $value = json_encode($value); } @@ -127,6 +127,12 @@ class Integration extends \Espo\Core\ORM\Entity $value = null; } break; + case self::JSON_OBJECT: + $value = is_string($value) ? json_decode($value) : $value; + if (!($value instanceof \stdClass) && !is_array($value)) { + $value = null; + } + break; default: break; } @@ -154,12 +160,14 @@ class Integration extends \Espo\Core\ORM\Entity } } - $data = json_decode($this->get('data'), true); + $data = $this->get('data'); if (empty($data)) { - $data = array(); + $data = new \stdClass(); } + + $dataArr = get_object_vars($data); - $arr = array_merge($arr, $data); + $arr = array_merge($arr, $dataArr); return $arr; } diff --git a/application/Espo/Resources/metadata/entityDefs/ExternalAccount.json b/application/Espo/Resources/metadata/entityDefs/ExternalAccount.json index 3dcdfa336b..4bb1ec7c78 100644 --- a/application/Espo/Resources/metadata/entityDefs/ExternalAccount.json +++ b/application/Espo/Resources/metadata/entityDefs/ExternalAccount.json @@ -1,7 +1,7 @@ { "fields": { "data": { - "type": "text" + "type": "jsonObject" }, "enabled": { "type": "bool" diff --git a/application/Espo/Resources/metadata/entityDefs/Integration.json b/application/Espo/Resources/metadata/entityDefs/Integration.json index 3dcdfa336b..4bb1ec7c78 100644 --- a/application/Espo/Resources/metadata/entityDefs/Integration.json +++ b/application/Espo/Resources/metadata/entityDefs/Integration.json @@ -1,7 +1,7 @@ { "fields": { "data": { - "type": "text" + "type": "jsonObject" }, "enabled": { "type": "bool"