合并分支 'akun' 到 'master'
Akun 查看合并请求 !157
正在显示
1 个修改的文件
包含
2 行增加
和
136 行删除
| @@ -41,14 +41,12 @@ class ProjectUpdateTemp extends Command | @@ -41,14 +41,12 @@ class ProjectUpdateTemp extends Command | ||
| 41 | 41 | ||
| 42 | public function handle() | 42 | public function handle() |
| 43 | { | 43 | { |
| 44 | - while (true) { | ||
| 45 | $this->start_update(); | 44 | $this->start_update(); |
| 46 | } | 45 | } |
| 47 | - } | ||
| 48 | 46 | ||
| 49 | protected function start_update() | 47 | protected function start_update() |
| 50 | { | 48 | { |
| 51 | - $list = UpdateLog::where('api_type', 'category')->get(); | 49 | + $list = UpdateLog::where('api_type', 'post')->get(); |
| 52 | 50 | ||
| 53 | foreach ($list as $task) { | 51 | foreach ($list as $task) { |
| 54 | 52 | ||
| @@ -62,45 +60,6 @@ class ProjectUpdateTemp extends Command | @@ -62,45 +60,6 @@ class ProjectUpdateTemp extends Command | ||
| 62 | 60 | ||
| 63 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL; | 61 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL; |
| 64 | 62 | ||
| 65 | - $task->status = UpdateLog::STATUS_ING;//同步中 | ||
| 66 | - $task->save(); | ||
| 67 | - | ||
| 68 | - $domain_arr = parse_url($api_url); | ||
| 69 | - //获取网站配置 | ||
| 70 | - $link_type = 0; | ||
| 71 | - $web_url_domain = $domain_arr['host']; | ||
| 72 | - $home_url = $domain_arr['host']; | ||
| 73 | - $url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text'; | ||
| 74 | - $data_config = curl_c($url_web_config); | ||
| 75 | - if ($data_config) { | ||
| 76 | - $link_type = $data_config['link_type'] ?? 0; | ||
| 77 | - | ||
| 78 | - $web_url_arr = parse_url($data_config['web_url_domain'] ?? ''); | ||
| 79 | - if (isset($web_url_arr['host'])) { | ||
| 80 | - $web_url_domain = $web_url_arr['host']; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - $home_url_arr = parse_url($data_config['home_url'] ?? ''); | ||
| 84 | - if (isset($home_url_arr['host'])) { | ||
| 85 | - $home_url = $home_url_arr['host']; | ||
| 86 | - } | ||
| 87 | - } | ||
| 88 | - //获取所有语种 | ||
| 89 | - $language_list = []; | ||
| 90 | - $url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json'; | ||
| 91 | - $data_language = curl_c($url_language); | ||
| 92 | - if ($data_language) { | ||
| 93 | - $language_list = array_column($data_language, 'short'); | ||
| 94 | - } | ||
| 95 | - //获取所有页面 | ||
| 96 | - $page_list = []; | ||
| 97 | - $url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json'; | ||
| 98 | - $data_page = curl_c($url_page); | ||
| 99 | - if ($data_page) { | ||
| 100 | - $page_list = array_column($data_page, 'path'); | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - $is_flush = 0; | ||
| 104 | //设置数据库 | 63 | //设置数据库 |
| 105 | $project = ProjectServer::useProject($project_id); | 64 | $project = ProjectServer::useProject($project_id); |
| 106 | if ($project) { | 65 | if ($project) { |
| @@ -136,53 +95,7 @@ class ProjectUpdateTemp extends Command | @@ -136,53 +95,7 @@ class ProjectUpdateTemp extends Command | ||
| 136 | $route = $this->get_url_route($item['url'] ?? ''); | 95 | $route = $this->get_url_route($item['url'] ?? ''); |
| 137 | if ($route) { | 96 | if ($route) { |
| 138 | $product = $model->read(['route' => $route], 'id'); | 97 | $product = $model->read(['route' => $route], 'id'); |
| 139 | - if (!$product) { | ||
| 140 | - //图片 | ||
| 141 | - $gallery = []; | ||
| 142 | - if ($item['images'] ?? []) { | ||
| 143 | - foreach ($item['images'] as $k_img => $img) { | ||
| 144 | - $gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)]; | ||
| 145 | - } | ||
| 146 | - } | ||
| 147 | - //分类 | ||
| 148 | - $category_id = ''; | ||
| 149 | - if ($item['category'] ?? []) { | ||
| 150 | - $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); | ||
| 151 | - $category_id = $logic->getLastCategory(array_column($category_arr, 'id')); | ||
| 152 | - } | ||
| 153 | - try { | ||
| 154 | - $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | ||
| 155 | - $id = $model->insertGetId([ | ||
| 156 | - 'project_id' => $project_id, | ||
| 157 | - 'title' => $item['ttile'], | ||
| 158 | - 'intro' => $item['short_description'] ?? '', | ||
| 159 | - 'content' => $item['content'] ?? '', | ||
| 160 | - 'category_id' => $category_id, | ||
| 161 | - 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', | ||
| 162 | - 'gallery' => Arr::a2s($gallery), | ||
| 163 | - 'seo_mate' => Arr::a2s([ | ||
| 164 | - 'title' => $item['ttile'], | ||
| 165 | - 'keyword' => $item['keywords'] ?? '', | ||
| 166 | - 'description' => $item['description'] ?? '' | ||
| 167 | - ]), | ||
| 168 | - 'status' => Product::STATUS_ON, | ||
| 169 | - 'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), | ||
| 170 | - 'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), | ||
| 171 | - 'sort' => $item['sort'] ?? 0, | ||
| 172 | - 'is_upgrade' => 1, | ||
| 173 | - 'six_read' => 1, | ||
| 174 | - 'route' => $route | ||
| 175 | - ]); | ||
| 176 | - $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); | ||
| 177 | - | ||
| 178 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); | ||
| 179 | - | ||
| 180 | - $is_flush = 1; | ||
| 181 | - } catch (\Exception $e) { | ||
| 182 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | ||
| 183 | - continue; | ||
| 184 | - } | ||
| 185 | - } else { | 98 | + if ($product) { |
| 186 | $category_id = ''; | 99 | $category_id = ''; |
| 187 | if ($item['category'] ?? []) { | 100 | if ($item['category'] ?? []) { |
| 188 | $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); | 101 | $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); |
| @@ -203,12 +116,6 @@ class ProjectUpdateTemp extends Command | @@ -203,12 +116,6 @@ class ProjectUpdateTemp extends Command | ||
| 203 | //关闭数据库 | 116 | //关闭数据库 |
| 204 | DB::disconnect('custom_mysql'); | 117 | DB::disconnect('custom_mysql'); |
| 205 | 118 | ||
| 206 | - $task->status = UpdateLog::STATUS_COM;//同步完成 | ||
| 207 | - if ($is_flush) { | ||
| 208 | - $task->collect_status = UpdateLog::COLLECT_STATUS_UN; | ||
| 209 | - } | ||
| 210 | - $task->save(); | ||
| 211 | - | ||
| 212 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL; | 119 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL; |
| 213 | 120 | ||
| 214 | sleep(2); | 121 | sleep(2); |
| @@ -315,45 +222,4 @@ class ProjectUpdateTemp extends Command | @@ -315,45 +222,4 @@ class ProjectUpdateTemp extends Command | ||
| 315 | } | 222 | } |
| 316 | } | 223 | } |
| 317 | } | 224 | } |
| 318 | - | ||
| 319 | - //资源下载 | ||
| 320 | - protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url) | ||
| 321 | - { | ||
| 322 | - if (!$url) { | ||
| 323 | - return ''; | ||
| 324 | - } | ||
| 325 | - | ||
| 326 | - $arr = parse_url($url); | ||
| 327 | - $scheme = $arr['scheme'] ?? ''; | ||
| 328 | - $host = $arr['host'] ?? ''; | ||
| 329 | - $path = $arr['path'] ?? ''; | ||
| 330 | - | ||
| 331 | - $url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path; | ||
| 332 | - | ||
| 333 | - if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) { | ||
| 334 | - | ||
| 335 | - $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); | ||
| 336 | - if (!$source) { | ||
| 337 | - $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete); | ||
| 338 | - | ||
| 339 | - if ($new_url) { | ||
| 340 | - CollectSource::insert([ | ||
| 341 | - 'project_id' => $project_id, | ||
| 342 | - 'origin' => $url, | ||
| 343 | - 'target' => $new_url, | ||
| 344 | - 'created_at' => date('Y-m-d H:i:s'), | ||
| 345 | - 'updated_at' => date('Y-m-d H:i:s'), | ||
| 346 | - ]); | ||
| 347 | - | ||
| 348 | - return getImageUrl($new_url); | ||
| 349 | - } else { | ||
| 350 | - return $url_complete; | ||
| 351 | - } | ||
| 352 | - } else { | ||
| 353 | - return getImageUrl($source['target']); | ||
| 354 | - } | ||
| 355 | - } else { | ||
| 356 | - return $url_complete; | ||
| 357 | - } | ||
| 358 | - } | ||
| 359 | } | 225 | } |
-
请 注册 或 登录 后发表评论