PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
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 2.31.0 2.31.1 All 253 releases
give / src / FormMigration / Controllers / TransferController.php

TransferController.php in GiveWP – Donation Plugin and Fundraising Platform 4.1.0, at src/FormMigration/Controllers/TransferController.php

60 lines 1.8 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\Controllers;
4
5 use Give\Campaigns\Repositories\CampaignRepository;
6 use Give\DonationForms\V2\Models\DonationForm;
7 use Give\FormMigration\Actions\GetMigratedFormId;
8 use Give\FormMigration\Actions\TransferDonations;
9 use Give\FormMigration\Actions\TransferFormUrl;
10 use Give\FormMigration\DataTransferObjects\TransferOptions;
11 use Give\Framework\Database\DB;
12 use WP_REST_Request;
13 use WP_REST_Response;
14
15 class TransferController
16 {
17 protected $debugContext;
18
19 /**
20 * @var WP_REST_Request
21 */
22 protected $request;
23
24 public function __construct(WP_REST_Request $request)
25 {
26 $this->request = $request;
27 }
28
29 public function __invoke(DonationForm $formV2, TransferOptions $options)
30 {
31 DB::transaction(function() use ($formV2, $options) {
32
33 $v3FormId = (new GetMigratedFormId)($formV2->id);
34 TransferFormUrl::from($formV2->id)->to($v3FormId);
35 TransferDonations::from($formV2->id)->to($v3FormId);
36
37 // Promote upgraded form to default form
38 $campaignRepository = give(CampaignRepository::class);
39 if ($campaign = $campaignRepository->getByFormId($formV2->id)) {
40 $defaultForm = $campaign->defaultForm();
41
42 if ($defaultForm->id === $formV2->id) {
43 $campaignRepository->updateDefaultCampaignForm($campaign, $v3FormId);
44 }
45 }
46
47 if($options->shouldDelete()) {
48 wp_trash_post($formV2->id);
49 }
50
51 wp_update_post(['ID' => $v3FormId, 'post_status' => $formV2->status->getValue()]);
52 give_update_meta($v3FormId, 'transferredFormId', true);
53 });
54
55 return new WP_REST_Response(array('errors' => [], 'successes' => [
56 $formV2->id
57 ]));
58 }
59 }
60