|
3 | 3 | namespace Give\FormMigration\Controllers; |
4 | 4 |
|
5 | 5 | use Give\Campaigns\Repositories\CampaignRepository; |
| 6 | +use Give\Campaigns\ValueObjects\CampaignType; |
6 | 7 | use Give\DonationForms\V2\Models\DonationForm; |
7 | 8 | use Give\FormMigration\Concerns\Blocks\BlockDifference; |
8 | 9 | use Give\FormMigration\DataTransferObjects\FormMigrationPayload; |
9 | 10 | use Give\FormMigration\Pipeline; |
10 | 11 | use Give\Framework\Blocks\BlockModel; |
| 12 | +use Give\Framework\Database\DB; |
11 | 13 | use Give\Log\Log; |
12 | 14 | use WP_REST_Request; |
13 | 15 | use WP_REST_Response; |
@@ -56,19 +58,35 @@ public function __invoke(DonationForm $formV2) |
56 | 58 | $campaignRepository = give(CampaignRepository::class); |
57 | 59 | if ($campaign = $campaignRepository->getByFormId($payload->formV2->id)) { |
58 | 60 | $campaignRepository->addCampaignForm($campaign, $payload->formV3->id); |
| 61 | + } else { |
| 62 | + // Fallback: Check for non-core campaigns (e.g., P2P) linked via give_campaigns.form_id |
| 63 | + $campaignData = DB::table('give_campaigns') |
| 64 | + ->where('form_id', $payload->formV2->id) |
| 65 | + ->where('campaign_type', CampaignType::CORE, '!=') |
| 66 | + ->get(); |
| 67 | + |
| 68 | + if ($campaignData) { |
| 69 | + DB::table('give_campaign_forms') |
| 70 | + ->insert([ |
| 71 | + 'form_id' => $payload->formV3->id, |
| 72 | + 'campaign_id' => $campaignData->id, |
| 73 | + ]); |
| 74 | + } |
59 | 75 | } |
60 | 76 |
|
61 | 77 | Log::info(esc_html__('Form migrated from v2 to v3.', 'give'), $this->debugContext); |
62 | 78 | }); |
63 | 79 |
|
| 80 | + $redirectArgs = apply_filters('givewp_form_migration_redirect_args', [ |
| 81 | + 'post_type' => 'give_forms', |
| 82 | + 'page' => 'givewp-form-builder', |
| 83 | + 'donationFormID' => $payload->formV3->id, |
| 84 | + ], $payload->formV2->id, $payload->formV3->id); |
| 85 | + |
64 | 86 | return new WP_REST_Response([ |
65 | 87 | 'v2FormId' => $payload->formV2->id, |
66 | 88 | 'v3FormId' => $payload->formV3->id, |
67 | | - 'redirect' => add_query_arg([ |
68 | | - 'post_type' => 'give_forms', |
69 | | - 'page' => 'givewp-form-builder', |
70 | | - 'donationFormID' => $payload->formV3->id, |
71 | | - ], admin_url('edit.php')), |
| 89 | + 'redirect' => add_query_arg($redirectArgs, admin_url('edit.php')), |
72 | 90 | ]); |
73 | 91 | } |
74 | 92 | } |
0 commit comments