|
...
|
...
|
@@ -107,7 +107,6 @@ class ProjectUpdate extends Command |
|
|
|
$page_list = array_column($data_page, 'path');
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_flush = 0;
|
|
|
|
//设置数据库
|
|
|
|
$project = ProjectServer::useProject($project_id);
|
|
|
|
if ($project) {
|
|
...
|
...
|
@@ -250,8 +249,6 @@ class ProjectUpdate extends Command |
|
|
|
foreach ($items as $item) {
|
|
|
|
$route = $this->get_url_route($item['url'] ?? '');
|
|
|
|
if ($route) {
|
|
|
|
$product = $model->read(['route' => $route], 'id');
|
|
|
|
if (!$product) {
|
|
|
|
//图片
|
|
|
|
$gallery = [];
|
|
|
|
if ($item['images'] ?? []) {
|
|
...
|
...
|
@@ -265,8 +262,12 @@ class ProjectUpdate extends Command |
|
|
|
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
|
|
|
|
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
//名称去掉特殊符号
|
|
|
|
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
|
|
|
|
|
|
|
|
try {
|
|
|
|
$product = $model->read(['route' => $route], 'id');
|
|
|
|
if (!$product) {
|
|
|
|
$id = $model->insertGetId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['ttile'],
|
|
...
|
...
|
@@ -290,43 +291,25 @@ class ProjectUpdate extends Command |
|
|
|
]);
|
|
|
|
$this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
|
|
|
|
|
|
|
|
//扩展字段
|
|
|
|
if ($item['extend'] ?? []) {
|
|
|
|
foreach (array_reverse($item['extend']) as $ke => $ve) {
|
|
|
|
$extend = $extend_model->read(['title' => $ke]);
|
|
|
|
if (!$extend) {
|
|
|
|
$extend_key = $this->get_extend_key($extend_model);
|
|
|
|
$extend_model->add([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $ke,
|
|
|
|
'type' => 1,
|
|
|
|
'key' => $extend_key
|
|
|
|
]);
|
|
|
|
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
|
|
|
|
} else {
|
|
|
|
$extend_key = $extend['key'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$extend_info = $extend_info_model->read(['key' => $extend_key, 'product_id' => $id]);
|
|
|
|
if (!$extend_info) {
|
|
|
|
$extend_info_model->add([
|
|
|
|
'key' => $extend_key,
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'product_id' => $id,
|
|
|
|
'values' => $ve,
|
|
|
|
'type' => 1
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$id = $product['id'];
|
|
|
|
$model->edit([
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'intro' => $item['short_description'] ?? '',
|
|
|
|
'content' => $item['content'] ?? '',
|
|
|
|
'category_id' => $category_id,
|
|
|
|
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
|
|
|
|
'gallery' => Arr::a2s($gallery),
|
|
|
|
'seo_mate' => Arr::a2s([
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'keyword' => $item['keywords'] ?? '',
|
|
|
|
'description' => $item['description'] ?? ''
|
|
|
|
]),
|
|
|
|
'sort' => $item['sort'] ?? 0,
|
|
|
|
], ['id' => $id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
|
|
|
|
$is_flush = 1;
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$id = $product['id'];
|
|
|
|
//扩展字段
|
|
|
|
if ($item['extend'] ?? []) {
|
|
|
|
foreach (array_reverse($item['extend']) as $ke => $ve) {
|
|
...
|
...
|
@@ -355,6 +338,9 @@ class ProjectUpdate extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -388,23 +374,25 @@ class ProjectUpdate extends Command |
|
|
|
foreach ($items as $item) {
|
|
|
|
$route = $this->get_url_route($item['url'] ?? '');
|
|
|
|
if ($route) {
|
|
|
|
$news = $model->read(['url' => $route], 'id');
|
|
|
|
if (!$news) {
|
|
|
|
//分类
|
|
|
|
$category_id = '';
|
|
|
|
if ($api_type == 'news' && ($item['category'] ?? [])) {
|
|
|
|
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
|
|
|
|
$category_id = $logic->getCategory(array_column($category_arr, 'id'));
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
|
|
|
|
|
|
|
|
//图片
|
|
|
|
if (is_array($item['images'])) {
|
|
|
|
$image = $item['images'][0] ?? '';
|
|
|
|
} else {
|
|
|
|
$image = $item['images'] ?? '';
|
|
|
|
}
|
|
|
|
$new_img = $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url);
|
|
|
|
//名称去掉特殊符号
|
|
|
|
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
|
|
|
|
|
|
|
|
try {
|
|
|
|
$news = $model->read(['url' => $route], 'id');
|
|
|
|
if (!$news) {
|
|
|
|
$id = $model->insertGetId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $item['ttile'],
|
|
...
|
...
|
@@ -413,7 +401,7 @@ class ProjectUpdate extends Command |
|
|
|
'seo_keywords' => $item['keywords'] ?? '',
|
|
|
|
'seo_description' => $item['description'] ?? '',
|
|
|
|
'text' => $item['content'] ?? '',
|
|
|
|
'image' => $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url),
|
|
|
|
'image' => $new_img,
|
|
|
|
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE,
|
|
|
|
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
...
|
...
|
@@ -425,7 +413,19 @@ class ProjectUpdate extends Command |
|
|
|
$this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
|
|
|
|
|
|
|
|
CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list);
|
|
|
|
$is_flush = 1;
|
|
|
|
} else {
|
|
|
|
$id = $news['id'];
|
|
|
|
$model->edit([
|
|
|
|
'name' => $item['ttile'],
|
|
|
|
'category_id' => $category_id,
|
|
|
|
'seo_title' => $item['ttile'],
|
|
|
|
'seo_keywords' => $item['keywords'] ?? '',
|
|
|
|
'seo_description' => $item['description'] ?? '',
|
|
|
|
'text' => $item['content'] ?? '',
|
|
|
|
'image' => $new_img,
|
|
|
|
'sort' => $item['sort'] ?? 0,
|
|
|
|
], ['id' => $id]);
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
...
|
...
|
@@ -434,7 +434,6 @@ class ProjectUpdate extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
...
|
...
|
@@ -457,10 +456,11 @@ class ProjectUpdate extends Command |
|
|
|
foreach ($items as $item) {
|
|
|
|
$route = $this->get_url_route($item['url'] ?? '');
|
|
|
|
if ($route) {
|
|
|
|
//名称去掉特殊符号
|
|
|
|
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
|
|
|
|
try {
|
|
|
|
$custom = $model->read(['url' => $route], 'id');
|
|
|
|
if (!$custom) {
|
|
|
|
try {
|
|
|
|
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
|
|
|
|
$id = $model->insertGetId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $item['ttile'],
|
|
...
|
...
|
@@ -478,7 +478,16 @@ class ProjectUpdate extends Command |
|
|
|
$this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id);
|
|
|
|
|
|
|
|
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list);
|
|
|
|
$is_flush = 1;
|
|
|
|
} else {
|
|
|
|
$id = $custom['id'];
|
|
|
|
$model->edit([
|
|
|
|
'name' => $item['ttile'],
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'keywords' => $item['keywords'] ?? '',
|
|
|
|
'description' => $item['description'] ?? '',
|
|
|
|
'html' => $item['content'] ?? '',
|
|
|
|
], ['id' => $id]);
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
...
|
...
|
@@ -487,7 +496,6 @@ class ProjectUpdate extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
...
|
...
|
@@ -497,9 +505,6 @@ class ProjectUpdate extends Command |
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
|
|
|
|
$task->status = UpdateLog::STATUS_COM;//同步完成
|
|
|
|
if ($is_flush) {
|
|
|
|
$task->collect_status = UpdateLog::COLLECT_STATUS_UN;
|
|
|
|
}
|
|
|
|
$task->save();
|
|
|
|
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL;
|
...
|
...
|
|