Skip to content

Commit

Permalink
Merge pull request #172 from uplink42/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
uplink42 authored Apr 29, 2017
2 parents 4b178ab + dbd87d2 commit 24b3659
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 103 deletions.
1 change: 1 addition & 0 deletions application/controllers/Apikeymanagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct()
*/
public function index($character_id)
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
settype($character_id, 'int');
if ($this->enforce($character_id, $this->user_id)) {

Expand Down
1 change: 1 addition & 0 deletions application/controllers/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct()
*/
public function index($character_id, $region_id = 0) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $this->user_id)) {
$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $this->user_id, $aggregate);
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Citadeltax.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct()
*/
public function index($character_id) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $user_id = $this->user_id)) {
$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $user_id, $aggregate);
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Contracts.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function __construct()
*/
public function index($character_id) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $user_id = $this->user_id)) {
$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $user_id, $aggregate);
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct()
*/
public function index($character_id, $interval = 1) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($interval > 7) {
$interval = 7;
}
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Marketexplorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct()
*/
public function index($character_id) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $this->user_id)) {
$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $this->user_id, $aggregate);
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Marketorders.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct()
*/
public function index($character_id) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $user_id = $this->user_id)) {
$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $this->user_id, $aggregate);
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Networthtracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct()
*/
public function index($character_id, $interval = 7) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($interval > 365) {
$interval = 365;
}
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Profits.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct()
*/
public function index($character_id, $item_id = null) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
$interval = 7;
if ($this->enforce($character_id, $this->user_id)) {
$aggregate = $this->aggregate;
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct()
*/
public function index($character_id) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $this->user_id)) {
$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $this->user_id, $aggregate);
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct()
*/
public function index($character_id, $interval = 7) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($interval > 365) {
$interval = 365;
}
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/Stocklists.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function __construct()
*/
public function index($character_id) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $this->user_id)) {

$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $this->user_id, $aggregate);
$chars = $data['chars'];
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/Traderoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function __construct()
*/
public function index($character_id) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $this->user_id)) {

$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $this->user_id, $aggregate);

