diff --git a/src/Campaigns/Migrations/MigrateFormsToCampaignForms.php b/src/Campaigns/Migrations/MigrateFormsToCampaignForms.php index 059bc736d5..13d85c064a 100644 --- a/src/Campaigns/Migrations/MigrateFormsToCampaignForms.php +++ b/src/Campaigns/Migrations/MigrateFormsToCampaignForms.php @@ -70,6 +70,7 @@ protected function getFormData(): array }) ->where('formmeta.meta_key', 'formBuilderSettings'); + // Exclude forms already associated with a campaign (ie Peer-to-peer). $query->join(function (JoinQueryBuilder $builder) { $builder ->leftJoin('give_campaigns', 'campaigns') @@ -77,6 +78,9 @@ protected function getFormData(): array }) ->whereIsNull('campaigns.id'); + // Exclude forms with an `upgraded` status, which are archived. + $query->where('forms.post_status', 'upgraded', '!='); + return $query->getAll(); } @@ -133,7 +137,6 @@ public function mapFormToCampaignStatus(string $status): string case 'publish': case 'private': - case 'upgraded': return 'active'; default: // TODO: How do we handle an unknown form status? diff --git a/tests/Unit/Campaigns/Migrations/MigrateFormsToCampaignFormsTest.php b/tests/Unit/Campaigns/Migrations/MigrateFormsToCampaignFormsTest.php index c8b4ab4dca..4b84018f94 100644 --- a/tests/Unit/Campaigns/Migrations/MigrateFormsToCampaignFormsTest.php +++ b/tests/Unit/Campaigns/Migrations/MigrateFormsToCampaignFormsTest.php @@ -4,8 +4,8 @@ use Give\Campaigns\Migrations\MigrateFormsToCampaignForms; use Give\Campaigns\Models\Campaign; -use Give\Campaigns\ValueObjects\CampaignType; use Give\DonationForms\Models\DonationForm; +use Give\DonationForms\ValueObjects\DonationFormStatus; use Give\Framework\Database\DB; use Give\Tests\TestCase; use Give\Tests\TestTraits\RefreshDatabase; @@ -48,4 +48,19 @@ public function testExistingPeerToPeerCampaignFormsAreNotMigrated() $this->assertNull($relationship); $this->assertEquals(1, DB::table('give_campaigns')->count()); } + + public function testUpgradedFormsAreNotMigrated() + { + $form = DonationForm::factory()->create([ + 'status' => DonationFormStatus::UPGRADED(), + ]); + + $migration = new MigrateFormsToCampaignForms(); + $migration->run(); + + $relationship = DB::table('give_campaign_forms')->where('form_id', $form->id)->get(); + + $this->assertNull($relationship); + $this->assertEquals(0, DB::table('give_campaigns')->count()); + } }