Skip to content

Commit f0bc05b

Browse files
committed
add badge migration
1 parent 86ba9b0 commit f0bc05b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

classes/update/class-update-161.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,39 @@ class Update_161 {
2222
* @return void
2323
*/
2424
public function run() {
25+
// Migrate the badges.
26+
$this->migrate_badges();
27+
28+
// Migrate the tasks.
2529
$this->migrate_tasks();
2630
}
2731

32+
/**
33+
* Migrate the badges.
34+
*
35+
* @return void
36+
*/
37+
private function migrate_badges() {
38+
// Get all badges.
39+
$badges = \progress_planner()->get_settings()->get( 'badges', [] );
40+
41+
foreach ( $badges as $badge_id => $badge ) {
42+
43+
// We are only migrating monthly badges.
44+
if ( 0 !== strpos( $badge_id, 'monthly-' ) ) {
45+
continue;
46+
}
47+
48+
if ( ! isset( $badges[ $badge_id ]['points'] ) ) {
49+
// We are just adding the points to the badge, for the new data structure - 10 is the max points for a badge.
50+
$badges[ $badge_id ]['points'] = 10 - (int) $badge['remaining'];
51+
}
52+
}
53+
54+
// Set the badges.
55+
\progress_planner()->get_settings()->set( 'badges', $badges );
56+
}
57+
2858
/**
2959
* Migrate the tasks.
3060
*

0 commit comments

Comments
 (0)