← Back
Editing: UpdateProductID.php
<?php namespace Give\Subscriptions\Migrations; use Give\Donations\ValueObjects\DonationMetaKeys; use Give\Framework\Database\DB; use Give\Framework\Database\Exceptions\DatabaseQueryException; use Give\Framework\Migrations\Contracts\Migration; use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; /** * @since 4.12.0 * * During the v2 form data transfer to the v3 form * we update the _give_payment_form_id in donations meta table to reference the new v3 form id * but that update was not reflected in give_subscriptions.product_id prior to this migration * * This migration will update all subscriptions that do not have the correct product_id value */ class UpdateProductID extends Migration { /** * @inheritDoc */ public static function id(): string { return 'update_transferred_subscriptions_product_id'; } /** * @inheritDoc */ public static function title(): string { return 'Update subscriptions to reflect the v2 form data transfer to the v3 form'; } /** * @inheritdoc */ public static function timestamp(): string { return strtotime('2025-10-15 00:00:00'); } /** * @since 4.20.0 Use a plain string in place of a heredoc for the SQL. * @since 4.19.1 Escape exception message. * @inheritDoc * * @throws DatabaseMigrationException */ public function run() { try { $query = " UPDATE %s AS subscriptions INNER JOIN %s revenue ON subscriptions.parent_payment_id = revenue.donation_id SET subscriptions.product_id = revenue.form_id WHERE subscriptions.product_id != revenue.form_id"; DB::query(sprintf( $query, DB::prefix('give_subscriptions'), DB::prefix('give_revenue') )); } catch (DatabaseQueryException $exception) { throw new DatabaseMigrationException("An error occurred while updating the give_subscriptions table", 0, $exception); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- $previous is a Throwable passed through for the stack trace, not output. } } }
Save File
Cancel