| 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.4 preserve additional donation level data |
| 13 |
* @since 2.13.3 |
| 14 |
*/ |
| 15 |
class SetFormDonationLevelsToStrings extends Migration |
| 16 |
{ |
| 17 |
/** |
| 18 |
* @var FormRepository |
| 19 |
*/ |
| 20 |
private $formRepository; |
| 21 |
|
| 22 |
/** |
| 23 |
* @inheritDoc |
| 24 |
*/ |
| 25 |
public static function id() |
| 26 |
{ |
| 27 |
return 'set-form-donation-levels-to-strings'; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* @inheritDoc |
| 32 |
*/ |
| 33 |
public static function timestamp() |
| 34 |
{ |
| 35 |
return strtotime('2020-09-01 11:47:00'); |
| 36 |
} |
| 37 |
|
| 38 |
public function __construct(FormRepository $formRepository) |
| 39 |
{ |
| 40 |
$this->formRepository = $formRepository; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* @inheritDoc |
| 45 |
*/ |
| 46 |
public function run() |
| 47 |
{ |
| 48 |
$formId = $this->formRepository->getDefaultFormID(); |
| 49 |
|
| 50 |
if (empty($formId)) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
$donationLevels = give_get_meta($formId, '_give_donation_levels', true); |
| 55 |
|
| 56 |
foreach ($donationLevels as &$level) { |
| 57 |
$level['_give_id']['level_id'] = (string)$level['_give_id']['level_id']; |
| 58 |
$level['_give_amount'] = give_sanitize_amount_for_db($level['_give_amount']); |
| 59 |
} |
| 60 |
unset($level); |
| 61 |
|
| 62 |
update_post_meta($formId, '_give_donation_levels', $donationLevels); |
| 63 |
} |
| 64 |
} |
| 65 |
|