Page MenuHomePhabricator

Improve donation export query
Open, Needs TriagePublic

Description

NOTE: this ticket needs some rework and simplification

Product perspective

Context

The queries that determine which donations can be exported rely on the deprecated status field, which coalesces different donation status updates into one status. Instead, it should look at the different pieces of information in the donation to determine, which donations can be exported

Acceptance criteria

  • Export works like before, but uses different query

Technical perspective

This ticket is part of an effort to get rid of reliance on the status field, see T359954: Remove status from donation queries

Constraints

This ticket does not change how we store the "Deleted" status of donations - we still rely on the current behavior of the fundraising-donations bounded context that preserves this status correctly in the deprecated status field as "D". We track the change to how the soft-delete works in T359955: Create a deletion flag on the donation database entries. We want to keep the scope of this export ticket low and don't want to block it.

Affected repositories

  • fundraising-backend

Implementation details

Before changing the production code, add a new test in ExportQueryBuilderTest (for Donation\ExportQueryBuilder), that inserts donations and makes a query. Check if the right donations are returned. This is the baseline test that tests the both the legacy and the new functionality. If the test fails at any point, have a good look at the data before you change the production code.
Parameters for DonationExportParameters:

  • addStatus( 'Z' ) to include bank transfer donations
  • setMarkerField('dt_gruen')

Parameters for ExportOptions - call setExportUntil with a date that catches most donations
Donations to insert that should be in the result set:

  • Bank Transfer donation
  • Direct Debit donation
  • Booked PayPal Donation
  • Booked Credit Card Donation

Donations to insert that should NOT be in the result set:

  • exported Bank Transfer donation
  • exported Direct Debit donation
  • exported Booked PayPal Donation
  • exported Booked Credit Card Donation
  • Bank Transfer donation with moderation
  • Direct Debit donation with moderation
  • Booked PayPal Donation with moderation
  • Booked Credit Card Donation with moderation
  • deleted Bank Transfer donation
  • deleted Direct Debit donation
  • Bank Transfer donation with a date outside of the range set in setExportuntil

You can use the donation fixtures in tests/Fixtures/Doctrine to build these. Make sure that both the status field *and* the payment and moderation entries are set correctly so the test works both for the legacy behavior and the new behavior.

Change the query in Donation\ExportQueryBuilder as follows:

  • Left-join the donations_moderation_reasons table. left-joining will ensure that all donations will be selected, regardless if they have moderation flags or not.
  • do not query status IN (...) any more (ignore DonationExportParameters::getStatuses() and DonationExportParameters::doIgnoreStatus). Instead, there are three new selection criteria (AND-combined):
    • Payment Status:
      • where payment_method == "BEZ" OR
      • where payment_method == "UEB" OR
      • where payment_method == "PPL" AND payment_paypal.valuation_date IS NOT NULL OR
      • where payment_method == "MCP" AND payment_credit_card.valuation_date IS NOT NULL
    • Moderation status (must not be in moderation queue)
      • donations_moderation_reasons.donation_id IS NULL. This will exclude all donations with a moderation flag
    • Deletion status:
      • We keep the deletion flag in the status field for now. This means you have to add a criterion with spenden.status !="D"