GetMigratedFormId.php
2 years ago
MapSettingsToDesignHeader.php
2 years ago
MapSettingsToDonationSummary.php
2 years ago
TransferDonations.php
2 years ago
TransferFormUrl.php
2 years ago
TransferDonations.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormMigration\Actions; |
| 4 | |
| 5 | use Give\DonationForms\ValueObjects\DonationFormStatus; |
| 6 | use Give\Framework\Database\DB; |
| 7 | |
| 8 | class TransferDonations |
| 9 | { |
| 10 | protected $sourceId; |
| 11 | |
| 12 | public function __construct($sourceId) |
| 13 | { |
| 14 | $this->sourceId = $sourceId; |
| 15 | } |
| 16 | |
| 17 | public static function from($sourceId): self |
| 18 | { |
| 19 | return new TransferDonations($sourceId); |
| 20 | } |
| 21 | |
| 22 | public function to($destinationId): void |
| 23 | { |
| 24 | $this->__invoke($destinationId); |
| 25 | } |
| 26 | |
| 27 | public function __invoke($destinationId) |
| 28 | { |
| 29 | DB::transaction(function() use ($destinationId) { |
| 30 | |
| 31 | // Mark the v2 form as "upgraded". |
| 32 | DB::table('posts') |
| 33 | ->where('ID', $this->sourceId) |
| 34 | ->update(['post_status' => DonationFormStatus::UPGRADED]); |
| 35 | |
| 36 | DB::table('give_donationmeta') |
| 37 | ->where('meta_key', '_give_payment_form_id') |
| 38 | ->where('meta_value', $this->sourceId) |
| 39 | ->update(['meta_value' => $destinationId]); |
| 40 | |
| 41 | DB::table('give_revenue') |
| 42 | ->where('form_id', $this->sourceId) |
| 43 | ->update(['form_id' => $destinationId]); |
| 44 | |
| 45 | give_update_meta( |
| 46 | $destinationId, |
| 47 | '_give_form_sales', |
| 48 | (int)give_get_meta($this->sourceId, '_give_form_sales', true) |
| 49 | ); |
| 50 | give_update_meta($this->sourceId, '_give_form_sales', 0); |
| 51 | |
| 52 | give_update_meta( |
| 53 | $destinationId, |
| 54 | '_give_form_earnings', |
| 55 | (float)give_get_meta($this->sourceId, '_give_form_earnings', true) |
| 56 | ); |
| 57 | give_update_meta($this->sourceId, '_give_form_earnings', 0); |
| 58 | |
| 59 | }); |
| 60 | } |
| 61 | } |
| 62 |