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 / Subscriptions / Migrations / AddCampaignId.php

AddCampaignId.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Subscriptions/Migrations/AddCampaignId.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\Subscriptions\Migrations;
4
5 use Give\Framework\Database\DB;
6 use Give\Framework\Database\Exceptions\DatabaseQueryException;
7 use Give\Framework\Migrations\Contracts\Migration;
8 use Give\Framework\Migrations\Contracts\ReversibleMigration;
9 use Give\Framework\Migrations\Exceptions\DatabaseMigrationException;
10
11 /**
12 * @since 4.11.0
13 */
14 class AddCampaignId extends Migration implements ReversibleMigration
15 {
16 /**
17 * @inheritDoc
18 */
19 public static function id(): string
20 {
21 return 'add_campaign_id_to_subscriptions';
22 }
23
24 /**
25 * @inheritDoc
26 */
27 public static function title(): string
28 {
29 return 'Add campaign id to subscriptions';
30 }
31
32 /**
33 * @inheritdoc
34 */
35 public static function timestamp(): string
36 {
37 return strtotime('2025-10-16 00:00:00');
38 }
39
40 /**
41 * @inheritDoc
42 *
43 * @throws DatabaseMigrationException
44 */
45 public function run()
46 {
47 try {
48 $query = <<<SQL
49 UPDATE %s AS subscriptions
50 JOIN %s campaignForms
51 ON subscriptions.product_id = campaignForms.form_id
52 SET subscriptions.campaign_id = campaignForms.campaign_id
53 SQL;
54
55 DB::query(sprintf(
56 $query,
57 DB::prefix('give_subscriptions'),
58 DB::prefix('give_campaign_forms')
59 ));
60 } catch (DatabaseQueryException $exception) {
61 throw new DatabaseMigrationException("An error occurred while adding campaign ID to the give_subscriptions table",
62 0, $exception);
63 }
64 }
65
66
67 /**
68 * @inheritDoc
69 */
70 public function reverse(): void
71 {
72 DB::table('give_subscriptions')->update(['campaign_id' => null]);
73 }
74 }
75