| @@ -2,14 +2,12 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Templately\Core\Importer; |
| 4 | 4 | |
| 5 | 5 | use Templately\Core\Importer\Utils\LogHandler; |
| 6 | -use Templately\Core\Importer\Utils\SessionData; | |
| 7 | 6 | use Templately\Core\Importer\Utils\Utils; |
| 8 | 7 | use Templately\Utils\Helper; |
| 9 | 8 | |
| 10 | 9 | trait LogHelper { |
| 11 | - private static $ai_last_progress = 0; | |
| 12 | 10 | private $log_types = [ |
| 13 | 11 | '' |
| 14 | 12 | ]; |
| 15 | 13 | |
| @@ -37,9 +35,9 @@ | ||
| 37 | 35 | 'progress' => 100 |
| 38 | 36 | ] ); |
| 39 | 37 | } |
| 40 | 38 | |
| 41 | - public function sse_message( $data, $ai_content = true ) { | |
| 39 | + public function sse_message( $data ) { | |
| 42 | 40 | // Log the data into debug log file |
| 43 | 41 | $this->sse_log_file( $data ); |
| 44 | 42 | |
| 45 | 43 | if(Helper::should_flush()){ |
| @@ -53,41 +51,8 @@ | ||
| 53 | 51 | if (ob_get_level() > 0) { |
| 54 | 52 | ob_flush(); |
| 55 | 53 | } |
| 56 | 54 | } |
| 57 | - | |
| 58 | - // $data = Utils::get_session_data_by_id(); | |
| 59 | - // if($ai_content && !empty($data['process_id']) && $data['process_id'] !== 'undefined' && "null" !== $data['process_id']){ | |
| 60 | - | |
| 61 | - // // wp_cache_delete( 'templately_ai_processed_pages', 'options' ); | |
| 62 | - // global $wpdb; | |
| 63 | - // $value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'templately_ai_processed_pages' ) ); | |
| 64 | - // // You might need to manually unserialize the value if it was serialized | |
| 65 | - // $processed_pages = maybe_unserialize( $value ); | |
| 66 | - // // $processed_pages = get_option( "templately_ai_processed_pages", [] ); | |
| 67 | - | |
| 68 | - // $updated_ids = $processed_pages[$data['process_id']]['pages'] ?? []; | |
| 69 | - // $ai_page_ids = array_reduce($data['ai_page_ids'], 'array_merge', array()); | |
| 70 | - | |
| 71 | - // // $ai_page_ids = array_filter(array_map('intval', explode(',', $data['ai_page_ids'] ?? ''))); | |
| 72 | - // // Calculate progress percentage | |
| 73 | - | |
| 74 | - // $total_pages = count($ai_page_ids); | |
| 75 | - // $updated_pages = count($updated_ids); | |
| 76 | - // $progress_percentage = $total_pages > 0 ? round(($updated_pages / $total_pages) * 100) : 0; | |
| 77 | - | |
| 78 | - // if( $progress_percentage != self::$ai_last_progress ) { | |
| 79 | - // self::$ai_last_progress = $progress_percentage; | |
| 80 | - // $this->sse_message( [ | |
| 81 | - // 'type' => 'ai-content', | |
| 82 | - // 'action' => 'updateLog', | |
| 83 | - // 'progress' => $progress_percentage, | |
| 84 | - // // 'name' => method_exists($runner, 'get_name') ? $runner->get_name() : '', | |
| 85 | - // 'processed_pages' => $processed_pages, | |
| 86 | - // // 'asdfg' => $updated_ids, | |
| 87 | - // ], false ); | |
| 88 | - // } | |
| 89 | - // } | |
| 90 | 55 | // else { |
| 91 | 56 | // $log = get_option( 'templately_fsi_log' ) ?: []; |
| 92 | 57 | // $log[] = $data; |
| 93 | 58 | // update_option( 'templately_fsi_log', $log ); |
| @@ -103,10 +68,9 @@ | ||
| 103 | 68 | * @param mixed $log |
| 104 | 69 | * @return void |
| 105 | 70 | */ |
| 106 | 71 | public function sse_log_file( $log ){ |
| 107 | - $session_id = SessionData::get_session_id(); | |
| 108 | - $request_params = $session_id ? SessionData::get_data($session_id) : []; | |
| 72 | + $request_params = Utils::get_session_data_by_id(); | |
| 109 | 73 | |
| 110 | 74 | if (is_array($log)) { |
| 111 | 75 | $log['timestamp'] = date('Y-m-d H:i:s'); |
| 112 | 76 | } |