PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Revenue / Migrations / RemoveRevenueForeignKeys.php

RemoveRevenueForeignKeys.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Revenue/Migrations/RemoveRevenueForeignKeys.php

75 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Revenue\Migrations;
4
5 use Give\Framework\Database\DB;
6 use Give\Framework\Migrations\Contracts\Migration;
7
8 /**
9 * Class RemoveRevenueForeignKeys
10 *
11 * @package Give\Revenue\Migrations
12 * @since 2.9.6
13 */
14 class RemoveRevenueForeignKeys extends Migration
15 {
16 /**
17 * @inheritDoc
18 */
19 public static function id()
20 {
21 return 'remove_revenue_foreign_keys';
22 }
23
24 /**
25 * @inheritDoc
26 */
27 public function run()
28 {
29 global $wpdb;
30
31 $this->dropColumnForeignKeyConstraint($wpdb->give_revenue, 'form_id');
32 $this->dropColumnForeignKeyConstraint($wpdb->give_revenue, 'donation_id');
33 }
34
35 /**
36 * @inheritDoc
37 */
38 public static function timestamp()
39 {
40 return strtotime('01-05-2020 12:45:00');
41 }
42
43 /**
44 * Drops the foreign key constraint for a given table and column
45 *
46 * @since 2.9.6
47 *
48 * @param string $table
49 * @param string $column
50 */
51 private function dropColumnForeignKeyConstraint($table, $column)
52 {
53 $constraintName = DB::get_var(
54 DB::prepare(
55 "
56 SELECT constraints.CONSTRAINT_NAME
57 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS as constraints
58 JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE as column_usage
59 ON constraints.CONSTRAINT_NAME = column_usage.CONSTRAINT_NAME
60 WHERE constraints.CONSTRAINT_TYPE = 'FOREIGN KEY'
61 AND constraints.TABLE_NAME = %s
62 AND column_usage.COLUMN_NAME = %s
63 ",
64 $table,
65 $column
66 )
67 );
68
69 if ( ! empty($constraintName)) {
70 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
71 DB::query("ALTER TABLE {$table} DROP FOREIGN KEY {$constraintName}");
72 }
73 }
74 }
75