Skip to content

Commit

Permalink
Merge pull request #64 from exodus4d/develop
Browse files Browse the repository at this point in the history
v0.0.15
  • Loading branch information
exodus4d committed Nov 11, 2015
2 parents 167f9ad + 02ec50d commit 1f19783
Show file tree
Hide file tree
Showing 53 changed files with 806 additions and 201 deletions.
7 changes: 5 additions & 2 deletions app/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ DEBUG = 0
; If TRUE, the framework, after having logged stack trace and errors, stops execution (die without any status) when a non-fatal error is detected.
HALT = FALSE

ONERROR = "Controller\Controller->showError"

; Timezone to use. Sync program with eve server time
TZ = "UTC"

; Cache backend. Can handle Memcache module, APC, WinCache, XCache and a filesystem-based cache.
CACHE = TRUE

; Callback functions ===================================================================================
ONERROR = "Controller\Controller->showError"

UNLOAD = "Controller\Controller->unload"

; Path configurations ==================================================================================
; relative to "BASE" dir

Expand Down
147 changes: 140 additions & 7 deletions app/main/controller/api/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,139 @@ public function init($f3){
echo json_encode($initData);
}

/**
* import new map data
* @param $f3
*/
public function import($f3){
$importData = (array)$f3->get('POST');

$return = (object) [];
$return->error = [];

if(
isset($importData['typeId']) &&
count($importData['mapData']) > 0
){
$user = $this->_getUser();

if($user){
$activeCharacter = $user->getActiveUserCharacter();

$map = Model\BasicModel::getNew('MapModel');
$system = Model\BasicModel::getNew('SystemModel');
$connection = Model\BasicModel::getNew('ConnectionModel');

foreach($importData['mapData'] as $mapData){
if(
isset($mapData['config']) &&
isset($mapData['data'])
){


if(
isset($mapData['data']['systems']) &&
isset($mapData['data']['connections'])
){
if(isset($mapData['config']['id'])){
unset($mapData['config']['id']);
}

$map->setData($mapData['config']);
$map->typeId = (int)$importData['typeId'];
$map->save();

// new system IDs will be generated
// therefore we need to temp store a mapping between IDs
$tempSystemIdMapping = [];

foreach($mapData['data']['systems'] as $systemData){
if(isset($systemData['id'])){
$oldId = (int)$systemData['id'];
unset($systemData['id']);

$system->setData($systemData);
$system->mapId = $map;
$system->createdCharacterId = $activeCharacter->characterId;
$system->updatedCharacterId = $activeCharacter->characterId;
$system->save();

$tempSystemIdMapping[$oldId] = $system->id;
$system->reset();
}
}


foreach($mapData['data']['connections'] as $connectionData){
// check if source and target IDs match with new system ID
if(
isset( $tempSystemIdMapping[$connectionData['source']] ) &&
isset( $tempSystemIdMapping[$connectionData['target']] )
){
if(isset($connectionData['id'])){
unset($connectionData['id']);
}

$connection->setData($connectionData);
$connection->mapId = $map;
$connection->source = $tempSystemIdMapping[$connectionData['source']];
$connection->target = $tempSystemIdMapping[$connectionData['target']];
$connection->save();

$connection->reset();
}
}

// map access info should not automatically imported
if($map->isPrivate()){
$map->setAccess($user);
}elseif($map->isCorporation()){
$corporation = $activeCharacter->getCharacter()->getCorporation();
if($corporation){
$map->setAccess($corporation);
}
}elseif($map->isAlliance()){
$alliance = $activeCharacter->getCharacter()->getAlliance();
if($alliance){
$map->setAccess($alliance);
}
}

}else{
// systems || connections missing
$missingConfigError = (object) [];
$missingConfigError->type = 'error';
$missingConfigError->message = 'Map data not valid (systems || connections) missing';
$return->error[] = $missingConfigError;
}

}else{
// map config || systems/connections missing
$missingConfigError = (object) [];
$missingConfigError->type = 'error';
$missingConfigError->message = 'Map data not valid (config || data) missing';
$return->error[] = $missingConfigError;
}


$map->reset();
}
}else{
// user not found
$return->error[] = $this->getUserLoggedOffError();
}
}else{
// map data missing
$missingDataError = (object) [];
$missingDataError->type = 'error';
$missingDataError->message = 'Map data missing';
$return->error[] = $missingDataError;
}


echo json_encode($return);
}

