From d8439b79858cefab2473433accabc065a14f6590 Mon Sep 17 00:00:00 2001 From: Christophe GARCIA Date: Tue, 12 Sep 2017 16:05:36 +0200 Subject: [PATCH] get persistence from ontology model --- composer.json | 2 +- .../persistence/smoothsql/search/GateWay.php | 15 +++++++-- .../search/driver/TaoSearchDriver.php | 31 +++++++++++++------ manifest.php | 2 +- scripts/update/Updater.php | 2 +- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index ac4916d36..e4d2bba5a 100755 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ "oat-sa/oatbox-extension-installer": "dev-master", "php" : ">=5.3.2", "psr/log": "~1.0", - "oat-sa/lib-generis-search": "2.0.1" + "oat-sa/lib-generis-search": "2.1.0" }, "replace": { "oat-sa/generis":"dev-master" diff --git a/core/kernel/persistence/smoothsql/search/GateWay.php b/core/kernel/persistence/smoothsql/search/GateWay.php index b5e4f03f5..4df6aa840 100644 --- a/core/kernel/persistence/smoothsql/search/GateWay.php +++ b/core/kernel/persistence/smoothsql/search/GateWay.php @@ -65,12 +65,21 @@ class GateWay extends TaoSearchGateWay { protected $resultSetClassName = '\\oat\\generis\\model\\kernel\\persistence\\smoothsql\\search\\TaoResultSet'; public function __construct() { - $this->connector = ServiceManager::getServiceManager() - ->get(common_persistence_Manager::SERVICE_ID) - ->getPersistenceById('default'); + } + public function init() + { + $options = $this->getServiceLocator()->get('search.options'); /** + * @var $model \core_kernel_persistence_smoothsql_SmoothModel + */ + $model = $options['model']; + $this->persistence = $model->getPersistence(); + return parent::init(); + } + + /** * try to connect to database. throw an exception * if connection failed. * diff --git a/core/kernel/persistence/smoothsql/search/driver/TaoSearchDriver.php b/core/kernel/persistence/smoothsql/search/driver/TaoSearchDriver.php index fabbe7c7b..8d3f7f1a6 100644 --- a/core/kernel/persistence/smoothsql/search/driver/TaoSearchDriver.php +++ b/core/kernel/persistence/smoothsql/search/driver/TaoSearchDriver.php @@ -25,11 +25,22 @@ class TaoSearchDriver extends EscaperAbstract { protected $persistence; public function __construct() { - $this->persistence = ServiceManager::getServiceManager() - ->get(\common_persistence_Manager::SERVICE_ID) - ->getPersistenceById('default'); + } - + + public function getPersistence() { + if(is_null($this->persistence)) { + $options = $this->getOptions(); + /** + * @var $model \core_kernel_persistence_smoothsql_SmoothModel + */ + $model = $options['model']; + $this->persistence = $model->getPersistence(); + } + + return $this->persistence; + } + /** * @inherit */ @@ -47,21 +58,21 @@ public function escape($stringValue) { * return quoted empty string */ public function getEmpty() { - return $this->persistence->getPlatForm()->getNullString(); + return $this->getPersistence()->getPlatForm()->getNullString(); } /** * @inherit */ public function quote($stringValue) { - return $this->persistence->quote($stringValue); + return $this->getPersistence()->quote($stringValue); } /** * @inherit */ public function reserved($stringValue) { - return $this->persistence->getPlatForm()->quoteIdentifier($stringValue); + return $this->getPersistence()->getPlatForm()->quoteIdentifier($stringValue); } /** @@ -73,7 +84,7 @@ public function random() { 'postgresql' => 'random()', 'mssql' => 'NEWID()', ]; - $name = $this->persistence->getPlatForm()->getName(); + $name = $this->getPersistence()->getPlatForm()->getName(); return $random[$name]; } @@ -84,7 +95,7 @@ public function groupAggregation($variable , $separator) { 'postgresql' => 'string_agg', ]; - $name = $this->persistence->getPlatForm()->getName(); + $name = $this->getPersistence()->getPlatForm()->getName(); return $group[$name] . '(' . $variable . ',' . $this->escape($this->quote($separator)) . ')'; } @@ -98,7 +109,7 @@ public function like() { 'postgresql' => 'ILIKE', ]; - $name = $this->persistence->getPlatForm()->getName(); + $name = $this->getPersistence()->getPlatForm()->getName(); return $like[$name]; } diff --git a/manifest.php b/manifest.php index 1c395fe1a..2d17f20ac 100755 --- a/manifest.php +++ b/manifest.php @@ -31,7 +31,7 @@ 'label' => 'Generis Core', 'description' => 'Core extension, provide the low level framework and an API to manage ontologies', 'license' => 'GPL-2.0', - 'version' => '4.1.2', + 'version' => '4.2.0', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => array(), 'models' => array( diff --git a/scripts/update/Updater.php b/scripts/update/Updater.php index ada914866..11b033289 100644 --- a/scripts/update/Updater.php +++ b/scripts/update/Updater.php @@ -390,7 +390,7 @@ public function update($initialVersion) { $this->setVersion('3.35.2'); } - $this->skip('3.35.2', '4.1.2'); + $this->skip('3.35.2', '4.2.0'); } private function getReadableModelIds() {