Skip to content

Commit 67ed08d

Browse files
author
Алексей Тихомиров
committed
fix(rest-api): fix getQueueJobs for array jobs and 404 test auth
- Support both objects and arrays in getQueueJobs endpoint - Add admin authorization to 404 test (was getting 403 without auth)
1 parent 2e59f0d commit 67ed08d

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/Admin/RestApi.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,22 @@ public function getQueueJobs(WP_REST_Request $request): WP_REST_Response
211211

212212
$result = [];
213213
foreach ($jobs as $index => $job) {
214-
$result[] = [
215-
'id' => $index,
216-
'class' => get_class($job),
217-
'attempts' => $job->attempts ?? 0,
218-
'available_at' => $job->availableAt ?? time(),
219-
];
214+
// Поддержка как объектов, так и массивов
215+
if (is_object($job)) {
216+
$result[] = [
217+
'id' => $index,
218+
'class' => get_class($job),
219+
'attempts' => $job->attempts ?? 0,
220+
'available_at' => $job->availableAt ?? time(),
221+
];
222+
} else {
223+
$result[] = [
224+
'id' => $index,
225+
'class' => $job['class'] ?? 'Unknown',
226+
'attempts' => $job['attempts'] ?? 0,
227+
'available_at' => $job['available_at'] ?? time(),
228+
];
229+
}
220230
}
221231

222232
return new WP_REST_Response($result);

tests/Feature/RestApiIntegrationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@
248248
});
249249

250250
test('REST API возвращает 404 для несуществующей очереди', function (): void {
251+
// Авторизуемся как администратор для доступа к API
252+
wp_set_current_user(1);
253+
251254
$request = new \WP_REST_Request('GET', '/wp-queue/v1/queues/nonexistent');
252255
$response = rest_do_request($request);
253256

0 commit comments

Comments
 (0)