Skip to content

Commit b306b8d

Browse files
committed
Fixed Database Table Schema on Update .
1 parent d70c803 commit b306b8d

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function kkd_pff_paystack_edit_dashboard_header_columns( $columns ) {
180180

181181
function kkd_pff_paystack_dashboard_table_data( $column, $post_id ) {
182182
global $post,$wpdb;
183-
$table = $wpdb->prefix . 'paystack_forms_payments';
183+
$table = $wpdb->prefix . KKD_PFF_PAYSTACK_TABLE;
184184

185185
switch( $column ) {
186186
case 'shortcode' :
@@ -506,7 +506,7 @@ public function prepare_items(){
506506

507507
global $wpdb;
508508

509-
$table = $wpdb->prefix."paystack_forms_payments";
509+
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
510510
$data = array();
511511
$alldbdata = $wpdb->get_results("SELECT * FROM $table WHERE (post_id = '".$post_id."' AND paid = '1')");
512512

includes/class-paystack-forms-activator.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,32 @@ class Kkd_Pff_Paystack_Activator {
33

44
public static function activate() {
55
global $wpdb;
6-
$table_name = $wpdb->prefix . 'paystack_forms_payments';
6+
$table_name = $wpdb->prefix . KKD_PFF_PAYSTACK_TABLE;
77

8-
$sql = "CREATE TABLE `".$table_name."` (
8+
$sql = "CREATE TABLE IF NOT EXISTS `".$table_name."` (
99
id int(11) NOT NULL AUTO_INCREMENT,
1010
post_id int(11) NOT NULL,
1111
user_id int(11) NOT NULL,
1212
email varchar(255) DEFAULT '' NOT NULL,
13-
plan varchar(255) DEFAULT '' NOT NULL,
1413
metadata text,
1514
paid int(1) NOT NULL DEFAULT '0',
15+
plan varchar(255) DEFAULT '' NOT NULL,
1616
txn_code varchar(255) DEFAULT '' NOT NULL,
1717
amount varchar(255) DEFAULT '' NOT NULL,
1818
ip varchar(255) NOT NULL,
1919
deleted_at varchar(255) DEFAULT '' NULL,
2020
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
2121
modified timestamp DEFAULT '0000-00-00 00:00:00' NOT NULL,
22-
UNIQUE KEY id (id)
22+
UNIQUE KEY id (id),PRIMARY KEY (id)
2323
);";
2424
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
2525
dbDelta($sql);
26+
$row = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
27+
WHERE table_name = '".$table_name."' AND column_name = 'plan'" );
28+
29+
if(empty($row)){
30+
$wpdb->query("ALTER TABLE `".$table_name."` ADD `plan` VARCHAR(255) NOT NULL AFTER `paid`;");
31+
}
2632

2733
}
2834

paystack-forms.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
define( 'KKD_PFF_PAYSTACK_PLUGIN_PATH', plugins_url( __FILE__ ) );
1717
define( 'KKD_PFF_PAYSTACK_MAIN_FILE', __FILE__ );
1818
define( 'KKD_PFF_PAYSTACK_VERSION', '1.0.4' );
19+
define( 'KKD_PFF_PAYSTACK_TABLE', 'paystack_forms_payments' );
1920

2021

2122
// fix some badly enqueued scripts with no sense of HTTPS

public/class-paystack-forms-public.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ function kkd_pff_paystack_generate_new_code($length = 10){
831831
}
832832
function kkd_pff_paystack_check_code($code){
833833
global $wpdb;
834-
$table = $wpdb->prefix."paystack_forms_payments";
834+
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
835835
$o_exist = $wpdb->get_results("SELECT * FROM $table WHERE txn_code = '".$code."'");
836836

837837
if (count($o_exist) > 0) {
@@ -877,7 +877,7 @@ function kkd_pff_paystack_submit_action() {
877877
global $wpdb;
878878
$code = kkd_pff_paystack_generate_code();
879879

880-
$table = $wpdb->prefix."paystack_forms_payments";
880+
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
881881
$metadata = $_POST;
882882
$fullname = $_POST['pf-fname'];
883883
$recur = $_POST['pf-recur'];
@@ -1108,7 +1108,7 @@ function kkd_pff_paystack_confirm_payment() {
11081108
exit(json_encode($response));
11091109
}
11101110
global $wpdb;
1111-
$table = $wpdb->prefix."paystack_forms_payments";
1111+
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
11121112
$code = $_POST['code'];
11131113
$record = $wpdb->get_results("SELECT * FROM $table WHERE (txn_code = '".$code."')");
11141114
if (array_key_exists("0", $record)) {

0 commit comments

Comments
 (0)