Files
pathfinder/app/main/db/database.php
Mark Friedrich 5c1cdca936 v1.1.2 (#270)
* fixed #194 PHP 5.6 error

* - closed #102 added "set waypoint/destination" context menu to route finder module
- update "Select2" 4.0.0 -> 4.0.3
- update "Font Awesome" 4.6.1 -> 4.6.3

* - added *.js files for develop branch

* - closed #195 fixed "BASE" dir for subDir installations
- fixed "Home" menu link

* -  #195 improved js load path

* - added "clear cache" function for manually cache clearing to /setup #200 #105 #158
- added cache size information to /setup
- added current pathfinder  "VERSION" to /setup
- updated "requireJs" 2.1.20 ->2.2.0
- removed unnecessary page cache timings from static templates (page cache)

* - added "document_root", "port", "protocol" and "PHP framework version" to /setup page
- added new "shattered" wormhole types to "signature table", closed #182, #179

* - added new "delete old signatures" option to "signature reader" dialog, closed #95

* - added new housekeeping cronjob für cached files, closed #200
- added new cache size information to /setup page

* - fixed signature groupId/typeId "overwriting" for already known signatures. closed #207
- improved system search dialog. Added trim(); before "api/signatures-> search" request

* updated README.me

* fixed PHP error "default object from empty value", closed #209

* reduced image file size

* - added local storage (IndexedDB)
- added local storage for map scroll position. closed #69

* - added "notice" panel for upcoming release information
- improved layout for "release dialog" (GitHub API)
- improved pagespeed (removed render blocking javascripts)
- improved map scrollbar configuration
- improved Chrome browser custom scrollbar layout
- removed "sign up" buttons from "map panels", closed #214

* - fixed some session and cookie  bugs

* - added new requirement check for `max_input_vars` to /setup URL, closed #224

* - fixed isWormhole(); bug

* -v1.1.1 added js build files

* - removed IGB support #206
- removed location tracking by IGB

* - added build files for upcoming version 1.1.2
- improved ajax authentication check and "logout" notification | closed #198
- improved logging, added missing log file configuration to pathfinder.ini
- added  logging for "unauthorized" requests | closed #198
- updated js "jQuery" 1.11.3 -> 3.0.0 | #206
- updated js "datatables" plugin 1.10.7 -> 1.10.12 | #206
- updated js "mCustomScrollbar" 3.1.14 -> 3.1.4 | #206

* - fixed some minor bugs in signature table module

* - fixed type "Cataclysmic", closed #241

* - added new setup DB indexing for "system_neighbour"  table to /setup route, #125
- fixed system "TrueSec" rounding in "routes module", closed #109

* - fixed system "TrueSec" rounding in "routes module", closed #109

* - added new wormhole statics for "Thera", closed #240

* - fixed missing statics for constellation "21000062" , closed #232

* - added "static" wormholes for "shattered" systems , closed #180
- added im/export function for "index" tables (*.csv import), as an alternative to the *.sql import, closed #125

* - added new system tooltip for "region name", closed #236
- updated "Bootstrap" JS-library 3.3.0 -> 3.3.5

* - removed console.log(),,,

* minor bugfixes in /setup page

* - added basic support for Russian signatures, closed #256
- added warning notification for invalid signature stings

* - added basic support for Russian signatures, closed #256

* - added requirement check for "PDO", "PDO_MYSQL" to "/setup" route
- imrpved DB PDO connection (added "TIMEOUT", forced "ERRMODE")
- fixed broken "system alias" renaming dialog

* - fixed "system graph" module rendering if there was no data available
- improved "image gallery" initialization on landing page
- added navigation to /setup page
- updated "blueImpGallery" (fixed some bugs after jQuery 3.0 upgrade) 1.15.2 -> 2.21.3
- updated "blueImpGalleryBootstrap"  (fixed some bugs after jQuery 3.0 upgrade)  3.1.1 -> 3.4.2

* - JS build files vor 1.1.2

* Updated pathfinder.css
2016-07-29 20:19:17 +02:00

174 lines
4.7 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: exodus4d
* Date: 30.07.2015
* Time: 15:55
*/
namespace DB;
use Controller;
use controller\LogController;
class Database extends \Prefab {
function __construct($database = 'PF'){
// set database
$this->setDB($database);
}
/**
* set database
* @param string $database
* @return SQL
*/
public function setDB($database = 'PF'){
$f3 = \Base::instance();
// "Hive" Key for DB storage
$dbHiveKey = $this->getDbHiveKey($database);
// check if DB connection already exists
if( !$f3->exists( $dbHiveKey ) ){
if($database === 'CCP'){
// CCP DB
$dns = Controller\Controller::getEnvironmentData('DB_CCP_DNS');
$name = Controller\Controller::getEnvironmentData('DB_CCP_NAME');
$user = Controller\Controller::getEnvironmentData('DB_CCP_USER');
$password = Controller\Controller::getEnvironmentData('DB_CCP_PASS');
}else{
// Pathfinder(PF) DB
$dns = Controller\Controller::getEnvironmentData('DB_DNS');
$name = Controller\Controller::getEnvironmentData('DB_NAME');
$user = Controller\Controller::getEnvironmentData('DB_USER');
$password = Controller\Controller::getEnvironmentData('DB_PASS');
}
$db = $this->connect($dns, $name, $user, $password);
if( !is_null($db) ){
// set DB timezone to UTC +00:00 (eve server time)
$db->exec('SET @@session.time_zone = "+00:00";');
// set default storage engine
$db->exec('SET @@session.default_storage_engine = "' .
Controller\Controller::getRequiredMySqlVariables('DEFAULT_STORAGE_ENGINE') . '"');
// store DB object
$f3->set($dbHiveKey, $db);
}
return $db;
}else{
return $f3->get( $dbHiveKey );
}
}
/**
* get database
* @param string $database
* @return SQL
*/
public function getDB($database = 'PF'){
$f3 = \Base::instance();
$dbHiveKey = $this->getDbHiveKey($database);
if( $f3->exists( $dbHiveKey ) ){
return $f3->get( $dbHiveKey );
}else{
return $this->setDB($database);
}
}
/**
* get a unique hive key for each DB connection
* @param $database
* @return string
*/
protected function getDbHiveKey($database){
return 'DB_' . $database;
}
/**
* connect to a database
* @param $dns
* @param $name
* @param $user
* @param $password
* @return SQL
*/
protected function connect($dns, $name, $user, $password){
$db = null;
try {
$db = new SQL(
$dns . $name,
$user,
$password,
[
\PDO::MYSQL_ATTR_COMPRESS => true,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_TIMEOUT => \Base::instance()->get('REQUIREMENTS.MYSQL.PDO_TIMEOUT'),
]
);
}catch(\PDOException $e){
// DB connection error
// -> log it
self::getLogger()->write($e->getMessage());
}
return $db;
}
/**
* get all table names from a DB
* @param string $database
* @return array|bool
*/
public function getTables($database = 'PF'){
$schema = new SQL\Schema( $this->getDB($database) );
return $schema->getTables();
}
/**
* checks whether a table exists on a DB or not
* @param $table
* @param string $database
* @return bool
*/
public function tableExists($table, $database = 'PF'){
$tableNames = $this->getTables($database);
return in_array($table, $tableNames);
}
/**
* get current row (data) count for an existing table
* -> returns 0 if table not exists or empty
* @param $table
* @param string $database
* @return int
*/
public function getRowCount($table, $database = 'PF') {
$count = 0;
if( $this->tableExists($table, $database) ){
$db = $this->getDB($database);
$countRes = $db->exec("SELECT COUNT(*) `num` FROM " . $db->quotekey($table));
if(isset($countRes[0]['num'])){
$count = (int)$countRes[0]['num'];
}
}
return $count;
}
/**
* get logger for DB logging
* @return \Log
*/
static function getLogger(){
return LogController::getLogger('ERROR');
}
}