Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging branch for unique version bump. #687

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
7 changes: 4 additions & 3 deletions common/class.Utils.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php
use oat\oatbox\PhpSerializable;
use oat\oatbox\service\ServiceManager;
use oat\generis\model\kernel\uri\UriProvider;
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -23,6 +20,10 @@
*
*/

use oat\oatbox\PhpSerializable;
use oat\oatbox\service\ServiceManager;
use oat\generis\model\kernel\uri\UriProvider;

/**
*
* Generis Object Oriented API - common/class.Utils.php
Expand Down
11 changes: 1 addition & 10 deletions common/persistence/class.Persistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @package generis
*
*/

abstract class common_persistence_Persistence
{
/**
Expand Down Expand Up @@ -102,15 +103,5 @@ protected function getParams(){
protected function setParams($params){
$this->params = $params;
}

/**
* Generates a unique, not auto-increment based, primary key.
*
* @return string
*/
public function getUniquePrimaryKey()
{
return strrev(uniqid('', true));
}
}

56 changes: 29 additions & 27 deletions common/persistence/class.SqlPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,68 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
*
*
* @author Lionel Lecaque <lionel@taotesting.com>
* @author Jerome Bogaerts, <jerome@taotesting.com>
* @author
*/


/**
* Persistence base on SQL
*
* @author Lionel Lecaque <lionel@taotesting.com>
* @license GPLv2
* @package generis
*
*/
class common_persistence_SqlPersistence extends common_persistence_Persistence
{

/**
*
* @author "Lionel Lecaque, <lionel@taotesting.com>"
* @param string $statement
* @param array $params
* @param array $types
* @return int number of updated rows
*/
public function exec($statement,$params = array())
public function exec($statement, array $params = [], array $types = [])
{
return $this->getDriver()->exec($statement,$params);
return $this->getDriver()->exec($statement, $params, $types);
}


/**
* @author "Lionel Lecaque, <lionel@taotesting.com>"
* @return common_persistence_sql_SchemaManager
*/
public function getSchemaManager(){
return $this->getDriver()->getSchemaManager();
}

/**
* @author Lionel Lecaque, <lionel@taotesting.com>
* @return common_persistence_sql_Platform
*/
public function getPlatForm(){
return $this->getDriver()->getPlatform();
}

/**
*
* @author "Lionel Lecaque, <lionel@taotesting.com>"
* Inserts one row.
*
* @param string $tableName
* @param array $data
* @param array $types
* @return int number of updated rows
*/
public function insert($tableName, array $data)
public function insert($tableName, array $data, array $types = [])
{
return $this->getDriver()->insert($tableName, $data);
return $this->getDriver()->insert($tableName, $data, $types);
}

public function insertMultiple($tableName, array $data)

/**
* Inserts one row.
*
* @param string $tableName
* @param array $data
* @param array $types
* @return int number of updated rows
*/
public function insertMultiple($tableName, array $data, array $types = [])
{
return $this->getDriver()->insertMultiple($tableName, $data);
return $this->getDriver()->insertMultiple($tableName, $data, $types);
}

/**
Expand All @@ -87,22 +91,21 @@ public function updateMultiple($table, array $data)
}

/**
* Executes parameterized query.
*
* @author "Lionel Lecaque, <lionel@taotesting.com>"
* @param string $statement
* @param array $params
* @return \Doctrine\DBAL\Driver\Statement
*/
public function query($statement,$params= array())
public function query($statement, $params = [], array $types = [])
{
return $this->getDriver()->query($statement,$params);
return $this->getDriver()->query($statement, $params, $types);
}


/**
* Convenience access to quote.
*
* @author Jerome Bogaerts, <jerome@taotesting.com>
* @param string $parameter The parameter to quote.
* @param int $parameter_type A PDO PARAM_XX constant.
* @return string The quoted string.
Expand All @@ -115,7 +118,6 @@ public function quote($parameter, $parameter_type = PDO::PARAM_STR){
/**
* Convenience access to lastInsertId.
*
* @author Jerome Bogaerts, <jerome@taotesting.com>
* @param string $name
* @return string The quoted string.
*/
Expand Down
25 changes: 11 additions & 14 deletions common/persistence/sql/dbal/class.Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,30 @@ public function getSchemaManager()
return new common_persistence_sql_dbal_SchemaManager($this->connection->getSchemaManager());
}


/**
* Execute the statement with provided params
*
* @author "Lionel Lecaque, <lionel@taotesting.com>"
* @param mixed $statement
* @param array $params
* @param array $types
* @return integer number of affected row
*/
public function exec($statement,$params = array())
public function exec($statement, $params = [], array $types = [])
{
return $this->connection->executeUpdate($statement,$params);
return $this->connection->executeUpdate($statement, $params, $types);
}


/**
* Query the statement with provided params
*
* @author "Lionel Lecaque, <lionel@taotesting.com>"
* @param mixed $statement
* @param array $params
* @param array $types
* @return \Doctrine\DBAL\Driver\Statement
*/
public function query($statement,$params = array())
public function query($statement, $params = [], array $types = [])
{
return $this->connection->executeQuery($statement,$params);
return $this->connection->executeQuery($statement, $params, $types);
}