/**
* save a new map or update an existing map
* @param $f3
Expand Down Expand Up @@ -337,7 +470,7 @@ public function updateData($f3){
$return->error = [];

if($user){
// -> get active user object
// -> get active character
$activeCharacter = $user->getActiveUserCharacter();

$cacheKey = 'user_map_data_' . $activeCharacter->id;
Expand Down Expand Up @@ -383,10 +516,10 @@ public function updateData($f3){
foreach($systems as $i => $systemData){

// check if current system belongs to the current map
$map->filter('systems', array('id = ?', $systemData['id'] ));
$map->filter('systems', ['id = ?', $systemData['id'] ]);
$filteredMap = $map->find(
array('id = ?', $map->id ),
array('limit' => 1)
['id = ?', $map->id ],
['limit' => 1]
);

// this should never fail
Expand All @@ -412,10 +545,10 @@ public function updateData($f3){
foreach($connections as $i => $connectionData){

// check if the current connection belongs to the current map
$map->filter('connections', array('id = ?', $connectionData['id'] ));
$map->filter('connections', ['id = ?', $connectionData['id'] ]);
$filteredMap = $map->find(
array('id = ?', $map->id ),
array('limit' => 1)
['id = ?', $map->id ],
['limit' => 1]
);

// this should never fail
Expand Down
6 changes: 3 additions & 3 deletions app/main/controller/api/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ private function setupSystemJumpTable(){
SELECT
GROUP_CONCAT( NULLIF(map_sys_inner.solarSystemName, NULL) SEPARATOR ':')
FROM
mapsolarsystemjumps map_jump INNER JOIN
mapsolarsystems map_sys_inner ON
mapSolarSystemJumps map_jump INNER JOIN
mapSolarSystems map_sys_inner ON
map_sys_inner.solarSystemID = map_jump.toSolarSystemID
WHERE
map_jump.fromSolarSystemID = map_sys.solarSystemID
) system_neighbours
FROM
mapsolarsystems map_sys
mapSolarSystems map_sys
HAVING
-- skip systems without neighbors (e.g. WHs)
system_neighbours IS NOT NULL
Expand Down
12 changes: 6 additions & 6 deletions app/main/controller/api/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class System extends \Controller\AccessController {
SELECT
LOWER( system_effect.typeName )
FROM
invtypes system_effect INNER JOIN
mapdenormalize map_norm ON
invTypes system_effect INNER JOIN
mapDenormalize map_norm ON
map_norm.typeID = system_effect.typeID
WHERE
system_effect.groupID = 995 AND
Expand All @@ -39,16 +39,16 @@ class System extends \Controller\AccessController {
SELECT
map_worm_class.wormholeClassID system_class
FROM
maplocationwormholeclasses map_worm_class
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
mapSolarSystems map_sys INNER JOIN
mapConstellations map_con ON
map_con.constellationID = map_sys.constellationID INNER JOIN
mapregions map_reg ON
mapRegions map_reg ON
map_reg.regionID = map_sys.regionID";

private $whereQuery = "";
Expand Down
44 changes: 40 additions & 4 deletions app/main/controller/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static function getIGBHeaderData(){
$data = (object) [];
$data->trusted = false;
$data->values = [];
$headerData = apache_request_headers();
$headerData = self::getRequestHeaders();

foreach($headerData as $key => $value){
$key = strtolower($key);
Expand All @@ -199,6 +199,33 @@ static function getIGBHeaderData(){
return $data;
}

/**
* Helper function to return all headers because
* getallheaders() is not available under nginx
*
* @return array (string $key -> string $value)
*/
static function getRequestHeaders(){
$headers = [];

if(function_exists('apache_request_headers') ){
// Apache Webserver
$headers = apache_request_headers();
}else{
// Other webserver, e.g. nginx
// Unfortunately this "fallback" does not work for me (Apache)
// Therefore we can´t use this for all servers
// https://github.com/exodus4d/pathfinder/issues/58
foreach($_SERVER as $name => $value){
if(substr($name, 0, 5) == 'HTTP_'){
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
}

return $headers;
}

/**
* check if the current request was send from inGame
* @return bool
Expand Down Expand Up @@ -282,8 +309,9 @@ static function getEnvironmentData($key){
public function showError($f3){

// set HTTP status
if(!empty($f3->get('ERROR.code'))){
$f3->status($f3->get('ERROR.code'));
$errorCode = $f3->get('ERROR.code');
if(!empty($errorCode)){
$f3->status($errorCode);
}

if($f3->get('AJAX')){
Expand All @@ -293,7 +321,7 @@ public function showError($f3){
$return = (object) [];
$error = (object) [];
$error->type = 'error';
$error->code = $f3->get('ERROR.code');
$error->code = $errorCode;
$error->status = $f3->get('ERROR.status');
$error->message = $f3->get('ERROR.text');

Expand Down Expand Up @@ -322,4 +350,12 @@ public function showError($f3){
die();
}

/**
* Callback for framework "unload"
* -> config.ini
*/
public function unload(){

}

}
4 changes: 3 additions & 1 deletion app/main/cron/characterupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class CharacterUpdate {
*/
function deleteLogData($f3){

$characterLogModel = Model\BasicModel::getNew('CharacterLogModel');
DB\Database::instance()->getDB('PF');

$characterLogModel = Model\BasicModel::getNew('CharacterLogModel', 0);

// find "old" character logs
$characterLogs = $characterLogModel->find([
Expand Down
3 changes: 1 addition & 2 deletions app/main/model/basicmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public function set($key, $val){
}
}


/**
* extent the fieldConf Array with static fields for each table
*/
Expand All @@ -128,7 +127,7 @@ private function addStaticFieldConfig(){
'type' => Schema::DT_TIMESTAMP
],
'updated' => [
'type' => Schema::DT_TIMESTAMP
'type' => Schema::DF_CURRENT_TIMESTAMP
]
];

Expand Down
Loading

0 comments on commit 1f19783

Please sign in to comment.