SetFormDonationLevelsToStrings.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Onboarding\Migrations; |
| 4 | |
| 5 | use Give\Framework\Migrations\Contracts\Migration; |
| 6 | use Give\Onboarding\FormRepository; |
| 7 | |
| 8 | /** |
| 9 | * This resolves an issue where the donation level data for the form created during onboarding was serialized as |
| 10 | * integers instead of strings, causing issues throughout |
| 11 | * |
| 12 | * @since 2.13.3 |
| 13 | */ |
| 14 | class SetFormDonationLevelsToStrings extends Migration |
| 15 | { |
| 16 | /** |
| 17 | * @var FormRepository |
| 18 | */ |
| 19 | private $formRepository; |
| 20 | |
| 21 | /** |
| 22 | * @inheritDoc |
| 23 | */ |
| 24 | public static function id() |
| 25 | { |
| 26 | return 'set-form-donation-levels-to-strings'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | */ |
| 32 | public static function timestamp() |
| 33 | { |
| 34 | return strtotime('2020-09-01 11:47:00'); |
| 35 | } |
| 36 | |
| 37 | public function __construct(FormRepository $formRepository) |
| 38 | { |
| 39 | $this->formRepository = $formRepository; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @inheritDoc |
| 44 | */ |
| 45 | public function run() |
| 46 | { |
| 47 | $formId = $this->formRepository->getDefaultFormID(); |
| 48 | |
| 49 | if (empty($formId)) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | $donationLevels = give_get_meta($formId, '_give_donation_levels', true); |
| 54 | |
| 55 | $updatedLevels = []; |
| 56 | foreach ($donationLevels as $level) { |
| 57 | $updatedLevels[] = [ |
| 58 | '_give_id' => [ |
| 59 | 'level_id' => (string)$level['_give_id']['level_id'], |
| 60 | ], |
| 61 | '_give_amount' => give_sanitize_amount_for_db($level['_give_amount']), |
| 62 | ]; |
| 63 | } |
| 64 | |
| 65 | update_post_meta($formId, '_give_donation_levels', $updatedLevels); |
| 66 | } |
| 67 | } |
| 68 |