- new import for static "region"/"constellation" universe data #515
- refactored DB connection handling - removed build.js (RequireJs is now handled by Gulp task)
This commit is contained in:
@@ -11,7 +11,6 @@ use Controller;
|
||||
use controller\MailController;
|
||||
use Model;
|
||||
use Exception;
|
||||
use DB;
|
||||
|
||||
class User extends Controller\Controller{
|
||||
|
||||
|
||||
93
app/main/controller/ccp/universe.php
Normal file
93
app/main/controller/ccp/universe.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: exodu
|
||||
* Date: 29.07.2017
|
||||
* Time: 11:31
|
||||
*/
|
||||
|
||||
namespace Controller\Ccp;
|
||||
|
||||
|
||||
use Controller\Controller;
|
||||
use Model\BasicModel;
|
||||
|
||||
class Universe extends Controller {
|
||||
|
||||
/**
|
||||
* Set up "Universe" Database
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function setupDB(\Base $f3){
|
||||
$this->setupRegions($f3);
|
||||
$this->setupConstellations($f3);
|
||||
}
|
||||
|
||||
/**
|
||||
* get all regions from CCP and store region data
|
||||
* @param \Base $f3
|
||||
*/
|
||||
private function setupRegions(\Base $f3){
|
||||
$this->getDB('UNIVERSE');
|
||||
$regionIds = $f3->ccpClient->getRegions();
|
||||
$regionModel = BasicModel::getNew('Universe\RegionModel');
|
||||
|
||||
foreach($regionIds as $regionId){
|
||||
$regionModel->getById($regionId);
|
||||
|
||||
if($regionModel->dry()){
|
||||
$regionData = $f3->ccpClient->getRegionData($regionId);
|
||||
if( !empty($regionData) ){
|
||||
$regionModel->copyfrom($regionData, ['id', 'name', 'description']);
|
||||
$regionModel->save();
|
||||
}
|
||||
}
|
||||
|
||||
$regionModel->reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get all constellations from CCP and store constellation data
|
||||
* @param \Base $f3
|
||||
*/
|
||||
private function setupConstellations(\Base $f3){
|
||||
$this->getDB('UNIVERSE');
|
||||
$constellationIds = $f3->ccpClient->getConstellations();
|
||||
$constellationModel = BasicModel::getNew('Universe\ConstellationModel');
|
||||
|
||||
foreach($constellationIds as $constellationId){
|
||||
$constellationModel->getById($constellationId);
|
||||
|
||||
if($constellationModel->dry()){
|
||||
$constellationData = $f3->ccpClient->getConstellationData($constellationId);
|
||||
|
||||
if( !empty($constellationData) ){
|
||||
// $constellationModel->copyfrom($constellationData, ['id', 'name', 'regionId']);
|
||||
$constellationModel->copyfrom($constellationData, function($fields){
|
||||
// add position coordinates as separate columns
|
||||
if(is_array($fields['position'])){
|
||||
$position = $fields['position'];
|
||||
if(
|
||||
isset($position['x']) &&
|
||||
isset($position['y']) &&
|
||||
isset($position['z'])
|
||||
){
|
||||
$fields['x'] = $position['x'];
|
||||
$fields['y'] = $position['y'];
|
||||
$fields['z'] = $position['z'];
|
||||
}
|
||||
}
|
||||
|
||||
// filter relevant data for insert
|
||||
return array_intersect_key($fields, array_flip(['id', 'name', 'regionId', 'x', 'y', 'z']));
|
||||
});
|
||||
|
||||
$constellationModel->save();
|
||||
}
|
||||
}
|
||||
|
||||
$constellationModel->reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class MapController extends AccessController {
|
||||
/**
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function init($f3) {
|
||||
public function init(\Base $f3) {
|
||||
$character = $this->getCharacter();
|
||||
|
||||
// page title
|
||||
|
||||
@@ -95,6 +95,15 @@ class Setup extends Controller {
|
||||
],
|
||||
'tables' => []
|
||||
],
|
||||
/* WIP ...
|
||||
'UNIVERSE' => [
|
||||
'info' => [],
|
||||
'models' => [
|
||||
'Model\Universe\RegionModel',
|
||||
'Model\Universe\ConstellationModel'
|
||||
],
|
||||
'tables' => []
|
||||
], */
|
||||
'CCP' => [
|
||||
'info' => [],
|
||||
'models' => [],
|
||||
@@ -596,8 +605,6 @@ class Setup extends Controller {
|
||||
foreach($this->databases as $dbKey => $dbData){
|
||||
|
||||
$dbLabel = '';
|
||||
$dbName = '';
|
||||
$dbUser = '';
|
||||
$dbConfig = [];
|
||||
|
||||
// DB connection status
|
||||
@@ -612,26 +619,25 @@ class Setup extends Controller {
|
||||
$dbColumnQueries = [];
|
||||
// tables that should exist in this DB
|
||||
$requiredTables = [];
|
||||
// get DB config
|
||||
$dbConfigValues = Config::getDatabaseConfig($dbKey);
|
||||
// check DB for valid connection
|
||||
$db = DB\Database::instance()->getDB($dbKey);
|
||||
|
||||
// check config that does NOT require a valid DB connection
|
||||
switch($dbKey){
|
||||
case 'PF':
|
||||
$dbLabel = 'Pathfinder';
|
||||
$dbName = Controller::getEnvironmentData('DB_NAME');
|
||||
$dbUser = Controller::getEnvironmentData('DB_USER');
|
||||
break;
|
||||
case 'CCP':
|
||||
$dbLabel = 'EVE-Online [SDE]';
|
||||
$dbName = Controller::getEnvironmentData('DB_CCP_NAME');
|
||||
$dbUser = Controller::getEnvironmentData('DB_CCP_USER');
|
||||
break;
|
||||
case 'PF': $dbLabel = 'Pathfinder'; break;
|
||||
case 'UNIVERSE': $dbLabel = 'EVE-Online universe'; break;
|
||||
case 'CCP': $dbLabel = 'EVE-Online [SDE]'; break;
|
||||
}
|
||||
|
||||
$dbName = $dbConfigValues['NAME'];
|
||||
$dbUser = $dbConfigValues['USER'];
|
||||
|
||||
if($db){
|
||||
switch($dbKey){
|
||||
case 'PF':
|
||||
case 'UNIVERSE':
|
||||
// enable (table) setup for this DB
|
||||
$dbSetupEnable = true;
|
||||
|
||||
@@ -854,10 +860,6 @@ class Setup extends Controller {
|
||||
$dbStatusCheckCount++;
|
||||
}
|
||||
|
||||
if($exec){
|
||||
$f3->reroute('@setup');
|
||||
}
|
||||
|
||||
if($dbStatusCheckCount !== 0){
|
||||
$this->databaseCheck = false;
|
||||
}
|
||||
@@ -880,6 +882,10 @@ class Setup extends Controller {
|
||||
];
|
||||
}
|
||||
|
||||
if($exec){
|
||||
$f3->reroute('@setup');
|
||||
}
|
||||
|
||||
return $this->databases;
|
||||
}
|
||||
|
||||
@@ -956,7 +962,7 @@ class Setup extends Controller {
|
||||
|
||||
// setup tables
|
||||
foreach($this->databases[$dbKey]['models'] as $modelClass){
|
||||
$checkTables[] = call_user_func($modelClass . '::setup');
|
||||
$checkTables[] = call_user_func($modelClass . '::setup', $db);
|
||||
}
|
||||
}
|
||||
return $checkTables;
|
||||
|
||||
Reference in New Issue
Block a user