Merge branch 'development' of github.com:MPOS/php-mpos into development
This commit is contained in:
commit
ccea37e4a1
@ -8,6 +8,9 @@
|
|||||||
* Added last 25 transactions
|
* Added last 25 transactions
|
||||||
* Can be changed via Admin System Settings -> Wallet
|
* Can be changed via Admin System Settings -> Wallet
|
||||||
* Always show all accounts
|
* Always show all accounts
|
||||||
|
* Updated Auto Payout Threshold to be stored in `coin_address` table
|
||||||
|
* Existing thresholds will be migrated when upgrading
|
||||||
|
* Update to `1.0.1` for the database using the upgrade script supplied in MPOS
|
||||||
* Updated Bootstrap to 3.3.4
|
* Updated Bootstrap to 3.3.4
|
||||||
* Updated MorrisJS to 0.5.1
|
* Updated MorrisJS to 0.5.1
|
||||||
* Updated RaphaelJS to 2.1.2
|
* Updated RaphaelJS to 2.1.2
|
||||||
|
|||||||
@ -27,6 +27,29 @@ class CoinAddress extends Base {
|
|||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch users Auto Payout Threshold for a currency
|
||||||
|
* @param UserID int UserID
|
||||||
|
* @return mixed Float value for threshold, false on error
|
||||||
|
**/
|
||||||
|
public function getAPThreshold($userID, $currency=NULL) {
|
||||||
|
if ($currency === NULL) $currency = $this->config['currency'];
|
||||||
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
|
$stmt = $this->mysqli->prepare("
|
||||||
|
SELECT ap_threshold
|
||||||
|
FROM " . $this->getTableName() . "
|
||||||
|
WHERE account_id = ? AND currency = ?
|
||||||
|
");
|
||||||
|
if ( $this->checkStmt($stmt) && $stmt->bind_param('is', $userID, $currency) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||||
|
if ($result->num_rows == 1) {
|
||||||
|
return $result->fetch_object()->ap_threshold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->debug->append("Unable to fetch users auto payout threshold for " . $currency);
|
||||||
|
return $this->sqlError();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a coin address is already set
|
* Check if a coin address is already set
|
||||||
* @param address string Coin Address to check for
|
* @param address string Coin Address to check for
|
||||||
@ -76,23 +99,24 @@ class CoinAddress extends Base {
|
|||||||
* Update a coin address record for a user and a currency
|
* Update a coin address record for a user and a currency
|
||||||
* @param userID int Account ID
|
* @param userID int Account ID
|
||||||
* @param address string Coin Address
|
* @param address string Coin Address
|
||||||
|
* @param ap_threshold float Threshold for auto payouts for this currency
|
||||||
* @param currency string Currency short handle, defaults to config option
|
* @param currency string Currency short handle, defaults to config option
|
||||||
* @return bool true or false
|
* @return bool true or false
|
||||||
**/
|
**/
|
||||||
public function update($userID, $address, $currency=NULL) {
|
public function update($userID, $address, $ap_threshold, $currency=NULL) {
|
||||||
if ($currency === NULL) $currency = $this->config['currency'];
|
if ($currency === NULL) $currency = $this->config['currency'];
|
||||||
if ($address != $this->getCoinAddress($userID) && $this->existsCoinAddress($address)) {
|
if ($address != $this->getCoinAddress($userID) && $this->existsCoinAddress($address)) {
|
||||||
$this->setErrorMessage('Unable to update coin address, address already exists');
|
$this->setErrorMessage('Unable to update coin address, address already exists');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->getCoinAddress($userID) != NULL) {
|
if ($this->getCoinAddress($userID) != NULL) {
|
||||||
$stmt = $this->mysqli->prepare("UPDATE " . $this->getTableName() . " SET coin_address = ? WHERE account_id = ? AND currency = ?");
|
$stmt = $this->mysqli->prepare("UPDATE " . $this->getTableName() . " SET coin_address = ?, ap_threshold = ? WHERE account_id = ? AND currency = ?");
|
||||||
if ( $this->checkStmt($stmt) && $stmt->bind_param('sis', $address, $userID, $currency) && $stmt->execute()) {
|
if ( $this->checkStmt($stmt) && $stmt->bind_param('sdis', $address, $ap_threshold, $userID, $currency) && $stmt->execute()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$stmt = $this->mysqli->prepare("INSERT INTO " . $this->getTableName() . " (coin_address, account_id, currency) VALUES (?, ?, ?)");
|
$stmt = $this->mysqli->prepare("INSERT INTO " . $this->getTableName() . " (coin_address, ap_threshold, account_id, currency) VALUES (?, ?, ?, ?)");
|
||||||
if ( $this->checkStmt($stmt) && $stmt->bind_param('sis', $address, $userID, $currency) && $stmt->execute()) {
|
if ( $this->checkStmt($stmt) && $stmt->bind_param('sdis', $address, $ap_threshold, $userID, $currency) && $stmt->execute()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -355,7 +355,7 @@ class Transaction extends Base {
|
|||||||
SELECT
|
SELECT
|
||||||
a.id,
|
a.id,
|
||||||
a.username,
|
a.username,
|
||||||
a.ap_threshold,
|
ca.ap_threshold,
|
||||||
ca.coin_address,
|
ca.coin_address,
|
||||||
IFNULL(
|
IFNULL(
|
||||||
(
|
(
|
||||||
@ -371,9 +371,9 @@ class Transaction extends Base {
|
|||||||
ON t.account_id = a.id
|
ON t.account_id = a.id
|
||||||
LEFT JOIN " . $this->coin_address->getTableName() . " AS ca
|
LEFT JOIN " . $this->coin_address->getTableName() . " AS ca
|
||||||
ON ca.account_id = a.id
|
ON ca.account_id = a.id
|
||||||
WHERE t.archived = 0 AND a.ap_threshold > 0 AND ca.coin_address IS NOT NULL AND ca.coin_address != '' AND ca.currency = ?
|
WHERE t.archived = 0 AND ca.ap_threshold > 0 AND ca.coin_address IS NOT NULL AND ca.coin_address != '' AND ca.currency = ?
|
||||||
GROUP BY t.account_id
|
GROUP BY t.account_id
|
||||||
HAVING confirmed > a.ap_threshold AND confirmed > " . $this->config['txfee_auto'] . "
|
HAVING confirmed > ca.ap_threshold AND confirmed > " . $this->config['txfee_auto'] . "
|
||||||
LIMIT ?");
|
LIMIT ?");
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('si', $this->config['currency'], $limit) && $stmt->execute() && $result = $stmt->get_result())
|
if ($this->checkStmt($stmt) && $stmt->bind_param('si', $this->config['currency'], $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||||
return $result->fetch_all(MYSQLI_ASSOC);
|
return $result->fetch_all(MYSQLI_ASSOC);
|
||||||
@ -446,7 +446,7 @@ class Transaction extends Base {
|
|||||||
SELECT
|
SELECT
|
||||||
a.id,
|
a.id,
|
||||||
a.username,
|
a.username,
|
||||||
a.ap_threshold,
|
ca.ap_threshold,
|
||||||
ca.coin_address,
|
ca.coin_address,
|
||||||
p.id AS payout_id,
|
p.id AS payout_id,
|
||||||
IFNULL(
|
IFNULL(
|
||||||
|
|||||||
@ -340,11 +340,11 @@ class User extends Base {
|
|||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
$stmt = $this->mysqli->prepare("
|
$stmt = $this->mysqli->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
a.id, a.username, ca.coin_address AS coin_address, a.ap_threshold
|
a.id, a.username, ca.coin_address AS coin_address, ca.ap_threshold
|
||||||
FROM " . $this->getTableName() . " AS a
|
FROM " . $this->getTableName() . " AS a
|
||||||
LEFT JOIN " . $this->coin_address->getTableName() . " AS ca
|
LEFT JOIN " . $this->coin_address->getTableName() . " AS ca
|
||||||
ON a.id = ca.account_id
|
ON a.id = ca.account_id
|
||||||
WHERE ap_threshold > 0 AND ca.currency = ?
|
WHERE ca.ap_threshold > 0 AND ca.currency = ?
|
||||||
AND ca.coin_address IS NOT NULL
|
AND ca.coin_address IS NOT NULL
|
||||||
");
|
");
|
||||||
if ( $this->checkStmt($stmt) && $stmt->bind_param('s', $this->config['currency']) && $stmt->execute() && $result = $stmt->get_result()) {
|
if ( $this->checkStmt($stmt) && $stmt->bind_param('s', $this->config['currency']) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||||
@ -544,12 +544,12 @@ class User extends Base {
|
|||||||
if ($email == 'hidden' || $email == NULL)
|
if ($email == 'hidden' || $email == NULL)
|
||||||
$email = $this->getUserEmailById($userID);
|
$email = $this->getUserEmailById($userID);
|
||||||
// We passed all validation checks so update the account
|
// We passed all validation checks so update the account
|
||||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET ap_threshold = ?, donate_percent = ?, email = ?, timezone = ?, is_anonymous = ? WHERE id = ?");
|
$stmt = $this->mysqli->prepare("UPDATE $this->table SET donate_percent = ?, email = ?, timezone = ?, is_anonymous = ? WHERE id = ?");
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ddssii', $threshold, $donate, $email, $timezone, $is_anonymous, $userID) && $stmt->execute()) {
|
if ($this->checkStmt($stmt) && $stmt->bind_param('dssii', $donate, $email, $timezone, $is_anonymous, $userID) && $stmt->execute()) {
|
||||||
$this->log->log("info", $this->getUserName($userID)." updated their account details");
|
$this->log->log("info", $this->getUserName($userID)." updated their account details");
|
||||||
// Update coin address too
|
// Update coin address and ap_threshold if coin_address is set
|
||||||
if ($address) {
|
if ($address) {
|
||||||
if ($this->coin_address->update($userID, $address)) {
|
if ($this->coin_address->update($userID, $address, $threshold)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -698,12 +698,13 @@ class User extends Base {
|
|||||||
$stmt = $this->mysqli->prepare("
|
$stmt = $this->mysqli->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
id AS id, username, pin, api_key, is_admin, is_anonymous, email, timezone, no_fees,
|
id AS id, username, pin, api_key, is_admin, is_anonymous, email, timezone, no_fees,
|
||||||
IFNULL(donate_percent, '0') as donate_percent, ap_threshold
|
IFNULL(donate_percent, '0') as donate_percent
|
||||||
FROM " . $this->getTableName() . "
|
FROM " . $this->getTableName() . "
|
||||||
WHERE id = ? LIMIT 0,1");
|
WHERE id = ? LIMIT 0,1");
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $userID) && $stmt->execute() && $result = $stmt->get_result()) {
|
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $userID) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||||
$aData = $result->fetch_assoc();
|
$aData = $result->fetch_assoc();
|
||||||
$aData['coin_address'] = $this->coin_address->getCoinAddress($userID);
|
$aData['coin_address'] = $this->coin_address->getCoinAddress($userID);
|
||||||
|
$aData['ap_threshold'] = $this->coin_address->getAPThreshold($userID);
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
return $aData;
|
return $aData;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
|
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
|
||||||
|
|
||||||
define('MPOS_VERSION', '1.0.2');
|
define('MPOS_VERSION', '1.0.2');
|
||||||
define('DB_VERSION', '1.0.0');
|
define('DB_VERSION', '1.0.1');
|
||||||
define('CONFIG_VERSION', '1.0.0');
|
define('CONFIG_VERSION', '1.0.0');
|
||||||
define('HASH_VERSION', 1);
|
define('HASH_VERSION', 1);
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,6 @@ CREATE TABLE IF NOT EXISTS `accounts` (
|
|||||||
`api_key` varchar(255) DEFAULT NULL,
|
`api_key` varchar(255) DEFAULT NULL,
|
||||||
`token` varchar(65) DEFAULT NULL,
|
`token` varchar(65) DEFAULT NULL,
|
||||||
`donate_percent` float DEFAULT '0',
|
`donate_percent` float DEFAULT '0',
|
||||||
`ap_threshold` float DEFAULT '0',
|
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `username` (`username`),
|
UNIQUE KEY `username` (`username`),
|
||||||
UNIQUE KEY `email` (`email`)
|
UNIQUE KEY `email` (`email`)
|
||||||
@ -56,6 +55,7 @@ CREATE TABLE IF NOT EXISTS `coin_addresses` (
|
|||||||
`account_id` int(11) NOT NULL,
|
`account_id` int(11) NOT NULL,
|
||||||
`currency` varchar(5) NOT NULL,
|
`currency` varchar(5) NOT NULL,
|
||||||
`coin_address` varchar(255) NOT NULL,
|
`coin_address` varchar(255) NOT NULL,
|
||||||
|
`ap_threshold` float DEFAULT '0',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `coin_address` (`coin_address`),
|
UNIQUE KEY `coin_address` (`coin_address`),
|
||||||
KEY `account_id` (`account_id`)
|
KEY `account_id` (`account_id`)
|
||||||
@ -142,7 +142,7 @@ CREATE TABLE IF NOT EXISTS `settings` (
|
|||||||
UNIQUE KEY `setting` (`name`)
|
UNIQUE KEY `setting` (`name`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '1.0.0');
|
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '1.0.1');
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `shares` (
|
CREATE TABLE IF NOT EXISTS `shares` (
|
||||||
`id` bigint(30) NOT NULL AUTO_INCREMENT,
|
`id` bigint(30) NOT NULL AUTO_INCREMENT,
|
||||||
|
|||||||
32
upgrade/definitions/1.0.0_to_1.0.1.inc.php
Normal file
32
upgrade/definitions/1.0.0_to_1.0.1.inc.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
function run_101() {
|
||||||
|
// Ugly but haven't found a better way
|
||||||
|
global $setting, $config, $coin_address, $user, $mysqli;
|
||||||
|
|
||||||
|
// Version information
|
||||||
|
$db_version_old = '1.0.0'; // What version do we expect
|
||||||
|
$db_version_new = '1.0.1'; // What is the new version we wish to upgrade to
|
||||||
|
$db_version_now = $setting->getValue('DB_VERSION'); // Our actual version installed
|
||||||
|
|
||||||
|
// Upgrade specific variables
|
||||||
|
$aSql[] = "ALTER TABLE `" . $coin_address->getTableName() . "` ADD ap_threshold float DEFAULT '0'";
|
||||||
|
$aSql[] = "UPDATE " . $coin_address->getTableName() . " AS ca LEFT JOIN " . $user->getTableName() . " AS a ON a.id = ca.account_id SET ca.ap_threshold = a.ap_threshold";
|
||||||
|
$aSql[] = "ALTER TABLE `" . $user->getTableName() . "` DROP `ap_threshold`";
|
||||||
|
$aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '1.0.1' 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user