File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments