PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.4
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.4
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/Core/Importer/LogHelper.php +37 -8 3.1.13.2.4 View file →
@@ -1,8 +1,10 @@
1 1 <?php
2 2
3 3 namespace Templately\Core\Importer;
4 4
5 +use Templately\Core\Importer\Utils\LogHandler;
6 +use Templately\Core\Importer\Utils\Utils;
5 7 use Templately\Utils\Helper;
6 8
7 9 trait LogHelper {
8 10 private $log_types = [
@@ -35,14 +37,10 @@
35 37 }
36 38
37 39 public function sse_message( $data ) {
38 40 // Log the data into debug log file
39 - $this->debug_log( $data );
41 + $this->sse_log_file( $data );
40 42
41 - $log = get_transient( 'templately_fsi_log' ) ?: [];
42 - $log[] = $data;
43 - set_transient( 'templately_fsi_log', $log, 15 * MINUTE_IN_SECONDS );
44 -
45 43 if(Helper::should_flush()){
46 44 echo "event: message\n";
47 45 echo 'data: ' . wp_json_encode( $data ) . "\n\n";
48 46
@@ -49,15 +47,44 @@
49 47 // Extra padding.
50 48 echo esc_html( ':' . str_repeat( ' ', 2048 ) . "\n\n" );
51 49
52 50 flush();
51 + if (ob_get_level() > 0) {
52 + ob_flush();
53 + }
53 54 }
54 - else if($data['action'] === 'complete' || $data['action'] === 'downloadComplete' || $data['action'] === 'error'){
55 - wp_send_json( $data );
56 - }
55 + // else {
56 + // $log = get_option( 'templately_fsi_log' ) ?: [];
57 + // $log[] = $data;
58 + // update_option( 'templately_fsi_log', $log );
59 + // }
60 + // else if($data['action'] === 'complete' || $data['action'] === 'downloadComplete' || $data['action'] === 'error'){
61 + // wp_send_json( $data );
62 + // }
57 63 }
58 64
59 65 /**
66 + * Printing Error Logs in debug.log file or in option.
67 + *
68 + * @param mixed $log
69 + * @return void
70 + */
71 + public function sse_log_file( $log ){
72 + $request_params = Utils::get_session_data_by_id();
73 +
74 + if (is_array($log)) {
75 + $log['timestamp'] = date('Y-m-d H:i:s');
76 + }
77 +
78 + if (isset($request_params['log_type']) && $request_params['log_type'] == 'file') {
79 + LogHandler::sse_log_file($log);
80 + } else {
81 + $_log = get_option('templately_fsi_log') ?: [];
82 + $_log[] = $log;
83 + update_option('templately_fsi_log', $_log, false);
84 + }
85 + }
86 + /**
60 87 * Printing Error Logs in debug.log file.
61 88 *
62 89 * @param mixed $log
63 90 * @return void
@@ -63,12 +90,14 @@
63 90 * @return void
64 91 */
65 92 public function debug_log( $log ){
66 93 if ( defined('TEMPLATELY_EVENT_LOG') && TEMPLATELY_EVENT_LOG === true ) {
94 +
67 95 if ( is_array( $log ) || is_object( $log ) ) {
68 96 error_log( print_r( $log, true ) );
69 97 } else if($log) {
70 98 error_log( $log );
71 99 }
100 +
72 101 }
73 102 }
74 103 }