Expand Down
1 change: 1 addition & 0 deletions application/controllers/Tradesimulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct()
*/
public function index($character_id, $res = null) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($this->enforce($character_id, $this->user_id)) {
$aggregate = $this->aggregate;
$data = $this->loadViewDependencies($character_id, $this->user_id, $aggregate);
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct()
*/
public function index($character_id, $interval = 14) : void
{
$this->Log->addEntry("visit " . $this->page, $this->user_id);
if ($interval > 365) {
$interval = 365;
}
Expand Down
201 changes: 102 additions & 99 deletions application/controllers/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function index()
$this->Updater_model->init($username);
} catch (Throwable $e) {
$this->Updater_model->release($username);
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
log_message('error', $e->getMessage());
return;
}
Expand All @@ -47,111 +49,112 @@ public function index()
if (!$this->ValidateRequest->testEndpoint()) {
$this->removeDirectory(FILESTORAGE . 'public/public/server');
// forward user to offline mode
$this->Updater_model->release($username);
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
// check if user is already updating
} else {
if ($this->Updater_model->isLocked($username)) {
return;
}

// check if user is already updating
if ($this->Updater_model->isLocked($username)) {
$this->displayResultTable($username);
return;
}

// check if user has any keys
$keys = $this->Updater_model->getKeys($username);
if (count($keys) == 0) {
$this->Updater_model->release($username);
log_message('error', $username . ' has no keys');
// no keys, so prompt for new one
$this->askForKey();
return;
}

// validate existing keys
$keys_status = $this->Updater_model->processAPIKeys($keys, $username);
if (!$keys_status) {
$this->Updater_model->release($username);
log_message('error', 'Unable to connect to verify key status');
// unable to connect to verify keys
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
return;
}

foreach($keys_status as $key => $val) {
$invalid_keys = [];
if ($val < 1) {
array_push($invalid_keys, $key);
}

if (count($invalid_keys) > 0) {
$this->Updater_model->release($username);
log_message('error', 'Invalid Keys detected');
// invalid key
buildMessage('error', Msg::OFFLINE_MODE_NOTICE_KEY . ' ' . implode($invalid_keys, ','));
$this->displayResultTable($username);
return;
}
}

// begin update
$this->Updater_model->lock($username);
try {
$result_iterate = $this->Updater_model->iterateAccountCharacters();
if (!$result_iterate) {
$this->Updater_model->release($username);
log_message('error', $username . ' iterate failed');
// transaction failed for some reason
// forward user to offline mode
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
return;
}

// if we arrived here, that means nothing went wrong (yet)
$this->db->trans_start();
$this->load->model('Updater_profit_model', 'profits');
$this->profits->beginProfitCalculation($username);
// update totals and history
$this->Updater_model->updateTotals($username);
$this->db->trans_complete();

if ($this->db->trans_status() === false) {
$this->Updater_model->release($username);
// something went wrong while calculating profits, abort
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
} else {
// check if user has any keys
$keys = $this->Updater_model->getKeys($username);
if (count($keys) == 0) {
log_message('error', $username . ' has no keys');
// no keys, so prompt for new one
$this->askForKey();
return;
} else {
// validate existing keys
$keys_status = $this->Updater_model->processAPIKeys($keys, $username);
if (!$keys_status) {
log_message('error', 'Unable to connect to verify key status');
// unable to connect to verify keys
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
return;
}

foreach($keys_status as $key => $val) {
$invalid_keys = [];
if ($val < 1) {
array_push($invalid_keys, $key);
}

if (count($invalid_keys) > 0) {
log_message('error', 'Invalid Keys detected');
// invalid key
buildMessage('error', Msg::OFFLINE_MODE_NOTICE_KEY . ' ' . implode($invalid_keys, ','));
$this->displayResultTable($username);
return;
}
}

// begin update
$this->Updater_model->lock($username);
try {
$result_iterate = $this->Updater_model->iterateAccountCharacters();
if (!$result_iterate) {
log_message('error', $username . ' iterate failed');
// transaction failed for some reason
// forward user to offline mode
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
} else {
// if we arrived here, that means nothing went wrong (yet)
$this->db->trans_start();
$this->load->model('Updater_profit_model', 'profits');
$this->profits->beginProfitCalculation($username);
// update totals and history
$this->Updater_model->updateTotals($username);
$this->db->trans_complete();

if ($this->db->trans_status() === false) {
// something went wrong while calculating profits, abort
buildMessage('error', Msg::DB_ERROR);
$data['view'] = "login/login_v";
$data['no_header'] = 1;
$this->twig->display('main/_template_v', $data);
return;
} else {
// successfully updated
buildMessage('success', Msg::UPDATE_SUCCESS);
$this->displayResultTable($username);
$this->Updater_model->release($username);
}
}
} catch (Throwable $e) {
//if an exception happens during update (this is a bug on Eve's API)
log_message('error', $e->getMessage());
// cache is now corrupted for 24 hours, remove cached data
$problematicKeys = $this->Updater_model->getAPIKeys($this->user_id);
$this->Log->addEntry('clear', $this->user_id);

if (true) {
// todo: check error code?
foreach ($problematicKeys as $row) {
log_message('error', $username . ' deleting cache folder');
$key = $row->key;
$dir = FILESTORAGE . $key;
$this->removeDirectory($dir);
// release the lock
$this->Updater_model->release($username);

// forward user to offline mode
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
}
} else {
$this->etmsession->delete('username');
$this->etmsession->delete('start');
$this->etmsession->delete('iduser');
$this->twig->display('main/_template_v', $data);
}
}
}
return;
}

// successfully updated
buildMessage('success', Msg::UPDATE_SUCCESS);
$this->displayResultTable($username);
$this->Updater_model->release($username);

} catch (Throwable $e) {
// if an exception happens during update (this is a bug on Eve's API)
log_message('error', $e->getMessage());
// cache is now corrupted for 24 hours, remove cached data
$problematicKeys = $this->Updater_model->getAPIKeys($this->user_id);
$this->Log->addEntry('clear', $this->user_id);

// todo: check error code?
foreach ($problematicKeys as $row) {
log_message('error', $username . ' deleting cache folder');
$key = $row->key;
$dir = FILESTORAGE . $key;
$this->removeDirectory($dir);

$this->Updater_model->release($username);
// forward user to offline mode
buildMessage('error', Msg::OFFLINE_MODE_NOTICE);
$this->displayResultTable($username);
}
}

$this->Updater_model->release($username);
}

/**
Expand Down
1 change: 0 additions & 1 deletion application/core/MY_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ protected function enforce($character_id, $user_id = null, bool $isJSRequest = f
$this->aggregate = false;
}

//$this->Log->addEntry("visit " . $this->page, $user_id);
return true;
} else {
if (!$isJSRequest) {
Expand Down
5 changes: 4 additions & 1 deletion application/views/login/select_nocharacter_v.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
<div class="form-group"><label for="keyid" class="col-sm-2 control-label">vCode</label>
<div class="col-sm-10"><input type="text" class="form-control list-name" id="vcode" name="vcode" placeholder="Type your vCode here" autofocus></div>
</div>
<button type="submit" class="btn btn-default submit-add" name="submit-add">Submit</button>
<div class="text-center">
<button type="submit" class="btn btn-default submit-add" name="submit-add">Submit</button>
<a href="{{base_url('Logout')}}" class="btn btn-default">Logout</a>
</div>
</div>
<div class="api-insert-2 text-center">
<span class="help-block small text-center">Select which characters you would like to import to your account: </span>
Expand Down

0 comments on commit 24b3659

Please sign in to comment.