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 / DonationForms / Migrations / UpdateDonationLevelsSchema.php

UpdateDonationLevelsSchema.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/DonationForms/Migrations/UpdateDonationLevelsSchema.php

81 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\DonationForms\Migrations;
4
5 use Give\DonationForms\Repositories\DonationFormRepository;
6 use Give\Framework\Migrations\Contracts\Migration;
7
8 /**
9 * Update the donation levels schema to support descriptions
10 *
11 * @since 3.12.0
12 */
13 class UpdateDonationLevelsSchema extends Migration
14 {
15 /**
16 * @inheritdoc
17 */
18 public static function id()
19 {
20 return 'donation-forms-donation-levels-schema';
21 }
22
23 /**
24 * @inheritdoc
25 */
26 public static function title()
27 {
28 return 'Update Donation Levels schema to support descriptions';
29 }
30
31 /**
32 * @inheritdoc
33 */
34 public static function timestamp()
35 {
36 return strtotime('2024-04-22');
37 }
38
39 /**
40 * @since 3.12.0
41 */
42 public function run()
43 {
44 $forms = give(DonationFormRepository::class)
45 ->prepareQuery()
46 ->whereIsNotNull("give_formmeta_attach_meta_fields.meta_value")
47 ->getAll();
48
49 if ( ! $forms) {
50 return;
51 }
52
53 foreach ($forms as $form) {
54 $amountBlock = $form->blocks->findByName('givewp/donation-amount');
55
56 if ( ! $amountBlock) {
57 continue;
58 }
59
60 $blockAttributes = $amountBlock->getAttributes();
61 $levels = $blockAttributes["levels"];
62 $defaultLevel = $blockAttributes["defaultLevel"] ?? 0;
63
64 if ( ! is_array($levels) || empty($levels) || isset($levels[0]['value'])) {
65 continue;
66 }
67
68 $levels = array_map(function($level) use ($defaultLevel) {
69 return [
70 'value' => $level,
71 'label' => '',
72 'checked' => $level === $defaultLevel,
73 ];
74 }, $levels);
75
76 $amountBlock->setAttribute('levels', $levels);
77 $form->save();
78 }
79 }
80 }
81