Merge branch 'bootstrap' of https://github.com/MPOS/php-mpos into development

This commit is contained in:
iAmShorty 2014-03-22 00:37:10 +01:00
commit 81fe0cf38a
18 changed files with 207 additions and 59 deletions

View File

@ -1,4 +1,4 @@
"./logs/*.txt" {
"./logs/*/*.txt" {
copytruncate
rotate 7
compress

View File

@ -1,5 +1,7 @@
#!/bin/bash
echo "Please be aware: This cron is deprecated and will be removed. Please read: https://github.com/MPOS/php-mpos/wiki/Cronjobs#setup"
sleep 2
#########################
# #

View File

@ -111,7 +111,7 @@ CREATE TABLE IF NOT EXISTS `payouts` (
`completed` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `account_id` (`account_id`,`completed`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `pool_worker` (
`id` int(255) NOT NULL AUTO_INCREMENT,

View File

@ -1,3 +0,0 @@
ALTER TABLE `accounts` CHANGE `sessionTimeoutStamp` `last_login` INT( 10 ) NULL DEFAULT NULL ;
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.2') ON DUPLICATE KEY UPDATE `value` = '0.0.2';
INSERT INTO `settings` (`name`, `value`) VALUES ('db_upgrade_required', 0) ON DUPLICATE KEY UPDATE `value` = 0;

View File

@ -1,6 +0,0 @@
INSERT INTO `token_types` (`name`, `expiration`) VALUES ('account_edit', 360);
INSERT INTO `token_types` (`name`, `expiration`) VALUES ('change_pw', 360);
INSERT INTO `token_types` (`name`, `expiration`) VALUES ('withdraw_funds', 360);
CREATE INDEX `account_id` ON `notification_settings` (`account_id`);
CREATE UNIQUE INDEX `account_id_type` ON `notification_settings` (`account_id`,`type`);
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.3') ON DUPLICATE KEY UPDATE `value` = '0.0.3';

View File

@ -1,5 +0,0 @@
ALTER TABLE `accounts` ADD COLUMN `signup_timestamp` INT( 10 ) NOT NULL DEFAULT '0' AFTER `failed_pins`;
ALTER TABLE `accounts` ADD COLUMN `notify_email` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `email`;
TRUNCATE TABLE `token_types`;
INSERT INTO `token_types` (`id`, `name`, `expiration`) VALUES (1, 'password_reset', 3600), (2, 'confirm_email', 0), (3, 'invitation', 0), (4, 'account_unlock', 0), (5, 'account_edit', 3600), (6, 'change_pw', 3600), (7, 'withdraw_funds', 3600);
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.4') ON DUPLICATE KEY UPDATE `value` = '0.0.4';

View File

@ -1,3 +0,0 @@
UPDATE `accounts` SET `coin_address` = NULL WHERE `coin_address` = '';
ALTER TABLE `accounts` ADD UNIQUE INDEX ( `coin_address` ) ;
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.5') ON DUPLICATE KEY UPDATE `value` = '0.0.5';

View File

@ -1,2 +0,0 @@
CREATE INDEX `account_id_archived` ON `transactions` (`account_id`,`archived`);
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.6') ON DUPLICATE KEY UPDATE `value` = '0.0.6';

View File

@ -1,2 +0,0 @@
ALTER TABLE `blocks` CHANGE `share_id` `share_id` BIGINT( 30 ) NULL DEFAULT NULL ;
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.7') ON DUPLICATE KEY UPDATE `value` = '0.0.7';

View File

@ -1,36 +0,0 @@
#!/usr/bin/php
<?php
/* Upgarde script for https://github.com/MPOS/php-mpos/issues/1981 */
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Version information
$db_version_old = '0.0.7'; // What version do we expect
$db_version_new = '0.0.8'; // What is the new version we wish to upgrade to
$db_version_now = $setting->getValue('DB_VERSION'); // Our actual version installed
// Upgrade specific variables
$dDifficulty = POW(2, ($config['difficulty'] - 16));
$aSql[] = "UPDATE " . $statistics->getTableName() . " SET valid = valid * $dDifficulty, invalid = invalid * $dDifficulty, pplns_valid = pplns_valid * $dDifficulty, pplns_invalid = pplns_invalid * $dDifficulty";
$aSql[] = "UPDATE " . $block->getTableName() . " SET shares = shares * $dDifficulty";
$aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '0.0.8' 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);
}
}
}
?>

View File

@ -0,0 +1,19 @@
<?php
function run_002() {
// Ugly but haven't found a better way
global $setting;
// Version information
$db_version_old = '0.0.1'; // What version do we expect
$db_version_new = '0.0.2'; // 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 `accounts` CHANGE `sessionTimeoutStamp` `last_login` INT( 10 ) NULL DEFAULT NULL";
$aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.2') ON DUPLICATE KEY UPDATE `value` = '0.0.2'";
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
execute_db_upgrade($aSql);
}
}
?>

View File

@ -0,0 +1,23 @@
<?php
function run_003() {
// Ugly but haven't found a better way
global $setting;
// Version information
$db_version_old = '0.0.2'; // What version do we expect
$db_version_new = '0.0.3'; // 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[] = "INSERT INTO `token_types` (`name`, `expiration`) VALUES ('account_edit', 360)";
$aSql[] = "INSERT INTO `token_types` (`name`, `expiration`) VALUES ('change_pw', 360)";
$aSql[] = "INSERT INTO `token_types` (`name`, `expiration`) VALUES ('withdraw_funds', 360)";
$aSql[] = "CREATE INDEX `account_id` ON `notification_settings` (`account_id`)";
$aSql[] = "CREATE UNIQUE INDEX `account_id_type` ON `notification_settings` (`account_id`,`type`)";
$aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.3') ON DUPLICATE KEY UPDATE `value` = '0.0.3'";
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
execute_db_upgrade($aSql);
}
}
?>

