Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
405523b
updated descriptions
cedricfrancoys Nov 30, 2022
71aa9bd
comments
cedricfrancoys Nov 30, 2022
83797df
added charset and collation to constructor
cedricfrancoys Nov 30, 2022
e5910ff
syntax
cedricfrancoys Nov 30, 2022
781a2c1
comments
cedricfrancoys Nov 30, 2022
c688d2e
added param for getting partial schema
cedricfrancoys Nov 30, 2022
f3a6608
removed timestamp pseudo-type
cedricfrancoys Nov 30, 2022
ee21c56
removed underscores in constraint names
cedricfrancoys Nov 30, 2022
704f786
syntax
cedricfrancoys Nov 30, 2022
15a3f07
minor
cedricfrancoys Nov 30, 2022
f57df6b
removed timezone assignment
cedricfrancoys Nov 30, 2022
f316a3f
comments
cedricfrancoys Nov 30, 2022
5dd091f
added logo file
cedricfrancoys Nov 30, 2022
bf371c7
added logo URL for app
cedricfrancoys Dec 1, 2022
a176eac
cleaned data
cedricfrancoys Dec 1, 2022
7ffc50f
added exception handling
cedricfrancoys Dec 1, 2022
1452957
added exception handling
cedricfrancoys Dec 1, 2022
1fc0dd8
added exception for invalid URI
cedricfrancoys Dec 1, 2022
927d805
updates
cedricfrancoys Dec 1, 2022
fb91c4b
added check to prevent hostname to hold port number
cedricfrancoys Dec 1, 2022
87d352d
syntax
cedricfrancoys Dec 1, 2022
0add385
refactored
cedricfrancoys Dec 1, 2022
974d35e
comments
cedricfrancoys Dec 1, 2022
e3827ed
removed refresh_token
cedricfrancoys Dec 1, 2022
9eb23d4
removed refresh_token
cedricfrancoys Dec 1, 2022
6fc85f0
syntax & cascade updates
cedricfrancoys Dec 1, 2022
4a5280a
translations
cedricfrancoys Dec 1, 2022
2fbf898
removed invalid translated fields
cedricfrancoys Dec 1, 2022
669fec7
syntax
cedricfrancoys Dec 1, 2022
b4867ff
fixed translations
cedricfrancoys Dec 1, 2022
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
4 changes: 2 additions & 2 deletions config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@
},
"DB_DBMS": {
"type": "string",
"description": "Database Management System running on the DB host. Possible values are: 'MYSQL', 'SQLSRV', 'MARIADB', 'POSTGRE', 'ORACLE'",
"description": "Database Management System running on the DB host. Possible values are: 'MYSQL', 'SQLSRV', 'MARIADB', 'POSTGRESQL', 'ORACLE'",
"instant": true,
"default": "MYSQL",
"example": "MARIADB"
},
"DB_CHARSET": {
"type": "string",
"description": "Charset to use when manipulating strings with DBMS. Possible values are: 'utf8' (3 bytes) or 'utf8mb4' (4 bytes).",
"description": "Charset encoding to use when manipulating strings with DBMS. Possible values are: 'utf8' (3 bytes) or 'utf8mb4' (4 bytes).",
"instant": true,
"default": "utf8mb4",
"example": "utf8"
Expand Down
16 changes: 6 additions & 10 deletions eq.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function defined($name) {
}

/**
* Retrieve a configuraiton parameter as a constant.
* Retrieve a configuration parameter as a constant.
*/
function constant($name, $default=null) {
return (isset($GLOBALS['QN_CONFIG_ARRAY'][$name]))?$GLOBALS['QN_CONFIG_ARRAY'][$name]:$default;
Expand Down Expand Up @@ -803,7 +803,7 @@ public static function announce(array $announcement) {
// convert value from input format + validate type and usage constraints
$f = Fields::create($config);
// raises an Exception if assignment is not possible
$f->set($body[$param], 'json');
$f->set($body[$param], 'json'); // not explicit type, but Content-Type from HTTP REQUEST
try {
$f->validate();
$result[$param] = $f->get();
Expand Down Expand Up @@ -1009,7 +1009,7 @@ public static function run($type, $operation, $body=[], $root=false) {
if(count($parts) > 0) {
// use first part as package name
$resolved['package'] = array_shift($parts);
// use reamining parts to build script path
// use remaining parts to build script path
if(count($parts) > 0) {
$resolved['script'] = implode('/', $parts).'.php';
}
Expand Down Expand Up @@ -1062,12 +1062,8 @@ public static function run($type, $operation, $body=[], $root=false) {
}
}

// #todo - remove this: L10N_TIMEZONE must be used in controllers producing front-end data (involving some output impacted by localization)
if(defined('L10N_TIMEZONE')) {
date_default_timezone_set(constant('L10N_TIMEZONE'));
}
// #todo - we should run this instead - in the meanwhile, value is the one set in schema.json
// date_default_timezone_set('UTC');
// force timezone to UTC
date_default_timezone_set('UTC');

if(!$root) {
// include and execute requested script
Expand Down Expand Up @@ -1128,7 +1124,7 @@ public static function load_class($class_name) {
// mark class as being loaded
$GLOBALS['eQual_loading_classes'][$class_name] = true;
$file_path = QN_BASEDIR.'/lib/'.str_replace('\\', '/', $class_name);
// use 'class.php' extention
// use 'class.php' extension
if(file_exists($file_path.'.class.php')) {
$result = include_once $file_path.'.class.php';
}
Expand Down
40 changes: 33 additions & 7 deletions lib/equal/db/DBConnection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,28 @@ protected function __construct() {
switch(constant('DB_DBMS')) {
case 'MARIADB':
case 'MYSQL' :
$this->dbConnection = new DBManipulatorMySQL(constant('DB_HOST'), constant('DB_PORT'), constant('DB_NAME'), constant('DB_USER'), constant('DB_PASSWORD'));
$this->dbConnection = new DBManipulatorMySQL(
constant('DB_HOST'),
constant('DB_PORT'),
constant('DB_NAME'),
constant('DB_USER'),
constant('DB_PASSWORD'),
constant('DB_CHARSET'),
constant('DB_COLLATION')
);
break;
case 'SQLSRV' :
$this->dbConnection = new DBManipulatorSqlSrv(constant('DB_HOST'), constant('DB_PORT'), constant('DB_NAME'), constant('DB_USER'), constant('DB_PASSWORD'));
$this->dbConnection = new DBManipulatorSqlSrv(
constant('DB_HOST'),
constant('DB_PORT'),
constant('DB_NAME'),
constant('DB_USER'),
constant('DB_PASSWORD'),
constant('DB_CHARSET'),
constant('DB_COLLATION')
);
break;
case 'POSTGRE' :
case 'POSTGRESQL' :
// #todo
break;
case 'ORACLE' :
Expand All @@ -38,8 +54,19 @@ protected function __construct() {
// add replica members, if any
$i = 1;

while(defined('DB_'.$i.'_HOST') && defined('DB_'.$i.'_PORT') && defined('DB_'.$i.'_USER') && defined('DB_'.$i.'_PASSWORD') && defined('DB_'.$i.'_NAME')) {
$this->addReplicaMember(constant('DB_'.$i.'_HOST'), constant('DB_'.$i.'_PORT'), constant('DB_'.$i.'_NAME'), constant('DB_'.$i.'_USER'), constant('DB_'.$i.'_PASSWORD'));
while(defined('DB_'.$i.'_HOST')
&& defined('DB_'.$i.'_PORT')
&& defined('DB_'.$i.'_USER')
&& defined('DB_'.$i.'_PASSWORD')
&& defined('DB_'.$i.'_NAME')) {

$this->addReplicaMember(
constant('DB_'.$i.'_HOST'),
constant('DB_'.$i.'_PORT'),
constant('DB_'.$i.'_NAME'),
constant('DB_'.$i.'_USER'),
constant('DB_'.$i.'_PASSWORD')
);
++$i;
}
}
Expand Down Expand Up @@ -79,9 +106,8 @@ public function disconnect() {
return $this->dbConnection->disconnect();
}


/**
* Magic overloading method: catch any call and relay it to dbConnection object
* Magic overloading method: catch any call and relay it to DBConnection object
*
* @param string $name
* @param array $arguments
Expand Down
44 changes: 24 additions & 20 deletions lib/equal/db/DBManipulator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,77 @@
class DBManipulator {

/**
* DB server hostname
* DB server hostname.
*
* @var string
* @access protected
*/
protected $host;

/**
* DB server connection port
* DB server TCP connection port.
*
* @var integer
* @access protected
*/
protected $port;

/**
* DB name
* DB name to use for SQL queries.
*
* @var string
* @access protected
*/
protected $db_name;

/**
* Charset encoding to use for communications with DBMS.
*
* @var string
*/
protected $charset;

/**
* Collation to use for storing data (applied on new tables and columns).
*
* @var string
*/
protected $collation;

/**
* DB user
*
* @var string
* @access protected
*/
protected $user_name;


/**
* DB password
*
* @var string
* @access protected
*/
protected $password;


/**
* Latest error id
*
* @var integer
* @access protected
*/
protected $last_id;


/**
* Number of rows affected by last query
*
* @var integer
* @access protected
*/
protected $affected_rows;

/**
* Latest query
*
* @var string
* @access protected
*/
protected $last_query;

/**
* @var \mysqli
* @var mixed
*/
protected $dbms_handler;

Expand All @@ -96,21 +98,23 @@ class DBManipulator {
* Initialize the DBMS data for SQL transactions
*
* @access public
* @param string DB server hostname
* @param string DB server hostname
* @param string DB name
* @param string Username to use for the connection
* @param string Password to use for the connection
* @return void
* @return void
*/
public final function __construct($host, $port, $db, $user, $pass) {
public final function __construct($host, $port, $db, $user, $pass, $charset=null, $collation=null) {
$this->host = $host;
$this->port = $port;
$this->db_name = $db;
$this->user_name = $user;
$this->password = $pass;
$this->dbms_handler = null;
$this->charset = $charset;
$this->collation = $collation;

$this->members = [];
$this->dbms_handler = null;
$this->members = [];
}


Expand Down
10 changes: 5 additions & 5 deletions lib/equal/db/DBManipulatorMySQL.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function connect($auto_select=true) {
if($auto_select) {
if($this->dbms_handler = mysqli_connect($this->host, $this->user_name, $this->password, $this->db_name, $this->port)) {
if($result = $this->select($this->db_name)) {
$query = 'set names '.constant('DB_CHARSET');
$query .= (defined('DB_COLLATION'))?' collate '.constant('DB_COLLATION'):'';
$query = 'set names '.$this->charset;
$query .= ($this->collation)?' collate '.$this->collation:'';
mysqli_query($this->dbms_handler, $query);
$result = true;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public function disconnect() {
}

public function createDatabase($db_name) {
$query = "CREATE DATABASE IF NOT EXISTS $db_name CHARACTER SET ".constant('DB_CHARSET')." COLLATE ".constant('DB_COLLATION').';';
$query = "CREATE DATABASE IF NOT EXISTS $db_name CHARACTER SET ".$this->charset." COLLATE ".$this->collation.';';
$this->sendQuery($query);
}

Expand All @@ -122,7 +122,7 @@ public function getTableConstraints($table_name) {

public function getQueryCreateTable($table_name) {
// #memo - we must add at least one column, so as a convention we add the id column
return "CREATE TABLE IF NOT EXISTS `{$table_name}` (`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY) DEFAULT CHARSET=".constant('DB_CHARSET')." COLLATE=".constant('DB_COLLATION').";";
return "CREATE TABLE IF NOT EXISTS `{$table_name}` (`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY) DEFAULT CHARSET=".$this->charset." COLLATE=".$this->collation.";";
}

/**
Expand All @@ -133,7 +133,7 @@ public function getQueryCreateTable($table_name) {
* 'type' => int(11),
* 'null' => false,
* 'default' => 0,
* 'auto_incremnt' => false,
* 'auto_increment' => false,
* 'primary' => false,
* 'index' => false
* ]
Expand Down
8 changes: 4 additions & 4 deletions lib/equal/db/DBManipulatorSqlSrv.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function connect($auto_select=true) {

if($auto_select) {
$connection_info['Database'] = $this->db_name;
$connection_info['CharacterSet'] = constant('DB_CHARSET');
$connection_info['CharacterSet'] = $this->charset;
}

if($this->dbms_handler = sqlsrv_connect($this->host, $connection_info)) {
Expand Down Expand Up @@ -113,7 +113,7 @@ public function disconnect() {
}

public function createDatabase($db_name) {
$query = "USE master; CREATE DATABASE $db_name COLLATE ".constant('DB_COLLATION').";";
$query = "USE master; CREATE DATABASE $db_name COLLATE ".$this->collation.";";
$this->sendQuery($query, 'create');
}

Expand Down Expand Up @@ -157,7 +157,7 @@ public function getQueryCreateTable($table_name) {
* 'type' => int(11),
* 'null' => false,
* 'default' => 0,
* 'auto_incremnt' => false,
* 'auto_increment' => false,
* 'primary' => false,
* 'index' => false
* ]
Expand All @@ -183,7 +183,7 @@ public function getQueryAddColumn($table_name, $column_name, $def) {
$sql .= ';';

if(isset($def['primary']) && $def['primary']) {
$sql .= "ALTER TABLE [{$table_name}] ADD CONSTRAINT PK_{$column_name} PRIMARY KEY({$def['type']});";
$sql .= "ALTER TABLE [{$table_name}] ADD CONSTRAINT PK_{$column_name} PRIMARY KEY({$def['type']});";
}

return $sql;
Expand Down
3 changes: 1 addition & 2 deletions lib/equal/http/HttpRequest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public function __construct($headline='', $headers=[], $body='') {
}

if(!HttpUri::isValid($uri)) {
echo 'invalid';
// #todo : should we raise an Exception ?
throw new \Exception('invalid URI :'.$uri, QN_ERROR_UNKNOWN);
}
}
// 3) retrieve method
Expand Down
Loading