PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.4
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.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 +80 -8 3.0.43.4.4 View file →
@@ -1,11 +1,14 @@
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 {
10 + private static $ai_last_progress = 0;
8 11 private $log_types = [
9 12 ''
10 13 ];
11 14
@@ -33,22 +36,89 @@
33 36 'progress' => 100
34 37 ] );
35 38 }
36 39
37 - public function sse_message( $data ) {
40 + public function sse_message( $data, $ai_content = true ) {
38 41 // Log the data into debug log file
39 - $this->debug_log( $data );
42 + $this->sse_log_file( $data );
40 43
41 - echo "event: message\n";
42 - echo 'data: ' . wp_json_encode( $data ) . "\n\n";
44 + if(Helper::should_flush()){
45 + echo "event: message\n";
46 + echo 'data: ' . wp_json_encode( $data ) . "\n\n";
43 47
44 - // Extra padding.
45 - echo esc_html( ':' . str_repeat( ' ', 2048 ) . "\n\n" );
48 + // Extra padding.
49 + echo esc_html( ':' . str_repeat( ' ', 2048 ) . "\n\n" );
46 50
47 - flush();
51 + flush();
52 + if (ob_get_level() > 0) {
53 + ob_flush();
54 + }
55 + }
56 +
57 + // $data = Utils::get_session_data_by_id();
58 + // if($ai_content && !empty($data['process_id']) && $data['process_id'] !== 'undefined' && "null" !== $data['process_id']){
59 +
60 + // // wp_cache_delete( 'templately_ai_processed_pages', 'options' );
61 + // global $wpdb;
62 + // $value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'templately_ai_processed_pages' ) );
63 + // // You might need to manually unserialize the value if it was serialized
64 + // $processed_pages = maybe_unserialize( $value );
65 + // // $processed_pages = get_option( "templately_ai_processed_pages", [] );
66 +
67 + // $updated_ids = $processed_pages[$data['process_id']]['pages'] ?? [];
68 + // $ai_page_ids = array_reduce($data['ai_page_ids'], 'array_merge', array());
69 +
70 + // // $ai_page_ids = array_filter(array_map('intval', explode(',', $data['ai_page_ids'] ?? '')));
71 + // // Calculate progress percentage
72 +
73 + // $total_pages = count($ai_page_ids);
74 + // $updated_pages = count($updated_ids);
75 + // $progress_percentage = $total_pages > 0 ? round(($updated_pages / $total_pages) * 100) : 0;
76 +
77 + // if( $progress_percentage != self::$ai_last_progress ) {
78 + // self::$ai_last_progress = $progress_percentage;
79 + // $this->sse_message( [
80 + // 'type' => 'ai-content',
81 + // 'action' => 'updateLog',
82 + // 'progress' => $progress_percentage,
83 + // // 'name' => method_exists($runner, 'get_name') ? $runner->get_name() : '',
84 + // 'processed_pages' => $processed_pages,
85 + // // 'asdfg' => $updated_ids,
86 + // ], false );
87 + // }
88 + // }
89 + // else {
90 + // $log = get_option( 'templately_fsi_log' ) ?: [];
91 + // $log[] = $data;
92 + // update_option( 'templately_fsi_log', $log );
93 + // }
94 + // else if($data['action'] === 'complete' || $data['action'] === 'downloadComplete' || $data['action'] === 'error'){
95 + // wp_send_json( $data );
96 + // }
48 97 }
49 98
50 99 /**
100 + * Printing Error Logs in debug.log file or in option.
101 + *
102 + * @param mixed $log
103 + * @return void
104 + */
105 + public function sse_log_file( $log ){
106 + $request_params = Utils::get_session_data_by_id();
107 +
108 + if (is_array($log)) {
109 + $log['timestamp'] = date('Y-m-d H:i:s');
110 + }
111 +
112 + if (isset($request_params['log_type']) && $request_params['log_type'] == 'file') {
113 + LogHandler::sse_log_file($log);
114 + } else {
115 + $_log = get_option('templately_fsi_log') ?: [];
116 + $_log[] = $log;
117 + update_option('templately_fsi_log', $_log, false);
118 + }
119 + }
120 + /**
51 121 * Printing Error Logs in debug.log file.
52 122 *
53 123 * @param mixed $log
54 124 * @return void
@@ -54,12 +124,14 @@
54 124 * @return void
55 125 */
56 126 public function debug_log( $log ){
57 127 if ( defined('TEMPLATELY_EVENT_LOG') && TEMPLATELY_EVENT_LOG === true ) {
128 +
58 129 if ( is_array( $log ) || is_object( $log ) ) {
59 130 error_log( print_r( $log, true ) );
60 - } else {
131 + } else if($log) {
61 132 error_log( $log );
62 133 }
134 +
63 135 }
64 136 }
65 137 }