PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.3.2
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.3.2
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
better-payment / includes / Classes / Migrator.php

Migrator.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.3.2, at includes/Classes/Migrator.php

73 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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::create_missing_tables();
27 self::update_tables();
28 }
29
30 /**
31 * Create any table added since this install was activated (dbDelta is
32 * idempotent). The migrator only runs once per version change, so an
33 * existing install picks up e.g. the better_payment_subscription_order table
34 * on its first load after an update — activation never re-runs there.
35 *
36 * Kept separate from update_tables(), which stays ALTER-only: the test
37 * environment rewrites CREATE TABLE to CREATE TEMPORARY TABLE, so a
38 * create inside a column-migration test would shadow the real table.
39 *
40 * @since 2.4.0
41 */
42 public static function create_missing_tables() {
43 ( new \Better_Payment\Lite\Installer() )->create_tables();
44 }
45
46 /**
47 * Update the plugin tables
48 *
49 * @since 0.0.2
50 */
51 public static function update_tables() {
52 //Add column
53 self::add_column( 'refund_info', 'longtext' );
54 self::add_column( 'campaign_id', 'text' );
55 }
56
57 private static function add_column( $column_name, $column_type ) {
58 global $wpdb;
59 $wpdb->hide_errors();
60 $table_name = "{$wpdb->prefix}better_payment";
61
62 // $row = $wpdb->get_results( "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table_name' AND column_name = '$column_name'" );
63
64 $columns = $wpdb->get_col( "DESC $table_name", 0 );
65
66 if (in_array($column_name, $columns)) {
67 return;
68 }
69
70 $wpdb->query($wpdb->prepare("ALTER TABLE $table_name ADD $column_name $column_type"));
71 }
72 }
73