PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 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 All 256 releases
← All changes | src/Campaigns/Migrations/RevenueTable/AddIndexes.php +19 -1 4.16.3 → 4.17.0 View file →
@@ -37,8 +37,12 @@
37 37 }
38 38
39 39 /**
40 40 * @inheritDoc
41 + *
42 + * @since 4.17.0 Only add indexes that do not exist yet, so re-running the migration is safe.
43 + * @since 4.0.0
44 + *
41 45 * @throws DatabaseMigrationException
42 46 */
43 47 public function run()
44 48 {
@@ -44,9 +48,23 @@
44 48 {
45 49 global $wpdb;
46 50
47 51 try {
48 - DB::query("ALTER TABLE {$wpdb->give_revenue} ADD INDEX (form_id), ADD INDEX (campaign_id)");
52 + $existing = DB::get_col("SHOW INDEX FROM {$wpdb->give_revenue}", 4);
53 +
54 + $indexes = array_filter(['form_id', 'campaign_id'], static function ($column) use ($existing) {
55 + return !in_array($column, $existing, true);
56 + });
57 +
58 + if (!$indexes) {
59 + return;
60 + }
61 +
62 + $clauses = array_map(static function ($column) {
63 + return "ADD INDEX ($column)";
64 + }, $indexes);
65 +
66 + DB::query("ALTER TABLE {$wpdb->give_revenue} " . implode(', ', $clauses));
49 67 } catch (DatabaseQueryException $exception) {
50 68 throw new DatabaseMigrationException("An error occurred while updating the {$wpdb->give_revenue} table", 0,
51 69 $exception);
52 70 }