File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Update class for version 1.9.0.
4+ *
5+ * @package Progress_Planner
6+ */
7+
8+ namespace Progress_Planner \Update ;
9+
10+ /**
11+ * Update class for version 1.7.2.
12+ *
13+ * @package Progress_Planner
14+ */
15+ class Update_190 {
16+
17+ const VERSION = '1.9.0 ' ;
18+
19+ /**
20+ * Run the update.
21+ *
22+ * @return void
23+ */
24+ public function run () {
25+ // Migrate the golden task.
26+ $ this ->migrate_golden_todo_task ();
27+ }
28+
29+ /**
30+ * Migrate the golden task.
31+ *
32+ * @return void
33+ */
34+ private function migrate_golden_todo_task () {
35+ // Get all user tasks.
36+ $ tasks = \progress_planner ()->get_suggested_tasks_db ()->get_tasks_by ( [ 'provider_id ' => 'user ' ] );
37+
38+ // Loop through tasks and update the `post_excerpt` if the `prpl_points` meta is set to 1.
39+ global $ wpdb ;
40+ foreach ( $ tasks as $ task ) {
41+ // Get the `prpl_points` meta.
42+ // We'll be getting the value directly from the database since the post-meta is no longer used.
43+ $ points = $ wpdb ->get_var ( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
44+ $ wpdb ->prepare (
45+ "SELECT meta_value FROM {$ wpdb ->postmeta } WHERE post_id = %d AND meta_key = 'prpl_points' " , // @phpstan-ignore-line property.nonObject
46+ $ task ->ID
47+ )
48+ );
49+ if ( 1 === (int ) $ points ) {
50+ \progress_planner ()->get_suggested_tasks_db ()->update_recommendation (
51+ $ task ->ID ,
52+ [ 'post_excerpt ' => 'GOLDEN ' ]
53+ );
54+ }
55+ }
56+ }
57+ }
You can’t perform that action at this time.
0 commit comments