| 1 |
<?php |
| 2 |
|
| 3 |
namespace Better_Payment\Lite\Classes; |
| 4 |
|
| 5 |
/** |
| 6 |
* Exit if accessed directly |
| 7 |
*/ |
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* The plugin migrator class |
| 14 |
* |
| 15 |
* @since 0.0.2 |
| 16 |
*/ |
| 17 |
class Migrator |
| 18 |
{ |
| 19 |
|
| 20 |
/** |
| 21 |
* Initialize the plugin |
| 22 |
* |
| 23 |
* @since 0.0.2 |
| 24 |
*/ |
| 25 |
public static function migrator() { |
| 26 |
self::update_tables(); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Update the plugin tables |
| 31 |
* |
| 32 |
* @since 0.0.2 |
| 33 |
*/ |
| 34 |
public static function update_tables() { |
| 35 |
//Add column |
| 36 |
self::add_column( 'refund_info', 'longtext' ); |
| 37 |
self::add_column( 'campaign_id', 'text' ); |
| 38 |
} |
| 39 |
|
| 40 |
private static function add_column( $column_name, $column_type ) { |
| 41 |
global $wpdb; |
| 42 |
$wpdb->hide_errors(); |
| 43 |
$table_name = "{$wpdb->prefix}better_payment"; |
| 44 |
|
| 45 |
// $row = $wpdb->get_results( "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table_name' AND column_name = '$column_name'" ); |
| 46 |
|
| 47 |
$columns = $wpdb->get_col( "DESC $table_name", 0 ); |
| 48 |
|
| 49 |
if (in_array($column_name, $columns)) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
$wpdb->query($wpdb->prepare("ALTER TABLE $table_name ADD $column_name $column_type")); |
| 54 |
} |
| 55 |
} |
| 56 |
|