Skip to content

Commit 35e6f45

Browse files
committed
Try to fix the phpunit test again
1 parent ccc18b2 commit 35e6f45

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

classes/update/class-update-190.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,30 @@ private function migrate_recommendations_slugs() {
5353
continue;
5454
}
5555

56+
// Get the target slug.
57+
$target_slug = \progress_planner()->get_suggested_tasks()->get_task_id_from_slug( $prpl_task_id );
58+
5659
// Check if there are any existing posts with the same slug.
5760
$existing_posts = \get_posts(
5861
[
5962
'post_type' => 'prpl_recommendations',
60-
'name' => \progress_planner()->get_suggested_tasks()->get_task_id_from_slug( $prpl_task_id ),
63+
'name' => $target_slug,
6164
]
6265
);
6366
if ( ! empty( $existing_posts ) && $existing_posts[0]->ID !== $recommendation->ID ) {
6467
// Delete the existing post (but not if it's the current one).
6568
\wp_delete_post( $existing_posts[0]->ID, true );
6669
}
6770

68-
// Set the slug.
69-
\wp_update_post(
70-
[
71-
'ID' => $recommendation->ID,
72-
'post_name' => \progress_planner()->get_suggested_tasks()->get_task_id_from_slug( $prpl_task_id ),
73-
]
74-
);
71+
// Only update if the slug is different from the current slug.
72+
if ( $recommendation->post_name !== $target_slug ) {
73+
\wp_update_post(
74+
[
75+
'ID' => $recommendation->ID,
76+
'post_name' => $target_slug,
77+
]
78+
);
79+
}
7580
}
7681
}
7782

@@ -194,10 +199,18 @@ public function migrate_task_priorities() {
194199

195200
// Update the menu_order for each task.
196201
foreach ( $tasks as $task ) {
202+
// Refresh the task data to ensure we have the latest menu_order value.
203+
$refreshed_task = \get_post( $task->ID );
204+
205+
// Skip if the post no longer exists.
206+
if ( ! $refreshed_task ) {
207+
continue;
208+
}
209+
197210
// Only update if the menu_order is different from the current priority.
198-
if ( (int) $task->menu_order !== $priority ) {
211+
if ( (int) $refreshed_task->menu_order !== $priority ) {
199212
\progress_planner()->get_suggested_tasks_db()->update_recommendation(
200-
$task->ID,
213+
$refreshed_task->ID,
201214
[ 'menu_order' => $priority ]
202215
);
203216
}

0 commit comments

Comments
 (0)