From 6ddca7466c0dcc38813546715ea10694bbd1de03 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 7 Jul 2014 14:31:17 +0200 Subject: [PATCH] [ADDED] Properly insert coin values --- include/classes/transaction.class.php | 4 ++- include/version.inc.php | 2 +- sql/000_base_structure.sql | 4 +-- upgrade/definitions/0.0.11_to_0.0.12.inc.php | 30 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 upgrade/definitions/0.0.11_to_0.0.12.inc.php diff --git a/include/classes/transaction.class.php b/include/classes/transaction.class.php index 990a6555..01d5fc14 100644 --- a/include/classes/transaction.class.php +++ b/include/classes/transaction.class.php @@ -16,8 +16,9 @@ class Transaction extends Base { * @return bool **/ public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $txid=NULL) { + $amount = number_format($amount, $this->setting->getValue('system_coin_precision', 12), '.', ''); $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address, txid) VALUES (?, ?, ?, ?, ?, ?)"); - if ($this->checkStmt($stmt) && $stmt->bind_param("idisss", $account_id, $amount, $block_id, $type, $coin_address, $txid) && $stmt->execute()) { + if ($this->checkStmt($stmt) && $stmt->bind_param("isisss", $account_id, $amount, $block_id, $type, $coin_address, $txid) && $stmt->execute()) { $this->insert_id = $stmt->insert_id; return true; } @@ -473,6 +474,7 @@ class Transaction extends Base { $transaction = new Transaction(); $transaction->setMemcache($memcache); $transaction->setNotification($notification); +$transaction->setSetting($setting); $transaction->setDebug($debug); $transaction->setMysql($mysqli); $transaction->setConfig($config); diff --git a/include/version.inc.php b/include/version.inc.php index 91d93ee8..a4e0d533 100644 --- a/include/version.inc.php +++ b/include/version.inc.php @@ -2,7 +2,7 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; define('MPOS_VERSION', '0.0.4'); -define('DB_VERSION', '0.0.11'); +define('DB_VERSION', '0.0.12'); define('CONFIG_VERSION', '0.0.8'); define('HASH_VERSION', 1); diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index 85e3e67c..c9773c5f 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -134,7 +134,7 @@ CREATE TABLE IF NOT EXISTS `settings` ( UNIQUE KEY `setting` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.11'); +INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.12'); CREATE TABLE IF NOT EXISTS `shares` ( `id` bigint(30) NOT NULL AUTO_INCREMENT, @@ -216,7 +216,7 @@ CREATE TABLE IF NOT EXISTS `transactions` ( `account_id` int(255) unsigned NOT NULL, `type` varchar(25) DEFAULT NULL, `coin_address` varchar(255) DEFAULT NULL, - `amount` double DEFAULT '0', + `amount` double(50,30) DEFAULT '0', `block_id` int(255) DEFAULT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `txid` varchar(256) DEFAULT NULL, diff --git a/upgrade/definitions/0.0.11_to_0.0.12.inc.php b/upgrade/definitions/0.0.11_to_0.0.12.inc.php new file mode 100644 index 00000000..7d8d7c6d --- /dev/null +++ b/upgrade/definitions/0.0.11_to_0.0.12.inc.php @@ -0,0 +1,30 @@ +getValue('DB_VERSION'); // Our actual version installed + + // Upgrade specific variables + $aSql[] = "ALTER TABLE " . $transaction->getTableName() . " CHANGE `amount` `amount` DOUBLE(60,30) NULL DEFAULT '0'"; + $aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '0.0.12' WHERE name = 'DB_VERSION'"; + + if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) { + // Run the upgrade + echo '- Starting database migration to version ' . $db_version_new . PHP_EOL; + foreach ($aSql as $sql) { + echo '- Preparing: ' . $sql . PHP_EOL; + $stmt = $mysqli->prepare($sql); + if ($stmt && $stmt->execute()) { + echo '- success' . PHP_EOL; + } else { + echo '- failed: ' . $mysqli->error . PHP_EOL; + exit(1); + } + } + } +} +?>