/** * imports all relevant map stats from CCPs API * >> php index.php "/cron/importSystemData" * @param \Base $f3 */ function importSystemData($f3) { $time_start = microtime(true); // prepare system jump log table $systemsData = $this->prepareSystemLogTables(); $time_end = microtime(true); $execTimePrepareSystemLogTables = $time_end - $time_start; $pfDB = DB\Database::instance()->getDB('PF'); // get current jump Data ------------------------------------------------------- $time_start = microtime(true); $apiPath = Config::getEnvironmentData('CCP_XML') . '/map/Jumps.xml.aspx'; $apiResponse = \Web::instance()->request($apiPath, $this->apiRequestOptions); $jumpData = []; $updateJumps = false; if ($apiResponse['body']) { $xml = simplexml_load_string($apiResponse['body']); $rowApiData = $xml->result->rowset; foreach ($rowApiData->children() as $systemApiData) { $attributeApiData = $systemApiData->attributes(); $systemId = $attributeApiData->solarSystemID->__toString(); $shipJumps = $attributeApiData->shipJumps->__toString(); $jumpData[$systemId] = $shipJumps; } $updateJumps = true; } $time_end = microtime(true); $execTimeGetJumpData = $time_end - $time_start; // get current kill Data ------------------------------------------------------- $time_start = microtime(true); $apiPath = Config::getEnvironmentData('CCP_XML') . '/map/Kills.xml.aspx'; $apiResponse = \Web::instance()->request($apiPath, $this->apiRequestOptions); $killData = []; $updateKills = false; if ($apiResponse['body']) { $xml = simplexml_load_string($apiResponse['body']); $rowApiData = $xml->result->rowset; foreach ($rowApiData->children() as $systemApiData) { $attributeApiData = $systemApiData->attributes(); $systemId = $attributeApiData->solarSystemID->__toString(); $shipKills = $attributeApiData->shipKills->__toString(); $podKills = $attributeApiData->podKills->__toString(); $factionKills = $attributeApiData->factionKills->__toString(); $killData[$systemId] = ['shipKills' => $shipKills, 'podKills' => $podKills, 'factionKills' => $factionKills]; } $updateKills = true; } $time_end = microtime(true); $execTimeGetKillData = $time_end - $time_start; // update system log tables ----------------------------------------------------- $time_start = microtime(true); // make sure last update is (at least) 1h ago $pfDB->begin(); foreach ($this->logTables as $key => $tableName) { $sql = "UPDATE\n " . $tableName . "\n SET\n updated = now(),\n value24 = value23,\n value23 = value22,\n value22 = value21,\n value21 = value20,\n value20 = value19,\n value19 = value18,\n value18 = value17,\n value17 = value16,\n value16 = value15,\n value15 = value14,\n value14 = value13,\n value13 = value12,\n value12 = value11,\n value11 = value10,\n value10 = value9,\n value9 = value8,\n value8 = value7,\n value7 = value6,\n value6 = value5,\n value5 = value4,\n value4 = value3,\n value3 = value2,\n value2 = value1,\n value1 = :value\n WHERE\n systemId = :systemId\n "; foreach ($systemsData as $systemData) { if ($key == 'jumps' && $updateJumps) { // update jump data (if available) $currentJumps = 0; if (array_key_exists($systemData['systemId'], $jumpData)) { $currentJumps = $jumpData[$systemData['systemId']]; } $pfDB->exec($sql, array(':systemId' => $systemData['systemId'], ':value' => $currentJumps), 0, false); } else { if ($updateKills) { // update kill data (if available) $currentKills = 0; if (array_key_exists($systemData['systemId'], $killData)) { $currentKillData = $killData[$systemData['systemId']]; $currentKills = $currentKillData[$key]; } $pfDB->exec($sql, array(':systemId' => $systemData['systemId'], ':value' => $currentKills), 0, false); } } } } $pfDB->commit(); $time_end = microtime(true); $execTimeUpdateTables = $time_end - $time_start; // Log ------------------------ $log = new \Log('cron_' . __FUNCTION__ . '.log'); $log->write(sprintf(self::LOG_TEXT, __FUNCTION__, $execTimePrepareSystemLogTables, $execTimeGetJumpData, $execTimeGetKillData, $execTimeUpdateTables)); }
/** * get environment specific configuration data * @param string $key * @return string|null */ static function getEnvironmentData($key) { return Config::getEnvironmentData($key); }
/** * set environment information * @param \Base $f3 * @return array */ protected function getEnvironmentInformation(\Base $f3) { $environmentData = []; // exclude some sensitive data (e.g. database, passwords) $excludeVars = ['DB_DNS', 'DB_NAME', 'DB_USER', 'DB_PASS', 'DB_CCP_DNS', 'DB_CCP_NAME', 'DB_CCP_USER', 'DB_CCP_PASS']; // obscure some values $obscureVars = ['SSO_CCP_CLIENT_ID', 'SSO_CCP_SECRET_KEY', 'SMTP_PASS']; foreach ($this->environmentVars as $var) { if (!in_array($var, $excludeVars)) { $value = Config::getEnvironmentData($var); $check = true; if (is_null($value)) { // variable missing $check = false; $value = '[missing]'; } elseif (in_array($var, $obscureVars)) { $length = strlen($value); $hideChars = $length < 10 ? $length : 10; $value = substr_replace($value, str_repeat('.', 3), -$hideChars); $value .= ' [' . $length . ']'; } $environmentData[$var] = ['label' => $var, 'value' => empty($value) && !is_int($value) ? ' ' : $value, 'check' => $check]; } } return $environmentData; }