Skip to content

Commit

Permalink
Merge pull request #610 from exodus4d/develop
Browse files Browse the repository at this point in the history
v1.3.4
  • Loading branch information
exodus4d authored Apr 12, 2018
2 parents f3953f4 + d7e081c commit d1a5aa0
Show file tree
Hide file tree
Showing 127 changed files with 2,202 additions and 1,166 deletions.
131 changes: 60 additions & 71 deletions app/lib/db/sql/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,96 +13,96 @@
* | | < | <| -__|-- __|
* |__|__|__||__|__|_____|_____|
*
* Copyright (c) 2016 by ikkez
* Copyright (c) 2012-2018 by ikkez
* Christian Knuth <[email protected]>
* https://github.com/ikkez/F3-Sugar/
*
* @package DB
* @version 2.2.1
* @date 25.04.2017
* @version 2.2.2
* @date 06.03.2018
**/


namespace DB\SQL;

use DB\SQL;
class Schema {

class Schema extends DB_Utils {
use DB_Utils;

public
$dataTypes = array(
'BOOLEAN' => array('mysql' => 'tinyint(1)',
'sqlite2?|pgsql' => 'BOOLEAN',
'mssql|sybase|dblib|odbc|sqlsrv' => 'bit',
'ibm' => 'numeric(1,0)',
'sqlite2?|pgsql' => 'BOOLEAN',
'mssql|sybase|dblib|odbc|sqlsrv' => 'bit',
'ibm' => 'numeric(1,0)',
),
'INT1' => array('mysql' => 'tinyint(4)',
'sqlite2?' => 'integer(4)',
'mssql|sybase|dblib|odbc|sqlsrv' => 'tinyint',
'pgsql|ibm' => 'smallint',
'sqlite2?' => 'integer(4)',
'mssql|sybase|dblib|odbc|sqlsrv' => 'tinyint',
'pgsql|ibm' => 'smallint',
),
'INT2' => array('mysql' => 'smallint(6)',
'sqlite2?' => 'integer(6)',
'pgsql|ibm|mssql|sybase|dblib|odbc|sqlsrv' => 'smallint',
'sqlite2?' => 'integer(6)',
'pgsql|ibm|mssql|sybase|dblib|odbc|sqlsrv' => 'smallint',
),
'INT4' => array('sqlite2?' => 'integer(11)',
'pgsql|imb' => 'integer',
'mysql' => 'int(11)',
'mssql|dblib|sybase|odbc|sqlsrv' => 'int',
'pgsql|imb' => 'integer',
'mysql' => 'int(11)',
'mssql|dblib|sybase|odbc|sqlsrv' => 'int',
),
'INT8' => array('sqlite2?' => 'integer(20)',
'pgsql|mssql|sybase|dblib|odbc|sqlsrv|imb' => 'bigint',
'mysql' => 'bigint(20)',
'pgsql|mssql|sybase|dblib|odbc|sqlsrv|imb' => 'bigint',
'mysql' => 'bigint(20)',
),
'FLOAT' => array('mysql|sqlite2?' => 'FLOAT',
'pgsql' => 'double precision',
'mssql|sybase|dblib|odbc|sqlsrv' => 'float',
'imb' => 'decfloat'
'pgsql' => 'double precision',
'mssql|sybase|dblib|odbc|sqlsrv' => 'float',
'imb' => 'decfloat'
),
'DOUBLE' => array('mysql|ibm' => 'decimal(18,6)',
'sqlite2?' => 'decimal(15,6)', // max 15-digit on sqlite
'pgsql' => 'numeric(18,6)',
'mssql|dblib|sybase|odbc|sqlsrv' => 'decimal(18,6)',
'sqlite2?' => 'decimal(15,6)', // max 15-digit on sqlite
'pgsql' => 'numeric(18,6)',
'mssql|dblib|sybase|odbc|sqlsrv' => 'decimal(18,6)',
),
'VARCHAR128' => array('mysql|sqlite2?|ibm|mssql|sybase|dblib|odbc|sqlsrv' => 'varchar(128)',
'pgsql' => 'character varying(128)',
'pgsql' => 'character varying(128)',
),
'VARCHAR256' => array('mysql|sqlite2?|ibm|mssql|sybase|dblib|odbc|sqlsrv' => 'varchar(255)',
'pgsql' => 'character varying(255)',
'pgsql' => 'character varying(255)',
),
'VARCHAR512' => array('mysql|sqlite2?|ibm|mssql|sybase|dblib|odbc|sqlsrv' => 'varchar(512)',
'pgsql' => 'character varying(512)',
'pgsql' => 'character varying(512)',
),
'TEXT' => array('mysql|sqlite2?|pgsql|mssql' => 'text',
'sybase|dblib|odbc|sqlsrv' => 'nvarchar(max)',
'ibm' => 'BLOB SUB_TYPE TEXT',
'sybase|dblib|odbc|sqlsrv' => 'nvarchar(max)',
'ibm' => 'BLOB SUB_TYPE TEXT',
),
'LONGTEXT' => array('mysql' => 'LONGTEXT',
'sqlite2?|pgsql|mssql' => 'text',
'sybase|dblib|odbc|sqlsrv' => 'nvarchar(max)',
'ibm' => 'CLOB(2000000000)',
'sqlite2?|pgsql|mssql' => 'text',
'sybase|dblib|odbc|sqlsrv' => 'nvarchar(max)',
'ibm' => 'CLOB(2000000000)',
),
'DATE' => array('mysql|sqlite2?|pgsql|mssql|sybase|dblib|odbc|sqlsrv|ibm' => 'date',
),
'DATETIME' => array('pgsql' => 'timestamp without time zone',
'mysql|sqlite2?|mssql|sybase|dblib|odbc|sqlsrv' => 'datetime',
'ibm' => 'timestamp',
'mysql|sqlite2?|mssql|sybase|dblib|odbc|sqlsrv' => 'datetime',
'ibm' => 'timestamp',
),
'TIMESTAMP' => array('mysql|ibm' => 'timestamp',
'pgsql|odbc' => 'timestamp without time zone',
'sqlite2?|mssql|sybase|dblib|sqlsrv'=>'DATETIME',
'pgsql|odbc' => 'timestamp without time zone',
'sqlite2?|mssql|sybase|dblib|sqlsrv'=>'DATETIME',
),
'BLOB' => array('mysql|odbc|sqlite2?|ibm' => 'blob',
'pgsql' => 'bytea',
'mssql|sybase|dblib' => 'image',
'sqlsrv' => 'varbinary(max)',
'pgsql' => 'bytea',
'mssql|sybase|dblib' => 'image',
'sqlsrv' => 'varbinary(max)',
),
),
$defaultTypes = array(
'CUR_STAMP' => array('mysql' => 'CURRENT_TIMESTAMP',
'mssql|sybase|dblib|odbc|sqlsrv' => 'getdate()',
'pgsql' => 'LOCALTIMESTAMP(0)',
'sqlite2?' => "(datetime('now','localtime'))",
'mssql|sybase|dblib|odbc|sqlsrv' => 'getdate()',
'pgsql' => 'LOCALTIMESTAMP(0)',
'sqlite2?' => "(datetime('now','localtime'))",
),
);

Expand All @@ -112,9 +112,6 @@ class Schema extends DB_Utils {
public static
$strict = FALSE;

/** @var \Base */
protected $fw;

const
// DataTypes and Aliases
DT_BOOL = 'BOOLEAN',
Expand Down Expand Up @@ -147,8 +144,7 @@ class Schema extends DB_Utils {

public function __construct(\DB\SQL $db)
{
$this->fw = \Base::instance();
parent::__construct($db);
$this->db = $db;
}

/**
Expand Down Expand Up @@ -304,7 +300,9 @@ public function isCompatible($colType,$colDef) {
}
}

abstract class TableBuilder extends DB_Utils {
abstract class TableBuilder {

use DB_Utils;

protected $columns, $pkeys, $queries, $increments, $rebuild_cmd, $suppress;
public $name;
Expand All @@ -318,7 +316,6 @@ abstract class TableBuilder extends DB_Utils {
/**
* @param string $name
* @param Schema $schema
* @return \DB\SQL\TableBuilder
*/
public function __construct($name, Schema $schema)
{
Expand All @@ -328,7 +325,7 @@ public function __construct($name, Schema $schema)
$this->queries = array();
$this->pkeys = array('id');
$this->increments = 'id';
parent::__construct($schema->db);
$this->db = $schema->db;
}

/**
Expand Down Expand Up @@ -549,6 +546,8 @@ class TableModifier extends TableBuilder {
/**
* generate SQL queries for altering the table and execute it if $exec is true,
* otherwise return the generated query string
* @param bool $exec
* @return array|FALSE
*/
public function build($exec = TRUE)
{
Expand Down Expand Up @@ -763,9 +762,9 @@ public function getCols($types = false)
else
foreach ($schema as $name => &$cols) {
$default = ($cols['default'] === '') ? null : $cols['default'];
if (!is_null($default) && (
(is_int(strpos($curdef=$this->findQuery($this->schema->defaultTypes['CUR_STAMP']),
$default)) || is_int(strpos($default,$curdef)))
if (!is_null($default) && ((is_int(strpos($curdef=strtolower(
$this->findQuery($this->schema->defaultTypes['CUR_STAMP'])),
strtolower($default))) || is_int(strpos(strtolower($default),$curdef)))
|| $default == "('now'::text)::timestamp(0) without time zone"))
{
$default = 'CUR_STAMP';
Expand Down Expand Up @@ -874,7 +873,6 @@ public function renameColumn($name, $new_name)
* @param string $name
* @param string|Column $datatype
* @param bool $force
* @return bool
*/
public function updateColumn($name, $datatype, $force = false)
{
Expand Down Expand Up @@ -1031,7 +1029,9 @@ public function drop($exec = true) {
* Class Column
* @package DB\SQL
*/
class Column extends DB_Utils {
class Column {

use DB_Utils;

public $name, $type, $nullable, $default, $after, $index, $unique, $passThrough, $pkey;
protected $table, $schema, $type_val;
Expand All @@ -1056,7 +1056,7 @@ public function __construct($name, TableBuilder $table) {

$this->table = $table;
$this->schema = $table->schema;
parent::__construct($this->schema->db);
$this->db = $this->schema->db;
}

/**
Expand Down Expand Up @@ -1281,22 +1281,16 @@ public function getDefault() {
constant('\PDO::PARAM_'.strtoupper($parts[0])) : \PDO::PARAM_STR;
return ($this->default === NULL ? 'NULL' :
$this->db->quote(htmlspecialchars($this->default, ENT_QUOTES,
$this->f3->get('ENCODING')), $pdo_type));
\Base::instance()->get('ENCODING')), $pdo_type));
}
}
}


class DB_Utils {
trait DB_Utils {

/** @var \DB\SQL */
protected $db;

/** @var \BASE */
protected $f3;

const
TEXT_ENGINE_NOT_SUPPORTED = 'DB Engine `%s` is not supported for this action.';
public $db;

/**
* parse command array and return backend specific query
Expand All @@ -1308,11 +1302,6 @@ public function findQuery($cmd) {
foreach ($cmd as $backend => $val)
if (preg_match('/'.$backend.'/', $this->db->driver()))
return $val;
trigger_error(sprintf(self::TEXT_ENGINE_NOT_SUPPORTED, $this->db->driver()),E_USER_ERROR);
}

public function __construct(SQL $db) {
$this->db = $db;
$this->f3 = \Base::instance();
trigger_error(sprintf('DB Engine `%s` is not supported for this action.', $this->db->driver()),E_USER_ERROR);
}
}
9 changes: 8 additions & 1 deletion app/main/controller/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


use Controller\Ccp\Sso;
use lib\Config;
use Model\CharacterModel;
use Model\CorporationModel;
use lib\Config;
use Model\MapModel;
use Model\RoleModel;

Expand Down Expand Up @@ -421,6 +421,13 @@ protected function initMaps(\Base $f3, CharacterModel $character){
}

$f3->set('tplMaps', $data);

if( !isset($data->corpMaps) ){
$f3->set('tplNotification', $this->getNotificationObject('No maps found',
'Only corporation maps could get loaded' ,
'info'
));
}
}

/**
Expand Down
18 changes: 3 additions & 15 deletions app/main/controller/api/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,12 @@ public function save(\Base $f3){
$connection = Model\BasicModel::getNew('ConnectionModel');
$connection->getById( (int)$connectionData['id'] );

// search if systems are neighbors
$routeController = new Route();
$routeController->initJumpData();
$route = $routeController->findRoute($connectionData['sourceName'], $connectionData['targetName'], 1);

if($route['routePossible'] == true){
// systems are next to each other
$connectionData['scope'] = 'stargate';
$connectionData['type'] = ['stargate'];
}elseif($connectionData['scope'] == 'stargate'){
// connection scope changed -> this can not be a stargate
$connectionData['scope'] = 'wh';
$connectionData['type'] = ['wh_fresh'];
}
$connectionData['mapId'] = $map;

$connection->setData($connectionData);

// change the default type for the new connection
$connection->setDefaultTypeData();

if($connection->save($activeCharacter)){
$return->connectionData = $connection->getData();

Expand Down
Loading

0 comments on commit d1a5aa0

Please sign in to comment.