Skip to content

Commit a925460

Browse files
committed
Refactor ViewLogsPage to use LogServiceInterface
Replaces direct usage of LogsRepository with LogServiceInterface in ViewLogsPage for improved abstraction and flexibility. Updates method to retrieve logs via the log service and adds a protected getter for the log service instance. Removes unused LogsRepository import from the related test file.
1 parent b29d376 commit a925460

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

plugins/wpgraphql-logging/src/Admin/ViewLogsPage.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
use WPGraphQL\Logging\Admin\View\Download\DownloadLogService;
88
use WPGraphQL\Logging\Admin\View\List\ListTable;
9+
use WPGraphQL\Logging\Logger\Api\LogServiceInterface;
910
use WPGraphQL\Logging\Logger\Database\LogsRepository;
11+
use WPGraphQL\Logging\Logger\Store\LogStoreService;
1012

1113
/**
1214
* The view logs page class for WPGraphQL Logging.
@@ -196,7 +198,7 @@ public function process_filters_redirect(): void {
196198
* @return string The constructed redirect URL.
197199
*/
198200
public function get_redirect_url(): string {
199-
$redirect_url = menu_page_url( self::ADMIN_PAGE_SLUG, false );
201+
$redirect_url = menu_page_url( self::ADMIN_PAGE_SLUG, false );
200202

201203
$possible_filters = [
202204
'start_date',
@@ -276,8 +278,8 @@ protected function render_view_page(): void {
276278
return;
277279
}
278280

279-
$repository = new LogsRepository();
280-
$log = $repository->get_log( $log_id );
281+
$log_service = $this->get_log_service();
282+
$log = $log_service->find_entity_by_id( $log_id );
281283

282284
if ( is_null( $log ) ) {
283285
echo '<div class="notice notice-error"><p>' . esc_html__( 'Log not found.', 'wpgraphql-logging' ) . '</p></div>';
@@ -291,4 +293,13 @@ protected function render_view_page(): void {
291293

292294
require_once $log_template; // @phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
293295
}
296+
297+
/**
298+
* Retrieves the log service instance.
299+
*
300+
* @return \WPGraphQL\Logging\Logger\Api\LogServiceInterface The log service instance.
301+
*/
302+
protected function get_log_service(): LogServiceInterface {
303+
return LogStoreService::get_log_service();
304+
}
294305
}

plugins/wpgraphql-logging/tests/wpunit/Admin/View/ViewLogsPageTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
use WPGraphQL\Logging\Admin\ViewLogsPage;
9-
use WPGraphQL\Logging\Logger\Database\LogsRepository;
109
use Codeception\TestCase\WPTestCase;
1110
use Brain\Monkey;
1211

0 commit comments

Comments
 (0)