- removed SDE database requirement from Pathfinder, #628

- improved "shattered" wormholes (e.g. UI updates on map, fixed broken statics,..), closed #647
- improved "route search" algorithm, WHs are no longer supposed to be "insecure"
This commit is contained in:
Mark Friedrich
2018-06-30 13:19:12 +02:00
parent e65d2b8bc0
commit e7184b7312
32 changed files with 653 additions and 913 deletions

View File

@@ -138,11 +138,10 @@ class Map extends Controller\AccessController {
$return->connectionScopes = $connectionScopeData;
// get available wormhole types ---------------------------------------------------------------------------
$wormholes = Model\BasicModel::getNew('WormholeModel');
$rows = $wormholes->find('id > 0', null, $expireTimeSQL);
$wormhole = Model\Universe\BasicUniverseModel::getNew('WormholeModel');
$wormholesData = [];
if($rows){
foreach((array)$rows as $rowData){
if($rows = $wormhole->find(null, ['order' => 'name asc'], $expireTimeSQL)){
foreach($rows as $rowData){
$wormholesData[$rowData->name] = $rowData->getData();
}
}
@@ -741,12 +740,11 @@ class Map extends Controller\AccessController {
// system belongs to the current map
if(is_object($filteredMap->systems)){
// update
/**
* @var $system Model\SystemModel
*/
$system = $filteredMap->systems->current();
$system->setData($systemData);
$system->copyfrom($systemData, ['alias', 'status', 'position', 'locked', 'rallyUpdated', 'rallyPoke']);
if($system->save($activeCharacter)){
$mapChanged = true;
@@ -776,7 +774,6 @@ class Map extends Controller\AccessController {
// connection belongs to the current map
if(is_object($filteredMap->connections)){
// update
/**
* @var $connection Model\ConnectionModel
*/

View File

@@ -7,11 +7,12 @@
*/
namespace Controller\Api;
use Controller;
use Controller\Ccp\Universe;
use lib\Config;
use Model;
/**
* Routes controller
* Class Route
@@ -101,6 +102,7 @@ class Route extends Controller\AccessController {
* -> (e.g. new system added, connection added/updated, ...)
* @param array $mapIds
* @param array $filterData
* @throws \Exception
*/
private function setDynamicJumpData($mapIds = [], $filterData = []){
// make sure, mapIds are integers (protect against SQL injections)
@@ -177,7 +179,7 @@ class Route extends Controller\AccessController {
`system_src`.`systemId` systemId,
(
SELECT
GROUP_CONCAT( NULLIF(`system_tar`.`name`, NULL) SEPARATOR ':')
GROUP_CONCAT( NULLIF(`system_tar`.`systemId`, NULL) SEPARATOR ':')
FROM
`connection` INNER JOIN
`system` system_tar ON
@@ -211,6 +213,17 @@ class Route extends Controller\AccessController {
$rows = $this->getDB()->exec($query, null, $this->dynamicJumpDataCacheTime);
if(count($rows) > 0){
// enrich $row data with static system data (from universe DB)
$universe = new Universe();
for($i = 0; $i < count($rows); $i++){
if($staticData = $universe->getSystemData($rows[$i]['systemId'])){
$rows[$i]['systemName'] = $staticData->name;
$rows[$i]['constellationId'] = $staticData->constellation->id;
$rows[$i]['regionId'] = $staticData->constellation->region->id;
$rows[$i]['trueSec'] = $staticData->trueSec;
}
}
// update jump data for this instance
$this->updateJumpData($rows);
}
@@ -229,7 +242,7 @@ class Route extends Controller\AccessController {
foreach($rows as &$row){
$regionId = (int)$row['regionId'];
$constId = (int)$row['constellationId'];
$systemName = strtoupper($row['systemName']);
$systemName = (string)($row['systemName']);
$systemId = (int)$row['systemId'];
$secStatus = (float)$row['trueSec'];
@@ -242,19 +255,19 @@ class Route extends Controller\AccessController {
}
// fill "idArray" data ------------------------------------------------------------------------------------
if( !isset($this->idArray[$systemName]) ){
$this->idArray[$systemName] = $systemId;
if( !isset($this->idArray[$systemId]) ){
$this->idArray[$systemId] = $systemName;
}
// fill "jumpArray" data ----------------------------------------------------------------------------------
if( !is_array($this->jumpArray[$systemName]) ){
$this->jumpArray[$systemName] = [];
if( !is_array($this->jumpArray[$systemId]) ){
$this->jumpArray[$systemId] = [];
}
$this->jumpArray[$systemName] = array_merge( explode(':', strtoupper($row['jumpNodes'])), $this->jumpArray[$systemName] );
$this->jumpArray[$systemId] = array_merge(array_map('intval', explode(':', $row['jumpNodes'])), $this->jumpArray[$systemId]);
// add systemId to end (if not already there)
if(end($this->jumpArray[$systemName]) != $systemId){
array_push($this->jumpArray[$systemName],$systemId);
// add systemName to end (if not already there)
if(end($this->jumpArray[$systemId]) != $systemName){
array_push($this->jumpArray[$systemId], $systemName);
}
}
}
@@ -267,24 +280,23 @@ class Route extends Controller\AccessController {
private function filterJumpData($filterData = [], $keepSystems = []){
if($filterData['flag'] == 'secure'){
// remove all systems (TrueSec < 0.5) from search arrays
$this->jumpArray = array_filter($this->jumpArray, function($jumpData) use($keepSystems) {
// systemId is always last entry
$systemId = end($jumpData);
$this->jumpArray = array_filter($this->jumpArray, function($systemId) use($keepSystems) {
$systemNameData = $this->nameArray[$systemId];
$systemSec = $systemNameData[3];
if($systemSec < 0.45 && !in_array($systemId, $keepSystems)){
// remove system from nameArray as well
if(
$systemSec < 0.45 &&
!in_array($systemId, $keepSystems) &&
!preg_match('/^j\d+$/i', $this->idArray[$systemId]) // WHs are supposed to be "secure"
){
// remove system from nameArray and idArray
unset($this->nameArray[$systemId]);
// remove system from idArray as well
$systemName = $systemNameData[0];
unset($this->idArray[$systemName]);
unset($this->idArray[$systemId]);
return false;
}else{
return true;
}
});
}, ARRAY_FILTER_USE_KEY );
}
}
@@ -298,16 +310,16 @@ class Route extends Controller\AccessController {
$info = null;
switch($option){
case 'systemName':
$info = $this->nameArray[ $systemId ][0];
$info = $this->nameArray[$systemId][0];
break;
case 'regionId':
$info = $this->nameArray[ $systemId ][1];
$info = $this->nameArray[$systemId][1];
break;
case 'constellationId':
$info = $this->nameArray[ $systemId ][2];
$info = $this->nameArray[$systemId][2];
break;
case 'trueSec':
$info = $this->nameArray[ $systemId ][3];
$info = $this->nameArray[$systemId][3];
break;
}
@@ -387,13 +399,13 @@ class Route extends Controller\AccessController {
/**
* get formatted jump node data
* @param $systemName
* @param int $systemId
* @return array
*/
protected function getJumpNodeData($systemName) : array {
protected function getJumpNodeData(int $systemId) : array {
return [
'system' => $systemName,
'security' => $this->getSystemInfoBySystemId($this->idArray[$systemName], 'trueSec')
'system' => $this->getSystemInfoBySystemId($systemId, 'systemName'),
'security' => $this->getSystemInfoBySystemId($systemId, 'trueSec')
];
}
@@ -430,6 +442,7 @@ class Route extends Controller\AccessController {
* @param array $mapIds
* @param array $filterData
* @return array
* @throws \Exception
* @throws \Exception\PathfinderException
*/
private function searchRouteCustom(int $systemFromId, int $systemToId, $searchDepth = 0, array $mapIds = [], array $filterData = []) : array {
@@ -454,19 +467,16 @@ class Route extends Controller\AccessController {
// --> don´t filter some systems (e.g. systemFrom, systemTo) even if they are are WH,LS,0.0
$this->filterJumpData($filterData, [$systemFromId, $systemToId]);
$systemFrom = $this->getSystemInfoBySystemId($systemFromId, 'systemName');
$systemTo = $this->getSystemInfoBySystemId($systemToId, 'systemName');
// search route -------------------------------------------------------------------------------------------
// jump counter
$jumpNum = 0;
$depthSearched = 0;
if( isset($this->jumpArray[$systemFrom]) ){
if( isset($this->jumpArray[$systemFromId]) ){
// check if the system we are looking for is a direct neighbour
foreach( $this->jumpArray[$systemFrom] as $n ) {
if ($n == $systemTo) {
foreach( $this->jumpArray[$systemFromId] as $n ) {
if ($n == $systemToId) {
$jumpNum = 2;
$routeData['route'][] = $this->getJumpNodeData($n);
break;
@@ -475,11 +485,11 @@ class Route extends Controller\AccessController {
// system is not a direct neighbour -> search recursive its neighbours
if ($jumpNum == 0) {
$searchResult = $this->graph_find_path( $this->jumpArray, $systemFrom, $systemTo, $searchDepth );
$searchResult = $this->graph_find_path( $this->jumpArray, $systemFromId, $systemToId, $searchDepth );
$depthSearched = $searchResult['depth'];
foreach( $searchResult['path'] as $systemName ) {
foreach( $searchResult['path'] as $systemId ) {
if ($jumpNum > 0) {
$routeData['route'][] = $this->getJumpNodeData($systemName);
$routeData['route'][] = $this->getJumpNodeData($systemId);
}
$jumpNum++;
}
@@ -489,7 +499,7 @@ class Route extends Controller\AccessController {
// route found
$routeData['routePossible'] = true;
// insert "from" system on top
array_unshift($routeData['route'], $this->getJumpNodeData($systemFrom));
array_unshift($routeData['route'], $this->getJumpNodeData($systemFromId));
} else {
// route not found
$routeData['routePossible'] = false;
@@ -512,6 +522,7 @@ class Route extends Controller\AccessController {
* @param array $mapIds
* @param array $filterData
* @return array
* @throws \Exception
* @throws \Exception\PathfinderException
*/
private function searchRouteESI(int $systemFromId, int $systemToId, int $searchDepth = 0, array $mapIds = [], array $filterData = []) : array {
@@ -540,18 +551,16 @@ class Route extends Controller\AccessController {
$this->filterJumpData($filterData, [$systemFromId, $systemToId]);
$connections = [];
foreach($this->jumpArray as $systemSourceName => $jumpData){
foreach($this->jumpArray as $systemSourceId => $jumpData){
$count = count($jumpData);
if($count > 1){
// ... should always > 1
$systemSourceId = (int)$this->idArray[$systemSourceName];
// loop all connections for current source system
foreach($jumpData as $systemTargetName) {
foreach($jumpData as $systemTargetId) {
// skip last entry
if(--$count <= 0){
break;
}
$systemTargetId = (int)$this->idArray[$systemTargetName];
// systemIds exist and wer not removed before in filterJumpData()
if($systemSourceId && $systemTargetId){
@@ -599,8 +608,7 @@ class Route extends Controller\AccessController {
$this->setStaticJumpData();
foreach($result['route'] as $systemId){
$systemName = $this->getSystemInfoBySystemId($systemId, 'systemName');
$routeData['route'][] = $this->getJumpNodeData($systemName);
$routeData['route'][] = $this->getJumpNodeData($systemId);
}
}else{
$depthSearched = $routeData['maxDepth'];

View File

@@ -91,11 +91,11 @@ class Setup extends Controller\Controller {
$return->countBuildAll = $categoryUniverseModel->getById($categoryId, 0)->getTypesCount(false);
$return->progress = $percent($return->countAll, $return->countBuildAll);
break;
case 'SystemNeighbourModel':
case 'SystemNeighbour':
// Becomes deprecated with new Universe DB!!!
$this->setupSystemJumpTable();
$return->countAll = 5214;
$return->countAll = (int)$f3->get('REQUIREMENTS.DATA.NEIGHBOURS');
$return->countBuild = Database::instance()->getRowCount('system_neighbour');
$return->countBuildAll = $return->countBuild;
$return->progress = $percent($return->countAll, $return->countBuildAll);
@@ -144,67 +144,87 @@ class Setup extends Controller\Controller {
* for system jump calculation. Call this function manually when CCP adds Systems/Stargates
*/
protected function setupSystemJumpTable(){
$pfDB = $this->getDB('PF');
$ccpDB = $this->getDB('CCP');
$universeDB = $this->getDB('UNIVERSE');
$query = "SELECT
map_sys.solarSystemID system_id,
map_sys.regionID region_id,
map_sys.constellationID constellation_id,
map_sys.solarSystemName system_name,
ROUND( map_sys.security, 4) system_security,
(
SELECT
GROUP_CONCAT( NULLIF(map_sys_inner.solarSystemName, NULL) SEPARATOR ':')
`system`.`id` `systemId`,
`system`.`name` `systemName`,
`system`.`constellationId` `constellationId`,
ROUND( `system`.`securityStatus`, 4) `trueSec`,
`constellation`.`regionId` `regionId`,
(
SELECT
GROUP_CONCAT( NULLIF(`sys_inner`.`id`, NULL) SEPARATOR ':')
FROM
`stargate` INNER JOIN
`system` `sys_inner` ON
`sys_inner`.`id` = `stargate`.`destinationSystemId`
WHERE
`stargate`.`systemId` = `system`.`id`
) `jumpNodes`
FROM
mapSolarSystemJumps map_jump INNER JOIN
mapSolarSystems map_sys_inner ON
map_sys_inner.solarSystemID = map_jump.toSolarSystemID
`system` INNER JOIN
`constellation` ON
`constellation`.`id` = `system`.`constellationId`
WHERE
map_jump.fromSolarSystemID = map_sys.solarSystemID
) system_neighbours
FROM
mapSolarSystems map_sys
HAVING
-- skip systems without neighbors (e.g. WHs)
system_neighbours IS NOT NULL
";
`constellation`.`regionId` != :regionIdJove1 AND
`constellation`.`regionId` != :regionIdJove2 AND
`constellation`.`regionId` != :regionIdJove3 AND
(
`system`.`security` = :ns OR
`system`.`security` = :ls OR
`system`.`security` = :hs
)
";
$rows = $ccpDB->exec($query);
$rows = $universeDB->exec($query, [
':regionIdJove1' => 10000017,
':regionIdJove2' => 10000019,
':regionIdJove3' => 10000004,
':ns' => '0.0',
':ls' => 'L',
':hs' => 'H'
]);
if(count($rows) > 0){
// switch DB back to pathfinder DB
if(count($rows)){
$pfDB = $this->getDB('PF');
// clear cache table
$pfDB->exec("TRUNCATE system_neighbour");
foreach($rows as $row){
if(!$row['jumpNodes']){
// should never happen!
continue;
}
$pfDB->exec("
INSERT INTO
system_neighbour(
regionId,
constellationId,
systemName,
systemId,
jumpNodes,
trueSec
)
VALUES(
:regionId,
:constellationId,
:systemName,
:systemId,
:jumpNodes,
:trueSec
)",
[
':regionId' => $row['region_id'],
':constellationId' => $row['constellation_id'],
':systemName' => $row['system_name'],
':systemId' => $row['system_id'],
':jumpNodes' => $row['system_neighbours'],
':trueSec' => $row['system_security']
]);
INSERT INTO
system_neighbour(
regionId,
constellationId,
systemName,
systemId,
jumpNodes,
trueSec
)
VALUES(
:regionId,
:constellationId,
:systemName,
:systemId,
:jumpNodes,
:trueSec
)",
[
':regionId' => $row['regionId'],
':constellationId' => $row['constellationId'],
':systemName' => $row['systemName'],
':systemId' => $row['systemId'],
':jumpNodes' => $row['jumpNodes'],
':trueSec' => $row['trueSec']
]
);
}
}
}

View File

@@ -9,127 +9,10 @@
namespace Controller\Api;
use Controller;
use Data\Mapper as Mapper;
use Model;
class System extends Controller\AccessController {
private $mainQuery = "SELECT
map_sys.constellationID `connstallation_id`,
map_sys.solarSystemID `system_id`,
map_sys.solarSystemName `system_name`,
map_sys.security `system_security`,
map_con.constellationName `constallation_name`,
map_reg.regionID `region_id`,
map_reg.regionName `region_name`,
'0' `trueSec`,
'' `type`,
IFNULL(
(
SELECT
LOWER( system_effect.typeName )
FROM
invTypes system_effect INNER JOIN
mapDenormalize map_norm ON
map_norm.typeID = system_effect.typeID
WHERE
system_effect.groupID = 995 AND
map_norm.solarSystemID = map_sys.solarSystemID
LIMIT 1
), '') `effect`,
IFNULL(
(
SELECT
map_worm_class.wormholeClassID system_class
FROM
mapLocationWormholeClasses map_worm_class
WHERE
map_worm_class.locationID = map_sys.regionID
LIMIT 1
), 7) `security`
FROM
mapSolarSystems map_sys INNER JOIN
mapConstellations map_con ON
map_sys.constellationID = map_con.constellationID INNER JOIN
mapRegions map_reg ON
map_con.regionID = map_reg.regionID";
private $whereQuery = "";
// exclude Jove Space
private $havingQuery = "HAVING
security IS NOT NULL";
private $orderByQuery = "ORDER BY
system_name";
private $limitQuery = "";
/**
* build query
* @return string
*/
private function _getQuery(){
$query = $this->mainQuery;
$query .= ' ' . $this->whereQuery;
$query .= ' ' . $this->havingQuery;
$query .= ' ' . $this->orderByQuery;
$query .= ' ' . $this->limitQuery;
return $query;
}
/**
* get system Data from CCPs [SDE]
* search column for IDs can be (solarSystemID, regionID, constellationID)
* @param array $columnIDs
* @param string $column
* @return Model\SystemModel[]
* @throws \Exception
*/
public function getSystemModelByIds($columnIDs = [], $column = 'solarSystemID'){
$systemModels = [];
$ccpDB = $this->getDB('CCP');
$this->whereQuery = "WHERE
map_sys." . $column . " IN (" . implode(',', $columnIDs) . ")";
$query = $this->_getQuery();
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);
// format result
$ccpSystemsData = (new Mapper\CcpSystemsMapper($rows))->getData();
foreach($ccpSystemsData as $ccpSystemData){
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
$system->setData($ccpSystemData);
$systemModels[] = $system;
}
return $systemModels;
}
/**
* Get all static system Data from CCP DB (long cache timer)
* @return array
*/
public function getSystems(){
$ccpDB = $this->getDB('CCP');
$query = $this->_getQuery();
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);
// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
return $mapper->getData();
}
/**
* save a new system to a a map
* @param \Base $f3
@@ -160,59 +43,36 @@ class System extends Controller\AccessController {
}
if( isset($systemData['id']) ){
// update existing system (e.g. changed system description) -------------------------------------------
// update existing system (e.g. set description) ------------------------------------------------------
/**
* @var $system Model\SystemModel
*/
$system = Model\BasicModel::getNew('SystemModel');
$system->getById($systemData['id']);
if( !$system->dry() ){
if( $system->hasAccess($activeCharacter) ){
// system model found
$systemModel = $system;
}
if(
!$system->dry() &&
$system->hasAccess($activeCharacter)
){
// system model found
// activate system (e.g. was inactive))
$system->setActive(true);
$systemModel = $system;
}
}elseif( isset($mapData['id']) ){
// save NEW system ------------------------------------------------------------------------------------
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById($mapData['id']);
if( $map->hasAccess($activeCharacter) ){
// make sure system is not already on map
// --> (e.g. multiple simultaneously save() calls for the same system)
$systemModel = $map->getSystemByCCPId($systemData['systemId']);
if( is_null($systemModel) ){
// system not found on map -> get static system data (CCP DB)
$systemModel = $map->getNewSystem($systemData['systemId']);
$defaultStatusId = 1;
}else{
// system already exists (e.g. was inactive)
$defaultStatusId = $systemModel->statusId;
}
if( !is_null($systemModel) ){
$systemModel->statusId = isset($systemData['statusId']) ? $systemData['statusId'] : $defaultStatusId;
}
// map is not changeable for a system! (security)
$systemData['mapId'] = $map;
if($map->hasAccess($activeCharacter)){
$systemModel = $map->getNewSystem($systemData['systemId']);
}
}
if( !is_null($systemModel) ){
// "statusId" was set above
unset($systemData['statusId']);
unset($systemData['mapId']);
// set/update system
$systemModel->setData($systemData);
// activate system (e.g. was inactive))
$systemModel->setActive(true);
// set/update system custom data
$systemModel->copyfrom($systemData, ['locked', 'rallyUpdated', 'position', 'description']);
if($systemModel->save($activeCharacter)){
// get data from "fresh" model (e.g. some relational data has changed: "statusId")
@@ -220,7 +80,7 @@ class System extends Controller\AccessController {
* @var $newSystemModel Model\SystemModel
*/
$newSystemModel = Model\BasicModel::getNew('SystemModel');
$newSystemModel->getById( $systemModel->id, 0);
$newSystemModel->getById( $systemModel->_id, 0);
$newSystemModel->clearCacheData();
$return->systemData = $newSystemModel->getData();

View File

@@ -70,8 +70,8 @@ class Universe extends Controller\AccessController {
$filter = [
'id LIKE :id OR name LIKE :name',
':id' => $search . '%',
':name' => '%' . $search . '%'
':id' => $search . '%', // -> match first
':name' => '%' . $search . '%' // -> match between
];
$options = [
'order' => 'name',

View File

@@ -8,7 +8,6 @@
namespace Controller\Ccp;
use Controller\Controller;
use lib\Util;
use Model;
@@ -137,6 +136,8 @@ class Universe extends Controller {
return $return;
}
// system search index methods ====================================================================================
/**
* build search index from all systems data
* @param int $offset
@@ -144,7 +145,7 @@ class Universe extends Controller {
* @return array
* @throws \Exception
*/
public function buildSystemsIndex(int $offset = 0, int $length = 10){
public function buildSystemsIndex(int $offset = 0, int $length = 10) : array {
/**
* @var $system Model\Universe\SystemModel
*/
@@ -194,15 +195,26 @@ class Universe extends Controller {
/**
* look for existing systemData in index
* -> id is either a valid systemId OR systemName
* @param int|string $id
* -> if not exists -> try to build
* @param int $systemId
* @return null|\stdClass
* @throws \Exception
*/
protected function getSystemData($id){
public function getSystemData(int $systemId){
$data = null;
if($id){
$cacheKeyRow = Model\Universe\BasicUniverseModel::generateHashKeyRow('system', $id);
if($systemId){
// ...check index for data
$cacheKeyRow = Model\Universe\BasicUniverseModel::generateHashKeyRow('system', $systemId);
$data = $this->get($cacheKeyRow);
if(!$data){
// .. try to build index
/**
* @var $system Model\Universe\SystemModel
*/
$system = Model\Universe\BasicUniverseModel::getNew('SystemModel');
$system->getById($systemId);
$data = $system->buildIndex();
}
}
return $data;
}
@@ -212,7 +224,7 @@ class Universe extends Controller {
* @param string $cacheKey
* @return null|\stdClass
*/
protected function get(string $cacheKey){
private function get(string $cacheKey){
$data = null;
if($this->getF3()->exists($cacheKey,$value)) {
if(is_string($value) && strpos($value, Model\Universe\BasicUniverseModel::CACHE_KEY_PREFIX) === 0) {
@@ -230,7 +242,7 @@ class Universe extends Controller {
* clear cacheKey
* @param string $cacheKey
*/
protected function clear(string $cacheKey){
private function clear(string $cacheKey){
if($this->getF3()->exists($cacheKey,$value)) {
if(is_string($value) && strpos($value, Model\Universe\BasicUniverseModel::CACHE_KEY_PREFIX) === 0) {
// value references another cacheKey -> clear that one as well

View File

@@ -32,10 +32,10 @@ class Setup extends Controller {
'DB_PF_NAME',
'DB_PF_USER',
'DB_PF_PASS',
'DB_CCP_DNS',
'DB_CCP_NAME',
'DB_CCP_USER',
'DB_CCP_PASS',
'DB_UNIVERSE_DNS',
'DB_UNIVERSE_NAME',
'DB_UNIVERSE_USER',
'DB_UNIVERSE_PASS',
'CCP_SSO_URL',
'CCP_SSO_CLIENT_ID',
'CCP_SSO_SECRET_KEY',
@@ -102,8 +102,7 @@ class Setup extends Controller {
'Model\SystemPodKillModel',
'Model\SystemFactionKillModel',
'Model\SystemJumpModel'
],
'tables' => []
]
],
'UNIVERSE' => [
'info' => [],
@@ -112,30 +111,15 @@ class Setup extends Controller {
'Model\Universe\GroupModel',
'Model\Universe\CategoryModel',
'Model\Universe\StructureModel',
// 'Model\Universe\WormholeModel',
// 'Model\Universe\StargateModel',
// 'Model\Universe\StarModel',
// 'Model\Universe\PlanetModel',
// 'Model\Universe\SystemModel',
// 'Model\Universe\ConstellationModel',
// 'Model\Universe\RegionModel',
// 'Model\Universe\SystemStaticModel'
],
'tables' => []
],
'CCP' => [
'info' => [],
'models' => [],
'tables' => [
'invTypes',
'mapConstellations',
'mapDenormalize',
'mapLocationWormholeClasses',
'mapRegions',
'mapSolarSystemJumps',
'mapSolarSystems'
'Model\Universe\WormholeModel',
'Model\Universe\StargateModel',
'Model\Universe\StarModel',
'Model\Universe\PlanetModel',
'Model\Universe\SystemModel',
'Model\Universe\ConstellationModel',
'Model\Universe\RegionModel',
'Model\Universe\SystemStaticModel'
]
]
];
@@ -277,98 +261,6 @@ class Setup extends Controller {
$f3->set('cacheSize', $this->getCacheData($f3));
}
/**
* IMPORTANT: This function is not required for setup. It just imports *.json -> DB
*
* imports wormhole static data for "shattered" systems
* into table "system_wormhole"
* -> a *.csv dump of this *.json file can e found under /export/csv
* @param \Base $f3
* @throws \Exception
*/
protected function importSystemWormholesFromJson(\Base $f3){
$path = $f3->get('EXPORT') .'json/statics.json';
$pfDB = $this->getDB('PF');
$ccpDB = $this->getDB('CCP');
$content = file_get_contents($path);
$jsonIterator = new \RecursiveIteratorIterator(
new \RecursiveArrayIterator(json_decode($content, TRUE)),
\RecursiveIteratorIterator::SELF_FIRST);
$staticNames = [];
$data = [];
$tmpVal = (object) [];
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
if(isset($tmpVal->name)){
$data[] = $tmpVal;
}
$tmpVal = (object) [];
$tmpVal->name = $key;
} else {
$tmpVal->wh = isset($tmpVal->wh) ? array_merge($tmpVal->wh, [$val]) : [$val];
$staticNames[] = $val;
}
}
$data[] = $tmpVal;
// get static IDs by name ------------------------------
$staticNames = array_unique($staticNames);
$staticNames = array_flip($staticNames);
foreach($staticNames as $name => $index){
$result = $pfDB->exec("
SELECT
id
FROM " . $pfDB->quotekey(Model\BasicModel::getNew('WormholeModel')->getTable()) . "
WHERE " . $pfDB->quotekey('name') . " = :name",
[':name' => $name]
);
$id = (int)$result[0]['id'];
if($id){
$staticNames[$name] = (int)$result[0]['id'];
}else{
$f3->error(500, 'Wormhole data missing in table "wormhole" for "name" = "' . $name . '"');
}
}
// import data -----------------------------------------
$systemWormhole = Model\BasicModel::getNew('SystemWormholeModel');
foreach($data as $staticData){
$result = $ccpDB->exec("
SELECT
solarSystemID
FROM " . $ccpDB->quotekey('mapSolarSystems') . "
WHERE
" . $ccpDB->quotekey('solarSystemName') . " = :systemName",
[':systemName' => $staticData->name]
);
$solarSystemID = (int)$result[0]['solarSystemID'];
if($solarSystemID){
foreach($staticData->wh as $wh){
$staticId = (int)$staticNames[$wh];
if($staticId){
// check if entry already exists
$systemWormhole->load(['systemId=? AND wormholeId=?', $solarSystemID, $staticId]);
if( $systemWormhole->dry() ){
$systemWormhole->systemId = $solarSystemID;
$systemWormhole->wormholeId = $staticId;
$systemWormhole->save();
$systemWormhole->reset();
}
}else{
$f3->error(500, 'Wormhole data missing for "name" = "' . $wh . '"');
}
}
}else{
$f3->error(500, 'System "' . $staticData->name . '" not found on CCP´s [SDE] database');
}
}
}
/**
* set environment information
* @param \Base $f3
@@ -378,8 +270,8 @@ class Setup extends Controller {
$environmentData = [];
// exclude some sensitive data (e.g. database, passwords)
$excludeVars = [
'DB_PF_DNS', 'DB_PF_NAME', 'DB_PF_USER', 'DB_PF_PASS',
'DB_CCP_DNS', 'DB_CCP_NAME', 'DB_CCP_USER', 'DB_CCP_PASS'
'DB_PF_DNS', 'DB_PF_NAME', 'DB_PF_USER', 'DB_PF_PASS',
'DB_UNIVERSE_DNS', 'DB_UNIVERSE_NAME', 'DB_UNIVERSE_USER', 'DB_UNIVERSE_PASS'
];
// obscure some values
@@ -885,7 +777,6 @@ class Setup extends Controller {
switch($dbKey){
case 'PF': $dbLabel = 'Pathfinder'; break;
case 'UNIVERSE': $dbLabel = 'EVE-Online universe'; break;
case 'CCP': $dbLabel = 'EVE-Online [SDE]'; break;
}
$dbName = $dbConfigValues['NAME'];
@@ -912,15 +803,6 @@ class Setup extends Controller {
];
}
break;
case 'CCP':
// get table model from static table array
foreach($dbData['tables'] as $tableName){
$requiredTables[$tableName] = [
'exists' => false,
'empty' => true
];
}
break;
}
// db connect was successful
@@ -1352,14 +1234,10 @@ class Setup extends Controller {
// active DB and tables are required for obtain index data
if(!$this->databaseHasError){
$categoryUniverseModel = Model\Universe\BasicUniverseModel::getNew('CategoryModel');
//$systemUniverseModel = Model\Universe\BasicUniverseModel::getNew('SystemModel');
$systemUniverseModel = Model\Universe\BasicUniverseModel::getNew('SystemModel');
$systemNeighbourModel = Model\BasicModel::getNew('SystemNeighbourModel');
$wormholeModel = Model\BasicModel::getNew('WormholeModel');
$systemWormholeModel = Model\BasicModel::getNew('SystemWormholeModel');
$constellationWormholeModel = Model\BasicModel::getNew('ConstellationWormholeModel');
$indexInfo = [
/*
'Systems' => [
'task' => [
[
@@ -1378,7 +1256,7 @@ class Setup extends Controller {
'countBuild' => count((new Universe())->getSystemsIndex()),
'countAll' => $this->dbLib->getRowCount($systemUniverseModel->getTable(), 'UNIVERSE'),
'tooltip' => 'build up a static search index over all systems found on DB. Do not refresh page until import is complete (check progress)! Runtime: ~5min'
], */
],
'Structures' => [
'task' => [
[
@@ -1392,7 +1270,7 @@ class Setup extends Controller {
'countBuild' => $categoryUniverseModel->getById(65, 0)->getTypesCount(false),
'countAll' => (int)$f3->get('REQUIREMENTS.DATA.STRUCTURES'),
'tooltip' => 'import all structure types (e.g. Citadels) from ESI. Runtime: ~15s'
], /*
],
'Ships' => [
'task' => [
[
@@ -1406,9 +1284,8 @@ class Setup extends Controller {
'countBuild' => $categoryUniverseModel->getById(6, 0)->getTypesCount(false),
'countAll' => (int)$f3->get('REQUIREMENTS.DATA.SHIPS'),
'tooltip' => 'import all ships types from ESI. Runtime: ~2min'
], */
// All following rows become deprecated
'SystemNeighbourModel' => [
],
'SystemNeighbour' => [
'task' => [
[
'action' => 'buildIndex',
@@ -1417,10 +1294,14 @@ class Setup extends Controller {
'btn' => 'btn-primary'
]
],
'label' => 'system_neighbour',
'label' => 'build neighbour index',
'countBuild' => $this->dbLib->getRowCount($systemNeighbourModel->getTable()),
'countAll' => 5214
'countAll' => (int)$f3->get('REQUIREMENTS.DATA.NEIGHBOURS'),
'tooltip' => 'build up a static search index for route search. This is used as fallback in case ESI is down. Runtime: ~30s'
],
// All following rows become deprecated
/*
'WormholeModel' => [
'task' => [
[
@@ -1438,53 +1319,18 @@ class Setup extends Controller {
'label' => 'wormhole',
'countBuild' => $this->dbLib->getRowCount($wormholeModel->getTable()),
'countAll' => 89
],
'SystemWormholeModel' => [
'task' => [
[
'action' => 'exportTable',
'label' => 'Export',
'icon' => 'fa-download',
'btn' => 'btn-default'
],[
'action' => 'importTable',
'label' => 'Import',
'icon' => 'fa-upload',
'btn' => 'btn-primary'
]
],
'label' => 'system_wormhole',
'countBuild' => $this->dbLib->getRowCount($systemWormholeModel->getTable()),
'countAll' => 234
],
'ConstellationWormholeModel' => [
'task' => [
[
'action' => 'exportTable',
'label' => 'Export',
'icon' => 'fa-download',
'btn' => 'btn-default'
],[
'action' => 'importTable',
'label' => 'Import',
'icon' => 'fa-upload',
'btn' => 'btn-primary'
]
],
'label' => 'constellation_wormhole',
'countBuild' => $this->dbLib->getRowCount( $constellationWormholeModel->getTable() ),
'countAll' => 461
]
*/
];
}else{
$indexInfo = [
'SystemNeighbourModel' => [
'SystemNeighbour' => [
'task' => [],
'label' => 'Fix database errors first!'
]
];
}
//var_dump($indexInfo); die();
return $indexInfo;
}