AddCampaignId.php
8 months ago
AddCampaignIdColumn.php
8 months ago
AddPaymentModeToSubscriptionTable.php
3 years ago
BackfillMissingCampaignIdForDonations.php
1 year ago
CreateSubscriptionTables.php
4 years ago
UpdateProductID.php
8 months ago
UpdateProductID.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Subscriptions\Migrations; |
| 4 | |
| 5 | use Give\Donations\ValueObjects\DonationMetaKeys; |
| 6 | use Give\Framework\Database\DB; |
| 7 | use Give\Framework\Database\Exceptions\DatabaseQueryException; |
| 8 | use Give\Framework\Migrations\Contracts\Migration; |
| 9 | use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; |
| 10 | |
| 11 | /** |
| 12 | * @since 4.12.0 |
| 13 | * |
| 14 | * During the v2 form data transfer to the v3 form |
| 15 | * we update the _give_payment_form_id in donations meta table to reference the new v3 form id |
| 16 | * but that update was not reflected in give_subscriptions.product_id prior to this migration |
| 17 | * |
| 18 | * This migration will update all subscriptions that do not have the correct product_id value |
| 19 | */ |
| 20 | class UpdateProductID extends Migration |
| 21 | { |
| 22 | /** |
| 23 | * @inheritDoc |
| 24 | */ |
| 25 | public static function id(): string |
| 26 | { |
| 27 | return 'update_transferred_subscriptions_product_id'; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @inheritDoc |
| 32 | */ |
| 33 | public static function title(): string |
| 34 | { |
| 35 | return 'Update subscriptions to reflect the v2 form data transfer to the v3 form'; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @inheritdoc |
| 40 | */ |
| 41 | public static function timestamp(): string |
| 42 | { |
| 43 | return strtotime('2025-10-15 00:00:00'); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @inheritDoc |
| 48 | * |
| 49 | * @throws DatabaseMigrationException |
| 50 | */ |
| 51 | public function run() |
| 52 | { |
| 53 | try { |
| 54 | $query = <<<SQL |
| 55 | UPDATE %s AS subscriptions |
| 56 | INNER JOIN %s revenue |
| 57 | ON subscriptions.parent_payment_id = revenue.donation_id |
| 58 | SET subscriptions.product_id = revenue.form_id |
| 59 | WHERE subscriptions.product_id != revenue.form_id |
| 60 | SQL; |
| 61 | |
| 62 | DB::query(sprintf( |
| 63 | $query, |
| 64 | DB::prefix('give_subscriptions'), |
| 65 | DB::prefix('give_revenue') |
| 66 | )); |
| 67 | } catch (DatabaseQueryException $exception) { |
| 68 | throw new DatabaseMigrationException("An error occurred while updating the give_subscriptions table", |
| 69 | 0, $exception); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 |