PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / FormMigration / Actions / TransferDonations.php

TransferDonations.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/FormMigration/Actions/TransferDonations.php

67 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // Update subscriptions to use v3 form ID
46 DB::table('give_subscriptions')
47 ->where('product_id', $this->sourceId)
48 ->update(['product_id' => $destinationId]);
49
50 give_update_meta(
51 $destinationId,
52 '_give_form_sales',
53 (int)give_get_meta($this->sourceId, '_give_form_sales', true)
54 );
55 give_update_meta($this->sourceId, '_give_form_sales', 0);
56
57 give_update_meta(
58 $destinationId,
59 '_give_form_earnings',
60 (float)give_get_meta($this->sourceId, '_give_form_earnings', true)
61 );
62 give_update_meta($this->sourceId, '_give_form_earnings', 0);
63
64 });
65 }
66 }
67