-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated db and underpayment flow #310
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
acf0af4
new db table blockonomics_payments, fixes #296
anktd ab086f7
delete (new) payments table on uninstall
anktd e00df06
use new table
anktd 4d85ba9
add coupon on underpayment
anktd f9b80e0
(fix) custom fields and mix payments
anktd 94d2481
send email on underpayment
anktd 7251c33
refactoring functions
anktd c92c771
refactor function update_paid_amount
anktd 0877e41
refactor function save_transaction
anktd 46ae09c
readability improvements
anktd 6ac7a65
changes in db update and creation
anktd 4425270
remove meta check for confirmed payments
anktd c5b0e65
update custom fields for addr & txid
anktd bd38dd5
update db_version only after db creation or update
anktd 85e4c32
remove hidden meta field _paid_to_addr
anktd c09bf62
change satoshi to bigint
anktd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -464,24 +464,31 @@ function bnomics_async_scripts($url) | |
add_action('admin_notices', 'blockonomics_plugin_activation'); | ||
|
||
global $blockonomics_db_version; | ||
$blockonomics_db_version = '1.1'; | ||
$blockonomics_db_version = '1.2'; | ||
|
||
function blockonomics_create_table() { | ||
// Create blockonomics_orders table | ||
// Create blockonomics_payments table | ||
// https://codex.wordpress.org/Creating_Tables_with_Plugins | ||
global $wpdb; | ||
global $blockonomics_db_version; | ||
/* for db version 1.2, new table blockonomics_payments is introduced | ||
status is renamed to payment_status | ||
satoshi is renamed to expected_satoshi | ||
value is renamed to expected_fiat & it is no longer longtext | ||
2 new fields are added for logging purpose only - paid_satoshi & paid_fiat */ | ||
|
||
$table_name = $wpdb->prefix . 'blockonomics_orders'; | ||
$table_name = $wpdb->prefix . 'blockonomics_payments'; | ||
$charset_collate = $wpdb->get_charset_collate(); | ||
$sql = "CREATE TABLE $table_name ( | ||
order_id int NOT NULL, | ||
status int NOT NULL, | ||
payment_status int NOT NULL, | ||
crypto varchar(3) NOT NULL, | ||
address varchar(191) NOT NULL, | ||
satoshi int, | ||
expected_satoshi bigint, | ||
expected_fiat double, | ||
currency varchar(3), | ||
value longtext, | ||
paid_satoshi bigint, | ||
paid_fiat double, | ||
txid text, | ||
PRIMARY KEY (address), | ||
KEY orderkey (order_id,crypto) | ||
|
@@ -501,19 +508,30 @@ function blockonomics_activation_hook() { | |
} | ||
|
||
// Since WP 3.1 the activation function registered with register_activation_hook() is not called when a plugin is updated. | ||
// blockonomics_update_db_check() is loaded for every PHP page by plugins_loaded hook | ||
function blockonomics_update_db_check() { | ||
global $wpdb; | ||
global $blockonomics_db_version; | ||
|
||
$installed_ver = get_site_option( 'blockonomics_db_version' ); | ||
if ( $installed_ver != $blockonomics_db_version ) { | ||
// blockonomics_create_table() should only be run if there is no $installed_ver, refer https://github.com/blockonomics/woocommerce-plugin/issues/296 | ||
if (empty($installed_ver)){ | ||
blockonomics_create_table(); | ||
} else if (version_compare( $installed_ver, $blockonomics_db_version, '!=')) { | ||
blockonomics_run_db_updates($installed_ver); | ||
} | ||
} | ||
|
||
function blockonomics_run_db_updates($installed_ver){ | ||
global $wpdb; | ||
global $blockonomics_db_version; | ||
if (version_compare($installed_ver, '1.1', '<')){ | ||
$table_name = $wpdb->prefix . 'blockonomics_orders'; | ||
if ($installed_ver < 1.1) { | ||
maybe_drop_column($table_name, "time_remaining", "ALTER TABLE $table_name DROP COLUMN time_remaining"); | ||
maybe_drop_column($table_name, "timestamp", "ALTER TABLE $table_name DROP COLUMN timestamp"); | ||
} | ||
maybe_drop_column($table_name, "time_remaining", "ALTER TABLE $table_name DROP COLUMN time_remaining"); | ||
maybe_drop_column($table_name, "timestamp", "ALTER TABLE $table_name DROP COLUMN timestamp"); | ||
} | ||
if (version_compare($installed_ver, '1.2', '<')){ | ||
blockonomics_create_table(); | ||
} | ||
update_option( 'blockonomics_db_version', $blockonomics_db_version ); | ||
} | ||
|
||
add_action( 'plugins_loaded', 'blockonomics_update_db_check' ); | ||
|
@@ -561,7 +579,8 @@ function blockonomics_uninstall_hook() { | |
delete_option('blockonomics_network_confirmation'); | ||
|
||
global $wpdb; | ||
$wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS ".$wpdb->prefix."blockonomics_orders")); | ||
// if module is uninstalled, drop both tables blockonomics_orders & blockonomics_payments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid trivial comments. Explaining motivation. For example, here we can explain why we are dropping blockonomics_orders ? |
||
$wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS ".$wpdb->prefix."blockonomics_orders , ".$wpdb->prefix."blockonomics_payments")); | ||
delete_option("blockonomics_db_version"); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why this code is required since we are using a different table now ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retaining the upgrade scripts ensures that any updates to the plugin between any versions will function correctly and behave consistently. Retaining the upgrade from the previous version allows users to update from versions <= 3.5.7 to version 3.5.8, rather than the most recent version 3.5.9 if they so choose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary. To much unrequited complexity. Lets remove