作者 刘锟

update

@@ -128,20 +128,21 @@ class ProjectUpdate extends Command @@ -128,20 +128,21 @@ class ProjectUpdate extends Command
128 128
129 $model = new Keyword(); 129 $model = new Keyword();
130 foreach ($items as $item) { 130 foreach ($items as $item) {
131 - if ($item['name'] ?? '') {  
132 - $keyword = $model->read(['title' => $item['name']], 'id'); 131 + $route = $this->get_url_route($item['url'] ?? '');
  132 + if ($route) {
  133 + $keyword = $model->read(['route' => $route], 'id');
133 if (!$keyword) { 134 if (!$keyword) {
134 try { 135 try {
135 - $item['name'] = $this->special2str($item['name']); 136 + $item['name'] = $this->special2str($item['name'] ?? '');
136 $id = $model->addReturnId([ 137 $id = $model->addReturnId([
137 'project_id' => $project_id, 138 'project_id' => $project_id,
138 'title' => $item['name'], 139 'title' => $item['name'],
139 'seo_title' => $item['seo_title'] ?? '', 140 'seo_title' => $item['seo_title'] ?? '',
140 'seo_keywords' => $item['seo_keywords'] ?? '', 141 'seo_keywords' => $item['seo_keywords'] ?? '',
141 'seo_description' => $item['seo_description'] ?? '', 142 'seo_description' => $item['seo_description'] ?? '',
142 - 'route' => $this->get_url_route($item['url']) 143 + 'route' => $route
143 ]); 144 ]);
144 - $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id); 145 + $this->set_map($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
145 146
146 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $link_type, $language_list, $page_list); 147 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $link_type, $language_list, $page_list);
147 } catch (\Exception $e) { 148 } catch (\Exception $e) {
@@ -225,8 +226,9 @@ class ProjectUpdate extends Command @@ -225,8 +226,9 @@ class ProjectUpdate extends Command
225 $model = new Product(); 226 $model = new Product();
226 227
227 foreach ($items as $item) { 228 foreach ($items as $item) {
228 - if ($item['ttile'] ?? '') {  
229 - $product = $model->read(['title' => $item['ttile']], 'id'); 229 + $route = $this->get_url_route($item['url'] ?? '');
  230 + if ($route) {
  231 + $product = $model->read(['route' => $route], 'id');
230 if (!$product) { 232 if (!$product) {
231 //图片 233 //图片
232 $gallery = []; 234 $gallery = [];
@@ -244,7 +246,7 @@ class ProjectUpdate extends Command @@ -244,7 +246,7 @@ class ProjectUpdate extends Command
244 for ($i = 0; $i < count($item['category']); $i++) { 246 for ($i = 0; $i < count($item['category']); $i++) {
245 $return = $this->get_category_name_arr($item['category'], $pid); 247 $return = $this->get_category_name_arr($item['category'], $pid);
246 if ($return) { 248 if ($return) {
247 - $category_arr[] = $this->special2str($return['name']); 249 + $category_arr[] = $this->special2str($return['name'] ?? '');
248 $pid = $return['id']; 250 $pid = $return['id'];
249 } 251 }
250 } 252 }
@@ -255,7 +257,7 @@ class ProjectUpdate extends Command @@ -255,7 +257,7 @@ class ProjectUpdate extends Command
255 } 257 }
256 } 258 }
257 try { 259 try {
258 - $item['ttile'] = $this->special2str($item['ttile']); 260 + $item['ttile'] = $this->special2str($item['ttile'] ?? '');
259 $id = $model->addReturnId([ 261 $id = $model->addReturnId([
260 'project_id' => $project_id, 262 'project_id' => $project_id,
261 'title' => $item['ttile'], 263 'title' => $item['ttile'],
@@ -270,9 +272,9 @@ class ProjectUpdate extends Command @@ -270,9 +272,9 @@ class ProjectUpdate extends Command
270 'description' => $item['description'] ?? '' 272 'description' => $item['description'] ?? ''
271 ]), 273 ]),
272 'status' => Product::STATUS_ON, 274 'status' => Product::STATUS_ON,
273 - 'route' => $this->get_url_route($item['url']) 275 + 'route' => $route
274 ]); 276 ]);
275 - $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT, $id, $project_id); 277 + $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
276 278
277 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); 279 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
278 } catch (\Exception $e) { 280 } catch (\Exception $e) {
@@ -308,12 +310,12 @@ class ProjectUpdate extends Command @@ -308,12 +310,12 @@ class ProjectUpdate extends Command
308 } 310 }
309 311
310 foreach ($items as $item) { 312 foreach ($items as $item) {
311 - $route = $this->get_url_route($item['url']); 313 + $route = $this->get_url_route($item['url'] ?? '');
312 if ($route) { 314 if ($route) {
313 $news = $model->read(['url' => $route], 'id'); 315 $news = $model->read(['url' => $route], 'id');
314 if (!$news) { 316 if (!$news) {
315 try { 317 try {
316 - $item['ttile'] = $this->special2str($item['ttile']); 318 + $item['ttile'] = $this->special2str($item['ttile'] ?? '');
317 319
318 if (is_array($item['images'])) { 320 if (is_array($item['images'])) {
319 $image = $item['images'][0] ?? ''; 321 $image = $item['images'][0] ?? '';
@@ -366,11 +368,12 @@ class ProjectUpdate extends Command @@ -366,11 +368,12 @@ class ProjectUpdate extends Command
366 $model = new BCustomTemplate(); 368 $model = new BCustomTemplate();
367 369
368 foreach ($items as $item) { 370 foreach ($items as $item) {
369 - if ($item['ttile'] ?? '') {  
370 - $custom = $model->read(['name' => $item['ttile']], 'id'); 371 + $route = $this->get_url_route($item['url'] ?? '');
  372 + if ($route) {
  373 + $custom = $model->read(['url' => $route], 'id');
371 if (!$custom) { 374 if (!$custom) {
372 try { 375 try {
373 - $item['ttile'] = $this->special2str($item['ttile']); 376 + $item['ttile'] = $this->special2str($item['ttile'] ?? '');
374 $id = $model->addReturnId([ 377 $id = $model->addReturnId([
375 'project_id' => $project_id, 378 'project_id' => $project_id,
376 'name' => $item['ttile'], 379 'name' => $item['ttile'],
@@ -379,9 +382,9 @@ class ProjectUpdate extends Command @@ -379,9 +382,9 @@ class ProjectUpdate extends Command
379 'description' => $item['description'] ?? '', 382 'description' => $item['description'] ?? '',
380 'html' => $item['content'] ?? '', 383 'html' => $item['content'] ?? '',
381 'status' => 1, 384 'status' => 1,
382 - 'url' => $this->get_url_route($item['url']) 385 + 'url' => $route
383 ]); 386 ]);
384 - $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PAGE, $id, $project_id); 387 + $this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id);
385 388
386 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list); 389 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list);
387 } catch (\Exception $e) { 390 } catch (\Exception $e) {
@@ -454,20 +457,21 @@ class ProjectUpdate extends Command @@ -454,20 +457,21 @@ class ProjectUpdate extends Command
454 { 457 {
455 $model = new Category(); 458 $model = new Category();
456 foreach ($items as $item) { 459 foreach ($items as $item) {
457 - if ($item['name'] ?? '') {  
458 - $parent = $model->read(['pid' => $pid, 'title' => $item['name']], 'id'); 460 + $route = $this->get_url_route($item['url'] ?? '');
  461 + if ($route) {
  462 + $parent = $model->read(['pid' => $pid, 'route' => $route], 'id');
459 if (!$parent) { 463 if (!$parent) {
460 try { 464 try {
461 - $item['name'] = $this->special2str($item['name']); 465 + $item['name'] = $this->special2str($item['name'] ?? '');
462 $parent_id = $model->addReturnId([ 466 $parent_id = $model->addReturnId([
463 'project_id' => $project_id, 467 'project_id' => $project_id,
464 'title' => $item['name'], 468 'title' => $item['name'],
465 'pid' => $pid, 469 'pid' => $pid,
466 'keywords' => $item['keywords'] ?? '', 470 'keywords' => $item['keywords'] ?? '',
467 'describe' => $item['description'] ?? '', 471 'describe' => $item['description'] ?? '',
468 - 'route' => $this->get_url_route($item['url']) 472 + 'route' => $route
469 ]); 473 ]);
470 - $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id); 474 + $this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
471 } catch (\Exception $e) { 475 } catch (\Exception $e) {
472 echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL; 476 echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
473 continue; 477 continue;