-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'epic/donation-amount-level-descriptions' into feature/l…
…evel-descriptions-frontend-ui
- Loading branch information
Showing
18 changed files
with
305 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/DonationForms/Migrations/UpdateDonationLevelsSchema.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Give\DonationForms\Migrations; | ||
|
||
use Give\DonationForms\Repositories\DonationFormRepository; | ||
use Give\Framework\Migrations\Contracts\Migration; | ||
|
||
/** | ||
* Update the donation levels schema to support descriptions | ||
* | ||
* @unreleased | ||
*/ | ||
class UpdateDonationLevelsSchema extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function id() | ||
{ | ||
return 'donation-forms-donation-levels-schema'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function title() | ||
{ | ||
return 'Update Donation Levels schema to support descriptions'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function timestamp() | ||
{ | ||
return strtotime('2024-04-22'); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function run() | ||
{ | ||
$forms = give(DonationFormRepository::class) | ||
->prepareQuery() | ||
->whereIsNotNull("give_formmeta_attach_meta_fields.meta_value") | ||
->getAll(); | ||
|
||
if ( ! $forms) { | ||
return; | ||
} | ||
|
||
foreach ($forms as $form) { | ||
$amountBlock = $form->blocks->findByName('givewp/donation-amount'); | ||
|
||
if ( ! $amountBlock) { | ||
continue; | ||
} | ||
|
||
$blockAttributes = $amountBlock->getAttributes(); | ||
$levels = $blockAttributes["levels"]; | ||
$defaultLevel = $blockAttributes["defaultLevel"] ?? 0; | ||
|
||
if ( ! is_array($levels) || empty($levels) || isset($levels[0]['value'])) { | ||
continue; | ||
} | ||
|
||
$levels = array_map(function($level) use ($defaultLevel) { | ||
return [ | ||
'value' => $level, | ||
'label' => '', | ||
'checked' => $level === $defaultLevel, | ||
]; | ||
}, $levels); | ||
|
||
$amountBlock->setAttribute('levels', $levels); | ||
$form->save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.