/**
Expand All @@ -189,18 +188,16 @@ public function quote($parameter, $parameter_type = PDO::PARAM_STR){
return $this->connection->quote($parameter, $parameter_type);
}



/**
* (non-PHPdoc)
* @see common_persistence_sql_Driver::insert()
* @inheritdoc
*/
public function insert($tableName, array $data){
public function insert($tableName, array $data, array $types = [])
{
$cleanColumns = array();
foreach ($data as $columnName => $value) {
$cleanColumns[$this->getPlatForm()->quoteIdentifier($columnName)] = $value;
}
return $this->connection->insert($tableName, $cleanColumns);
return $this->connection->insert($tableName, $cleanColumns, $types);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions common/persistence/sql/interface.Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
interface common_persistence_sql_Driver extends common_persistence_Driver
{

public function query($statement,$params);
public function query($statement,$params, array $types = []);

public function exec($statement,$params);
public function exec($statement,$params, array $types = []);

/**
* Insert a single row into the database.
Expand All @@ -37,7 +37,7 @@ public function exec($statement,$params);
* @param array $data An associative array containing column-value pairs.
* @return integer The number of affected rows.
*/
public function insert($tableName, array $data);
public function insert($tableName, array $data, array $types = []);

public function insertMultiple($tableName, array $data);

Expand Down
4 changes: 2 additions & 2 deletions common/persistence/sql/trait.MultipleOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait common_persistence_sql_MultipleOperations
/** @var common_persistence_sql_UpdateMultiple */
private $updateMultiple = null;

public function insertMultiple($tableName, array $data)
public function insertMultiple($tableName, array $data, array $types = [])
{
if (is_array($data) && count($data) > 0) {

Expand All @@ -51,7 +51,7 @@ function ($value) use ($platform) {

$query .= implode(', ', $valuesQueries);

return $this->exec($query, $allValues);
return $this->exec($query, $allValues, $types);
} else {
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"monolog/monolog": "^1.23.0",
"fluent/logger": "^1.0.1",
"symfony/lock": "^3.4",
"psr/container": "^1.0.0"
"psr/container": "^1.0.0",
"ramsey/uuid": "^3.8"
},
"require-dev": {
"mikey179/vfsstream": "1.4.0",
Expand Down
4 changes: 1 addition & 3 deletions core/kernel/persistence/smoothsql/search/GateWay.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ public function search(QueryBuilderInterface $Builder) {
}

/**
*
* @param \PDOStatement $statement
* @return array
*/
protected function statementToArray(\PDOStatement $statement) {
protected function statementToArray($statement) {
$result = [];
while($row = $statement->fetch(\PDO::FETCH_OBJ)) {
$result[] = $row;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function like() {
$like = [
'mysql' => 'LIKE',
'postgresql' => 'ILIKE',
'gcp-spanner' => 'LIKE',
];

$name = $this->persistence->getPlatForm()->getName();
Expand Down
39 changes: 39 additions & 0 deletions helpers/UuidPrimaryKeyTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2019 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author "Julien Sébire, <julien@taotesting.com>"
*/

namespace oat\generis\Helper;

use Exception;
use Ramsey\Uuid\Uuid;

trait UuidPrimaryKeyTrait
{
/**
* Generates a unique, not auto-increment based, primary key.
*
* @return string
* @throws Exception
*/
public function getUniquePrimaryKey()
{
return Uuid::uuid4();
}
}
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'label' => 'Generis Core',
'description' => 'Core extension, provide the low level framework and an API to manage ontologies',
'license' => 'GPL-2.0',
'version' => '12.5.2',
'version' => '12.6.0',
'author' => 'Open Assessment Technologies, CRP Henri Tudor',
'requires' => array(),
'models' => array(
Expand Down
5 changes: 5 additions & 0 deletions scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,10 @@ public function update($initialVersion)
$this->setVersion('12.4.1');
}
$this->skip('12.4.1', '12.5.2');
if ($this->isVersion('12.5.2')) {
// not sure about what to do in here.

$this->setVersion('12.6.0');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* Copyright (c) (original work) 2015 Open Assessment Technologies SA
*
*/
namespace oat\generis\test\unit\model\persistence\smoothsql;

namespace oat\generis\test\integration\model\persistence\smoothsql;

use Prophecy\Promise\ReturnPromise;
use Prophecy\Argument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* Copyright (c) (original work) 2015 Open Assessment Technologies SA
*
*/
namespace oat\generis\test\unit\model\persistence\smoothsql;

namespace oat\generis\test\integration\model\persistence\smoothsql;

use \core_kernel_persistence_smoothsql_SmoothRdf;
use Prophecy\Prophet;
Expand Down Expand Up @@ -171,4 +172,4 @@ public function testRemove()
}
}

?>
?>