正在显示
1 个修改的文件
包含
58 行增加
和
53 行删除
| @@ -107,7 +107,6 @@ class ProjectUpdate extends Command | @@ -107,7 +107,6 @@ class ProjectUpdate extends Command | ||
| 107 | $page_list = array_column($data_page, 'path'); | 107 | $page_list = array_column($data_page, 'path'); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | - $is_flush = 0; | ||
| 111 | //设置数据库 | 110 | //设置数据库 |
| 112 | $project = ProjectServer::useProject($project_id); | 111 | $project = ProjectServer::useProject($project_id); |
| 113 | if ($project) { | 112 | if ($project) { |
| @@ -250,8 +249,6 @@ class ProjectUpdate extends Command | @@ -250,8 +249,6 @@ class ProjectUpdate extends Command | ||
| 250 | foreach ($items as $item) { | 249 | foreach ($items as $item) { |
| 251 | $route = $this->get_url_route($item['url'] ?? ''); | 250 | $route = $this->get_url_route($item['url'] ?? ''); |
| 252 | if ($route) { | 251 | if ($route) { |
| 253 | - $product = $model->read(['route' => $route], 'id'); | ||
| 254 | - if (!$product) { | ||
| 255 | //图片 | 252 | //图片 |
| 256 | $gallery = []; | 253 | $gallery = []; |
| 257 | if ($item['images'] ?? []) { | 254 | if ($item['images'] ?? []) { |
| @@ -265,8 +262,12 @@ class ProjectUpdate extends Command | @@ -265,8 +262,12 @@ class ProjectUpdate extends Command | ||
| 265 | $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); | 262 | $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); |
| 266 | $category_id = $logic->getLastCategory(array_column($category_arr, 'id')); | 263 | $category_id = $logic->getLastCategory(array_column($category_arr, 'id')); |
| 267 | } | 264 | } |
| 268 | - try { | 265 | + //名称去掉特殊符号 |
| 269 | $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | 266 | $item['ttile'] = $this->special2str($item['ttile'] ?? ''); |
| 267 | + | ||
| 268 | + try { | ||
| 269 | + $product = $model->read(['route' => $route], 'id'); | ||
| 270 | + if (!$product) { | ||
| 270 | $id = $model->insertGetId([ | 271 | $id = $model->insertGetId([ |
| 271 | 'project_id' => $project_id, | 272 | 'project_id' => $project_id, |
| 272 | 'title' => $item['ttile'], | 273 | 'title' => $item['ttile'], |
| @@ -290,43 +291,25 @@ class ProjectUpdate extends Command | @@ -290,43 +291,25 @@ class ProjectUpdate extends Command | ||
| 290 | ]); | 291 | ]); |
| 291 | $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); | 292 | $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); |
| 292 | 293 | ||
| 293 | - //扩展字段 | ||
| 294 | - if ($item['extend'] ?? []) { | ||
| 295 | - foreach (array_reverse($item['extend']) as $ke => $ve) { | ||
| 296 | - $extend = $extend_model->read(['title' => $ke]); | ||
| 297 | - if (!$extend) { | ||
| 298 | - $extend_key = $this->get_extend_key($extend_model); | ||
| 299 | - $extend_model->add([ | ||
| 300 | - 'project_id' => $project_id, | ||
| 301 | - 'title' => $ke, | ||
| 302 | - 'type' => 1, | ||
| 303 | - 'key' => $extend_key | ||
| 304 | - ]); | 294 | + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); |
| 305 | } else { | 295 | } else { |
| 306 | - $extend_key = $extend['key']; | ||
| 307 | - } | ||
| 308 | - | ||
| 309 | - $extend_info = $extend_info_model->read(['key' => $extend_key, 'product_id' => $id]); | ||
| 310 | - if (!$extend_info) { | ||
| 311 | - $extend_info_model->add([ | ||
| 312 | - 'key' => $extend_key, | ||
| 313 | - 'project_id' => $project_id, | ||
| 314 | - 'product_id' => $id, | ||
| 315 | - 'values' => $ve, | ||
| 316 | - 'type' => 1 | ||
| 317 | - ]); | ||
| 318 | - } | ||
| 319 | - } | 296 | + $id = $product['id']; |
| 297 | + $model->edit([ | ||
| 298 | + 'title' => $item['ttile'], | ||
| 299 | + 'intro' => $item['short_description'] ?? '', | ||
| 300 | + 'content' => $item['content'] ?? '', | ||
| 301 | + 'category_id' => $category_id, | ||
| 302 | + 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', | ||
| 303 | + 'gallery' => Arr::a2s($gallery), | ||
| 304 | + 'seo_mate' => Arr::a2s([ | ||
| 305 | + 'title' => $item['ttile'], | ||
| 306 | + 'keyword' => $item['keywords'] ?? '', | ||
| 307 | + 'description' => $item['description'] ?? '' | ||
| 308 | + ]), | ||
| 309 | + 'sort' => $item['sort'] ?? 0, | ||
| 310 | + ], ['id' => $id]); | ||
| 320 | } | 311 | } |
| 321 | 312 | ||
| 322 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); | ||
| 323 | - $is_flush = 1; | ||
| 324 | - } catch (\Exception $e) { | ||
| 325 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | ||
| 326 | - continue; | ||
| 327 | - } | ||
| 328 | - }else{ | ||
| 329 | - $id = $product['id']; | ||
| 330 | //扩展字段 | 313 | //扩展字段 |
| 331 | if ($item['extend'] ?? []) { | 314 | if ($item['extend'] ?? []) { |
| 332 | foreach (array_reverse($item['extend']) as $ke => $ve) { | 315 | foreach (array_reverse($item['extend']) as $ke => $ve) { |
| @@ -355,6 +338,9 @@ class ProjectUpdate extends Command | @@ -355,6 +338,9 @@ class ProjectUpdate extends Command | ||
| 355 | } | 338 | } |
| 356 | } | 339 | } |
| 357 | } | 340 | } |
| 341 | + } catch (\Exception $e) { | ||
| 342 | + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | ||
| 343 | + continue; | ||
| 358 | } | 344 | } |
| 359 | } | 345 | } |
| 360 | } | 346 | } |
| @@ -388,23 +374,25 @@ class ProjectUpdate extends Command | @@ -388,23 +374,25 @@ class ProjectUpdate extends Command | ||
| 388 | foreach ($items as $item) { | 374 | foreach ($items as $item) { |
| 389 | $route = $this->get_url_route($item['url'] ?? ''); | 375 | $route = $this->get_url_route($item['url'] ?? ''); |
| 390 | if ($route) { | 376 | if ($route) { |
| 391 | - $news = $model->read(['url' => $route], 'id'); | ||
| 392 | - if (!$news) { | ||
| 393 | //分类 | 377 | //分类 |
| 394 | $category_id = ''; | 378 | $category_id = ''; |
| 395 | if ($api_type == 'news' && ($item['category'] ?? [])) { | 379 | if ($api_type == 'news' && ($item['category'] ?? [])) { |
| 396 | $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); | 380 | $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); |
| 397 | $category_id = $logic->getCategory(array_column($category_arr, 'id')); | 381 | $category_id = $logic->getCategory(array_column($category_arr, 'id')); |
| 398 | } | 382 | } |
| 399 | - try { | ||
| 400 | - $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | ||
| 401 | - | 383 | + //图片 |
| 402 | if (is_array($item['images'])) { | 384 | if (is_array($item['images'])) { |
| 403 | $image = $item['images'][0] ?? ''; | 385 | $image = $item['images'][0] ?? ''; |
| 404 | } else { | 386 | } else { |
| 405 | $image = $item['images'] ?? ''; | 387 | $image = $item['images'] ?? ''; |
| 406 | } | 388 | } |
| 389 | + $new_img = $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url); | ||
| 390 | + //名称去掉特殊符号 | ||
| 391 | + $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | ||
| 407 | 392 | ||
| 393 | + try { | ||
| 394 | + $news = $model->read(['url' => $route], 'id'); | ||
| 395 | + if (!$news) { | ||
| 408 | $id = $model->insertGetId([ | 396 | $id = $model->insertGetId([ |
| 409 | 'project_id' => $project_id, | 397 | 'project_id' => $project_id, |
| 410 | 'name' => $item['ttile'], | 398 | 'name' => $item['ttile'], |
| @@ -413,7 +401,7 @@ class ProjectUpdate extends Command | @@ -413,7 +401,7 @@ class ProjectUpdate extends Command | ||
| 413 | 'seo_keywords' => $item['keywords'] ?? '', | 401 | 'seo_keywords' => $item['keywords'] ?? '', |
| 414 | 'seo_description' => $item['description'] ?? '', | 402 | 'seo_description' => $item['description'] ?? '', |
| 415 | 'text' => $item['content'] ?? '', | 403 | 'text' => $item['content'] ?? '', |
| 416 | - 'image' => $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url), | 404 | + 'image' => $new_img, |
| 417 | 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE, | 405 | 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE, |
| 418 | 'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), | 406 | 'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), |
| 419 | 'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), | 407 | 'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), |
| @@ -425,7 +413,19 @@ class ProjectUpdate extends Command | @@ -425,7 +413,19 @@ class ProjectUpdate extends Command | ||
| 425 | $this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id); | 413 | $this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id); |
| 426 | 414 | ||
| 427 | CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list); | 415 | CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list); |
| 428 | - $is_flush = 1; | 416 | + } else { |
| 417 | + $id = $news['id']; | ||
| 418 | + $model->edit([ | ||
| 419 | + 'name' => $item['ttile'], | ||
| 420 | + 'category_id' => $category_id, | ||
| 421 | + 'seo_title' => $item['ttile'], | ||
| 422 | + 'seo_keywords' => $item['keywords'] ?? '', | ||
| 423 | + 'seo_description' => $item['description'] ?? '', | ||
| 424 | + 'text' => $item['content'] ?? '', | ||
| 425 | + 'image' => $new_img, | ||
| 426 | + 'sort' => $item['sort'] ?? 0, | ||
| 427 | + ], ['id' => $id]); | ||
| 428 | + } | ||
| 429 | } catch (\Exception $e) { | 429 | } catch (\Exception $e) { |
| 430 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 430 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 431 | continue; | 431 | continue; |
| @@ -434,7 +434,6 @@ class ProjectUpdate extends Command | @@ -434,7 +434,6 @@ class ProjectUpdate extends Command | ||
| 434 | } | 434 | } |
| 435 | } | 435 | } |
| 436 | } | 436 | } |
| 437 | - } | ||
| 438 | } else { | 437 | } else { |
| 439 | return true; | 438 | return true; |
| 440 | } | 439 | } |
| @@ -457,10 +456,11 @@ class ProjectUpdate extends Command | @@ -457,10 +456,11 @@ class ProjectUpdate extends Command | ||
| 457 | foreach ($items as $item) { | 456 | foreach ($items as $item) { |
| 458 | $route = $this->get_url_route($item['url'] ?? ''); | 457 | $route = $this->get_url_route($item['url'] ?? ''); |
| 459 | if ($route) { | 458 | if ($route) { |
| 459 | + //名称去掉特殊符号 | ||
| 460 | + $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | ||
| 461 | + try { | ||
| 460 | $custom = $model->read(['url' => $route], 'id'); | 462 | $custom = $model->read(['url' => $route], 'id'); |
| 461 | if (!$custom) { | 463 | if (!$custom) { |
| 462 | - try { | ||
| 463 | - $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | ||
| 464 | $id = $model->insertGetId([ | 464 | $id = $model->insertGetId([ |
| 465 | 'project_id' => $project_id, | 465 | 'project_id' => $project_id, |
| 466 | 'name' => $item['ttile'], | 466 | 'name' => $item['ttile'], |
| @@ -478,7 +478,16 @@ class ProjectUpdate extends Command | @@ -478,7 +478,16 @@ class ProjectUpdate extends Command | ||
| 478 | $this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id); | 478 | $this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id); |
| 479 | 479 | ||
| 480 | CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list); | 480 | CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list); |
| 481 | - $is_flush = 1; | 481 | + } else { |
| 482 | + $id = $custom['id']; | ||
| 483 | + $model->edit([ | ||
| 484 | + 'name' => $item['ttile'], | ||
| 485 | + 'title' => $item['ttile'], | ||
| 486 | + 'keywords' => $item['keywords'] ?? '', | ||
| 487 | + 'description' => $item['description'] ?? '', | ||
| 488 | + 'html' => $item['content'] ?? '', | ||
| 489 | + ], ['id' => $id]); | ||
| 490 | + } | ||
| 482 | } catch (\Exception $e) { | 491 | } catch (\Exception $e) { |
| 483 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 492 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 484 | continue; | 493 | continue; |
| @@ -487,7 +496,6 @@ class ProjectUpdate extends Command | @@ -487,7 +496,6 @@ class ProjectUpdate extends Command | ||
| 487 | } | 496 | } |
| 488 | } | 497 | } |
| 489 | } | 498 | } |
| 490 | - } | ||
| 491 | } else { | 499 | } else { |
| 492 | return true; | 500 | return true; |
| 493 | } | 501 | } |
| @@ -497,9 +505,6 @@ class ProjectUpdate extends Command | @@ -497,9 +505,6 @@ class ProjectUpdate extends Command | ||
| 497 | DB::disconnect('custom_mysql'); | 505 | DB::disconnect('custom_mysql'); |
| 498 | 506 | ||
| 499 | $task->status = UpdateLog::STATUS_COM;//同步完成 | 507 | $task->status = UpdateLog::STATUS_COM;//同步完成 |
| 500 | - if ($is_flush) { | ||
| 501 | - $task->collect_status = UpdateLog::COLLECT_STATUS_UN; | ||
| 502 | - } | ||
| 503 | $task->save(); | 508 | $task->save(); |
| 504 | 509 | ||
| 505 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL; | 510 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL; |
-
请 注册 或 登录 后发表评论