Skip to content

Commit

Permalink
refactor: Exclude upgraded forms from migration
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohnson committed Sep 9, 2024
1 parent 7ec7b59 commit fe3f605
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Campaigns/Migrations/MigrateFormsToCampaignForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ 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')
->on('campaigns.form_id', 'forms.ID');
})
->whereIsNull('campaigns.id');

// Exclude forms with an `upgraded` status, which are archived.
$query->where('forms.post_status', 'upgraded', '!=');

return $query->getAll();
}

Expand Down Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit fe3f605

Please sign in to comment.