From f9ee57a858624fd111988e0c8b41e766a5b9f12d Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 23 Jun 2021 11:00:50 +0000 Subject: [PATCH] remove second decay by creation transaction, update old data set --- community_server/src/Controller/AppController.php | 2 +- community_server/src/Controller/MigrationsController.php | 8 ++++++++ .../src/Model/Transactions/TransactionCreation.php | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/community_server/src/Controller/AppController.php b/community_server/src/Controller/AppController.php index 2c6344511..7ca966e98 100644 --- a/community_server/src/Controller/AppController.php +++ b/community_server/src/Controller/AppController.php @@ -151,7 +151,7 @@ class AppController extends Controller if($last_migration) { $current_db_version = $last_migration->db_version; } - $php_data_version = 2; + $php_data_version = 3; if($current_db_version < $php_data_version) { $this->redirect(['controller' => 'Migrations', 'action' => 'migrate', 'html' => $html, 'db_version' => $current_db_version]); } diff --git a/community_server/src/Controller/MigrationsController.php b/community_server/src/Controller/MigrationsController.php index 97481aff5..47e3b611a 100644 --- a/community_server/src/Controller/MigrationsController.php +++ b/community_server/src/Controller/MigrationsController.php @@ -69,6 +69,14 @@ class MigrationsController extends AppController [$stateBalancesTable, 'updateAllBalances'] ]; $new_db_version = 2; + } else if($current_db_version == 2) { + $commands = [ + [$stateUserTransactionsTable, 'truncate'], + [$stateBalancesTable, 'truncate'], + [$transactionsTable, 'fillStateUserTransactions'], + [$stateBalancesTable, 'updateAllBalances'] + ]; + $new_db_version = 3; } $migration_result = $this->callFunctions($commands); diff --git a/community_server/src/Model/Transactions/TransactionCreation.php b/community_server/src/Model/Transactions/TransactionCreation.php index 9150d24eb..87f2d2104 100644 --- a/community_server/src/Model/Transactions/TransactionCreation.php +++ b/community_server/src/Model/Transactions/TransactionCreation.php @@ -163,7 +163,8 @@ class TransactionCreation extends TransactionBase { $transactionCreationEntity->target_date = $this->protoTransactionCreation->getTargetDate()->getSeconds(); $target_date = new FrozenTime($transactionCreationEntity->target_date); - $decayed_balance = $stateBalancesTable->calculateDecay($this->getAmount(), $target_date, $received); + //$decayed_balance = $stateBalancesTable->calculateDecay($this->getAmount(), $target_date, $received); + $balance = $this->getAmount(); if(!$this->transactionCreationsTable->save($transactionCreationEntity)) { $this->addError('TransactionCreation::save', 'error saving transactionCreation with errors: ' . json_encode($transactionCreationEntity->getErrors())); @@ -171,13 +172,13 @@ class TransactionCreation extends TransactionBase { } // update state balance - $final_balance = $this->updateStateBalance($receiverUserId, $decayed_balance, $received); + $final_balance = $this->updateStateBalance($receiverUserId, $balance, $received); if(false === $final_balance) { return false; } // decay is a virtual field which is calculated from amount and now() - record_date - if(!$this->addStateUserTransaction($receiverUserId, $transaction_id, 1, $decayed_balance, $received)) { + if(!$this->addStateUserTransaction($receiverUserId, $transaction_id, 1, $balance, $received)) { return false; }