first commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
use WPML\API\Sanitize;
|
||||
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
class WPML_XML_Config_Log_Notice {
|
||||
const NOTICE_ERROR_GROUP = 'wpml-config-update';
|
||||
const NOTICE_ERROR_ID = 'wpml-config-update-error';
|
||||
|
||||
/** @var WPML_Config_Update_Log */
|
||||
private $log;
|
||||
|
||||
public function __construct( WPML_Log $log ) {
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
public function add_hooks() {
|
||||
if ( is_admin() ) {
|
||||
add_action( 'wpml_loaded', array( $this, 'refresh_notices' ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function refresh_notices() {
|
||||
$notices = wpml_get_admin_notices();
|
||||
|
||||
if ( $this->log->is_empty() ) {
|
||||
$notices->remove_notice( self::NOTICE_ERROR_GROUP, self::NOTICE_ERROR_ID );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$text = '<p>' . esc_html__( 'WPML could not load configuration files, which your site needs.', 'sitepress' ) . '</p>';
|
||||
|
||||
$notice = $notices->create_notice( self::NOTICE_ERROR_ID, $text, self::NOTICE_ERROR_GROUP );
|
||||
$notice->set_css_class_types( array( 'error' ) );
|
||||
|
||||
$log_url = add_query_arg( array( 'page' => WPML_Config_Update_Log::get_support_page_log_section() ), get_admin_url( null, 'admin.php#xml-config-log' ) );
|
||||
|
||||
$show_logs = $notices->get_new_notice_action( __( 'Detailed error log', 'sitepress' ), $log_url );
|
||||
|
||||
$return_url = null;
|
||||
if ( $this->is_admin_user_action() ) {
|
||||
$admin_uri = preg_replace( '#^/wp-admin/#', '', $_SERVER['SCRIPT_NAME'] );
|
||||
$return_url = get_admin_url( null, $admin_uri );
|
||||
|
||||
$return_url_qs = $_GET;
|
||||
unset( $return_url_qs[ self::NOTICE_ERROR_GROUP . '-action' ], $return_url_qs[ self::NOTICE_ERROR_GROUP . '-nonce' ] );
|
||||
$return_url = add_query_arg( $return_url_qs, $return_url );
|
||||
}
|
||||
|
||||
$retry_url = add_query_arg(
|
||||
array(
|
||||
self::NOTICE_ERROR_GROUP . '-action' => 'wpml_xml_update_refresh',
|
||||
self::NOTICE_ERROR_GROUP . '-nonce' => wp_create_nonce( 'wpml_xml_update_refresh' ),
|
||||
),
|
||||
$return_url
|
||||
);
|
||||
$retry = $notices->get_new_notice_action( __( 'Retry', 'sitepress' ), $retry_url, false, false, true );
|
||||
|
||||
$notice->add_action( $show_logs );
|
||||
$notice->add_action( $retry );
|
||||
$notice->set_dismissible( true );
|
||||
$notice->set_restrict_to_page_prefixes(
|
||||
array(
|
||||
'sitepress-multilingual-cms',
|
||||
'wpml-translation-management',
|
||||
'wpml-package-management',
|
||||
'wpml-string-translation',
|
||||
)
|
||||
);
|
||||
|
||||
$notice->set_restrict_to_screen_ids( array( 'dashboard', 'plugins', 'themes' ) );
|
||||
$notice->add_exclude_from_page( WPML_Config_Update_Log::get_support_page_log_section() );
|
||||
$notices->add_notice( $notice );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function is_admin_user_action() {
|
||||
return is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX )
|
||||
&& ( 'heartbeat' !== Sanitize::stringProp( 'action', $_POST ) )
|
||||
&& ( ! defined( 'DOING_CRON' ) || ! DOING_CRON );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
class WPML_XML_Config_Log_Factory {
|
||||
private $log;
|
||||
|
||||
function create_log() {
|
||||
if ( ! $this->log ) {
|
||||
$this->log = new WPML_Config_Update_Log();
|
||||
}
|
||||
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
function create_ui() {
|
||||
$template_paths = array(
|
||||
WPML_PLUGIN_PATH . '/templates/xml-config/log/',
|
||||
);
|
||||
|
||||
$template_loader = new WPML_Twig_Template_Loader( $template_paths );
|
||||
$template_service = $template_loader->get_template();
|
||||
|
||||
return new WPML_XML_Config_Log_UI( $this->create_log(), $template_service );
|
||||
}
|
||||
|
||||
function create_notice() {
|
||||
return new WPML_XML_Config_Log_Notice( $this->create_log() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
class WPML_XML_Config_Log_UI {
|
||||
/** @var IWPML_Template_Service */
|
||||
private $template_service;
|
||||
/**
|
||||
* @var \WPML_Config_Update_Log
|
||||
*/
|
||||
private $log;
|
||||
|
||||
function __construct( WPML_Config_Update_Log $log, IWPML_Template_Service $template_service ) {
|
||||
$this->log = $log;
|
||||
$this->template_service = $template_service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function show() {
|
||||
$model = $this->get_model();
|
||||
|
||||
return $this->template_service->show( $model, 'main.twig' );
|
||||
}
|
||||
|
||||
/** @return array */
|
||||
private function get_model() {
|
||||
$entries = $this->log->get();
|
||||
krsort( $entries );
|
||||
|
||||
$table_data = array();
|
||||
$columns = array();
|
||||
foreach ( $entries as $entry ) {
|
||||
$columns += array_keys( $entry );
|
||||
}
|
||||
$columns = array_unique( $columns );
|
||||
|
||||
foreach ( $entries as $timestamp => $entry ) {
|
||||
$table_row = array( 'timestamp' => $this->getDateTimeFromMicroseconds( $timestamp ) );
|
||||
|
||||
foreach ( $columns as $column ) {
|
||||
$table_row[ $column ] = null;
|
||||
if ( array_key_exists( $column, $entry ) ) {
|
||||
$table_row[ $column ] = $entry[ $column ];
|
||||
}
|
||||
}
|
||||
$table_data[] = $table_row;
|
||||
}
|
||||
|
||||
array_unshift( $columns, 'timestamp' );
|
||||
|
||||
$model = array(
|
||||
'strings' => array(
|
||||
'title' => __( 'Remote XML Config Log', 'sitepress' ),
|
||||
'message' => __( "WPML needs to load configuration files, which tell it how to translate your theme and the plugins that you use. If there's a problem, use the Retry button. If the problem continues, contact WPML support, show the error details and we'll help you resolve it.", 'sitepress' ),
|
||||
'details' => __( 'Details', 'sitepress' ),
|
||||
'empty_log' => __( 'The remote XML Config Log is empty', 'sitepress' ),
|
||||
),
|
||||
'buttons' => array(
|
||||
'retry' => array(
|
||||
'label' => __( 'Retry', 'sitepress' ),
|
||||
'url' => null,
|
||||
'type' => 'primary',
|
||||
),
|
||||
'clear' => array(
|
||||
'label' => __( 'Clear log', 'sitepress' ),
|
||||
'url' => null,
|
||||
'type' => 'secondary',
|
||||
),
|
||||
),
|
||||
'columns' => $columns,
|
||||
'entries' => $table_data,
|
||||
);
|
||||
|
||||
if ( $table_data ) {
|
||||
$clear_log_url = add_query_arg(
|
||||
array(
|
||||
WPML_XML_Config_Log_Notice::NOTICE_ERROR_GROUP . '-action' => 'wpml_xml_update_clear',
|
||||
WPML_XML_Config_Log_Notice::NOTICE_ERROR_GROUP . '-nonce' => wp_create_nonce( 'wpml_xml_update_clear' ),
|
||||
),
|
||||
$this->log->get_log_url()
|
||||
);
|
||||
$model['buttons']['clear']['url'] = $clear_log_url;
|
||||
|
||||
$retry_url = add_query_arg(
|
||||
array(
|
||||
WPML_XML_Config_Log_Notice::NOTICE_ERROR_GROUP . '-action' => 'wpml_xml_update_refresh',
|
||||
WPML_XML_Config_Log_Notice::NOTICE_ERROR_GROUP . '-nonce' => wp_create_nonce( 'wpml_xml_update_refresh' ),
|
||||
),
|
||||
$this->log->get_log_url()
|
||||
);
|
||||
$model['buttons']['retry']['url'] = $retry_url;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
private function getDateTimeFromMicroseconds( $time ) {
|
||||
$dFormat = 'Y-m-d H:i:s';
|
||||
|
||||
if ( strpos( $time, '.' ) === false ) {
|
||||
return $time;
|
||||
}
|
||||
|
||||
list( $sec, $usec ) = explode( '.', $time ); // split the microtime on .
|
||||
|
||||
return date( $dFormat, $sec ) . $usec;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user