View File

@ -0,0 +1,22 @@
<?php
function run_004() {
// Ugly but haven't found a better way
global $setting;
// Version information
$db_version_old = '0.0.3'; // What version do we expect
$db_version_new = '0.0.4'; // 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 `accounts` ADD COLUMN `signup_timestamp` INT( 10 ) NOT NULL DEFAULT '0' AFTER `failed_pins`";
$aSql[] = "ALTER TABLE `accounts` ADD COLUMN `notify_email` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `email`";
$aSql[] = "TRUNCATE TABLE `token_types`";
$aSql[] = "INSERT INTO `token_types` (`id`, `name`, `expiration`) VALUES (1, 'password_reset', 3600), (2, 'confirm_email', 0), (3, 'invitation', 0), (4, 'account_unlock', 0), (5, 'account_edit', 3600), (6, 'change_pw', 3600), (7, 'withdraw_funds', 3600)";
$aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.4') ON DUPLICATE KEY UPDATE `value` = '0.0.4'";
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
execute_db_upgrade($aSql);
}
}
?>

View File

@ -0,0 +1,21 @@
<?php
function run_005() {
// Ugly but haven't found a better way
global $setting;
// Version information
$db_version_old = '0.0.4'; // What version do we expect
$db_version_new = '0.0.5'; // 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 `accounts` ADD COLUMN `signup_timestamp` INT( 10 ) NOT NULL DEFAULT '0' AFTER `failed_pins`";
$aSql[] = "UPDATE `accounts` SET `coin_address` = NULL WHERE `coin_address` = ''";
$aSql[] = "ALTER TABLE `accounts` ADD UNIQUE INDEX ( `coin_address` )";
$aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.5') ON DUPLICATE KEY UPDATE `value` = '0.0.5'";
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
execute_db_upgrade($aSql);
}
}
?>

View File

@ -0,0 +1,19 @@
<?php
function run_006() {
// Ugly but haven't found a better way
global $setting;
// Version information
$db_version_old = '0.0.5'; // What version do we expect
$db_version_new = '0.0.6'; // 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[] = "CREATE INDEX `account_id_archived` ON `transactions` (`account_id`,`archived`)";
$aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.6') ON DUPLICATE KEY UPDATE `value` = '0.0.6'";
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
execute_db_upgrade($aSql);
}
}
?>

View File

@ -0,0 +1,19 @@
<?php
function run_007() {
// Ugly but haven't found a better way
global $setting;
// Version information
$db_version_old = '0.0.6'; // What version do we expect
$db_version_new = '0.0.7'; // 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 `blocks` CHANGE `share_id` `share_id` BIGINT( 30 ) NULL DEFAULT NULL";
$aSql[] = "INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.7') ON DUPLICATE KEY UPDATE `value` = '0.0.7'";
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
execute_db_upgrade($aSql);
}
}
?>

View File

@ -0,0 +1,32 @@
<?php
function run_008() {
// Ugly but haven't found a better way
global $setting, $config, $statistics, $block, $mysqli;
// Version information
$db_version_old = '0.0.7'; // What version do we expect
$db_version_new = '0.0.8'; // What is the new version we wish to upgrade to
$db_version_now = $setting->getValue('DB_VERSION'); // Our actual version installed
// Upgrade specific variables
$dDifficulty = POW(2, ($config['difficulty'] - 16));
$aSql[] = "UPDATE " . $statistics->getTableName() . " SET valid = valid * $dDifficulty, invalid = invalid * $dDifficulty, pplns_valid = pplns_valid * $dDifficulty, pplns_invalid = pplns_invalid * $dDifficulty";
$aSql[] = "UPDATE " . $block->getTableName() . " SET shares = shares * $dDifficulty";
$aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '0.0.8' 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);
}
}
}
}
?>

48
upgrade/run_upgrades.php Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/php
<?php
/* Upgarde script for https://github.com/MPOS/php-mpos/issues/1981 */
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Fetch current version
$db_version_now = $setting->getValue('DB_VERSION');
// Helper functions
function run_db_upgrade($db_version_now) {
// Find upgrades
$files = glob(dirname(__FILE__) . "/definitions/${db_version_now}_to_*");
if (count($files) == 0) die('No upgrade definitions found for ' . $db_version_now . PHP_EOL);
foreach ($files as $file) {
$db_version_to = preg_replace("/(.*)\/definitions\/${db_version_now}_to_/", '', $file);
$db_version_to = preg_replace("/.inc.php/", '', $db_version_to);
$run_string = preg_replace("/\./", '', $db_version_to);
if (!require_once($file)) die('Failed to load upgrade definition: ' . $file);
echo "+ Running upgrade from $db_version_now to $db_version_to" . PHP_EOL;
$run = "run_$run_string";
$run();
run_db_upgrade($db_version_to);
}
}
function execute_db_upgrade($aSql) {
global $mysqli;
// 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);
}
}
}
// Initial caller
run_db_upgrade($db_version_now);
?>