Scaffold the single file view
This commit is contained in:
parent
7ecb9dfaee
commit
e914b9a2d5
|
@ -166,6 +166,26 @@ class FileController {
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a File instance from a file ID.
|
||||||
|
*
|
||||||
|
* @param string $file_id A file ID (file basename without the hash).
|
||||||
|
*
|
||||||
|
* @return File|WP_Error
|
||||||
|
*/
|
||||||
|
public function get_file_by_id( string $file_id ) {
|
||||||
|
$result = $this->get_files_by_id( array( $file_id ) );
|
||||||
|
|
||||||
|
if ( count( $result ) < 1 ) {
|
||||||
|
return new WP_Error(
|
||||||
|
'wc_log_file_error',
|
||||||
|
esc_html__( 'Could not read the specified file.', 'woocommerce' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return reset( $result );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to get an array of File instances.
|
* Helper method to get an array of File instances.
|
||||||
*
|
*
|
||||||
|
|
|
@ -260,7 +260,7 @@ class ListTable extends WP_List_Table {
|
||||||
$single_file_url = add_query_arg(
|
$single_file_url = add_query_arg(
|
||||||
array(
|
array(
|
||||||
'view' => 'single_file',
|
'view' => 'single_file',
|
||||||
'log_file' => $log_file,
|
'file_id' => $log_file,
|
||||||
),
|
),
|
||||||
$this->page_controller->get_logs_tab_url()
|
$this->page_controller->get_logs_tab_url()
|
||||||
);
|
);
|
||||||
|
|
|
@ -124,7 +124,7 @@ class PageController {
|
||||||
$this->render_file_list_page( $params );
|
$this->render_file_list_page( $params );
|
||||||
break;
|
break;
|
||||||
case 'single_file':
|
case 'single_file':
|
||||||
WC_Admin_Status::status_logs_file();
|
$this->render_single_file_page( $params );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ class PageController {
|
||||||
/**
|
/**
|
||||||
* Render the file list view.
|
* Render the file list view.
|
||||||
*
|
*
|
||||||
* @param array $params Args for rendering the views.
|
* @param array $params Args for rendering the view.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -141,7 +141,7 @@ class PageController {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<h2>
|
<h2>
|
||||||
<?php esc_html_e( 'Log files', 'woocommerce' ); ?>
|
<?php esc_html_e( 'Browse log files', 'woocommerce' ); ?>
|
||||||
</h2>
|
</h2>
|
||||||
<form id="logs-list-table-form" method="get">
|
<form id="logs-list-table-form" method="get">
|
||||||
<input type="hidden" name="page" value="wc-status" />
|
<input type="hidden" name="page" value="wc-status" />
|
||||||
|
@ -161,6 +161,42 @@ class PageController {
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the single file view.
|
||||||
|
*
|
||||||
|
* @param array $params Args for rendering the view.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function render_single_file_page( array $params ): void {
|
||||||
|
$file = $this->file_controller->get_file_by_id( $params['file_id'] );
|
||||||
|
|
||||||
|
if ( is_wp_error( $file ) ) {
|
||||||
|
?>
|
||||||
|
<div class="notice notice-error notice-inline">
|
||||||
|
<p>
|
||||||
|
<?php echo wp_kses_post( $file->get_error_message() ); ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<h2>
|
||||||
|
<?php
|
||||||
|
printf(
|
||||||
|
// translators: %s is the name of a log file.
|
||||||
|
esc_html__( 'Viewing log file %s', 'woocommerce' ),
|
||||||
|
esc_html( $file->get_file_id() )
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default values for URL query params for FileV2 views.
|
* Get the default values for URL query params for FileV2 views.
|
||||||
*
|
*
|
||||||
|
@ -168,6 +204,7 @@ class PageController {
|
||||||
*/
|
*/
|
||||||
public function get_query_param_defaults(): array {
|
public function get_query_param_defaults(): array {
|
||||||
return array(
|
return array(
|
||||||
|
'file_id' => '',
|
||||||
'order' => $this->file_controller::DEFAULTS_GET_FILES['order'],
|
'order' => $this->file_controller::DEFAULTS_GET_FILES['order'],
|
||||||
'orderby' => $this->file_controller::DEFAULTS_GET_FILES['orderby'],
|
'orderby' => $this->file_controller::DEFAULTS_GET_FILES['orderby'],
|
||||||
'source' => $this->file_controller::DEFAULTS_GET_FILES['source'],
|
'source' => $this->file_controller::DEFAULTS_GET_FILES['source'],
|
||||||
|
@ -185,11 +222,17 @@ class PageController {
|
||||||
$params = filter_input_array(
|
$params = filter_input_array(
|
||||||
INPUT_GET,
|
INPUT_GET,
|
||||||
array(
|
array(
|
||||||
'view' => array(
|
'file_id' => array(
|
||||||
|
'filter' => FILTER_CALLBACK,
|
||||||
|
'options' => function( $file_id ) {
|
||||||
|
return sanitize_file_name( $file_id );
|
||||||
|
},
|
||||||
|
),
|
||||||
|
'order' => array(
|
||||||
'filter' => FILTER_VALIDATE_REGEXP,
|
'filter' => FILTER_VALIDATE_REGEXP,
|
||||||
'options' => array(
|
'options' => array(
|
||||||
'regexp' => '/^(list_files|single_file)$/',
|
'regexp' => '/^(asc|desc)$/i',
|
||||||
'default' => $defaults['view'],
|
'default' => $defaults['order'],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'orderby' => array(
|
'orderby' => array(
|
||||||
|
@ -199,19 +242,19 @@ class PageController {
|
||||||
'default' => $defaults['orderby'],
|
'default' => $defaults['orderby'],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'order' => array(
|
|
||||||
'filter' => FILTER_VALIDATE_REGEXP,
|
|
||||||
'options' => array(
|
|
||||||
'regexp' => '/^(asc|desc)$/i',
|
|
||||||
'default' => $defaults['order'],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'source' => array(
|
'source' => array(
|
||||||
'filter' => FILTER_CALLBACK,
|
'filter' => FILTER_CALLBACK,
|
||||||
'options' => function( $source ) {
|
'options' => function( $source ) {
|
||||||
return $this->file_controller->sanitize_source( wp_unslash( $source ) );
|
return $this->file_controller->sanitize_source( wp_unslash( $source ) );
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
'view' => array(
|
||||||
|
'filter' => FILTER_VALIDATE_REGEXP,
|
||||||
|
'options' => array(
|
||||||
|
'regexp' => '/^(list_files|single_file)$/',
|
||||||
|
'default' => $defaults['view'],
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue