作者 刘锟

导入bug修复

@@ -69,7 +69,7 @@ class ProjectImport extends Command @@ -69,7 +69,7 @@ class ProjectImport extends Command
69 $task->status = ImportTask::STATUS_COM;//导入完成 69 $task->status = ImportTask::STATUS_COM;//导入完成
70 $task->save(); 70 $task->save();
71 71
72 - $this->send_mail($task->user_id, $task->created_at, $task->type, 0, 0, '文件编码格式错误,仅支持UTF-8和GBK编码格式'); 72 + $this->send_mail($task->user_id, $task->created_at, $task->type, 0, 0, 0, '文件编码格式错误,仅支持UTF-8和GBK编码格式');
73 return true; 73 return true;
74 } elseif ($file_code_type === 'GBK') { 74 } elseif ($file_code_type === 'GBK') {
75 $is_gbk = 1; 75 $is_gbk = 1;
@@ -89,13 +89,14 @@ class ProjectImport extends Command @@ -89,13 +89,14 @@ class ProjectImport extends Command
89 $task->status = ImportTask::STATUS_COM;//导入完成 89 $task->status = ImportTask::STATUS_COM;//导入完成
90 $task->save(); 90 $task->save();
91 91
92 - $this->send_mail($task->user_id, $task->created_at, $task->type, 0, 0, '读取文件数据失败'); 92 + $this->send_mail($task->user_id, $task->created_at, $task->type, 0, 0, 0, '读取文件数据失败');
93 return true; 93 return true;
94 } 94 }
95 95
96 $total_count = 0; //总条数 96 $total_count = 0; //总条数
97 $success_count = 0; //成功导入条数 97 $success_count = 0; //成功导入条数
98 $repeat_count = 0; //过滤已存在条数 98 $repeat_count = 0; //过滤已存在条数
  99 + $fail_count = 0;
99 if (count($line_of_text) > 1) { 100 if (count($line_of_text) > 1) {
100 101
101 //设置数据库 102 //设置数据库
@@ -132,6 +133,7 @@ class ProjectImport extends Command @@ -132,6 +133,7 @@ class ProjectImport extends Command
132 } 133 }
133 } 134 }
134 } catch (\Exception $e) { 135 } catch (\Exception $e) {
  136 + $fail_count += 1;
135 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', title: ' . $v[0] . ', import fail, error: ' . $e->getMessage() . PHP_EOL; 137 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', title: ' . $v[0] . ', import fail, error: ' . $e->getMessage() . PHP_EOL;
136 } 138 }
137 } 139 }
@@ -146,7 +148,7 @@ class ProjectImport extends Command @@ -146,7 +148,7 @@ class ProjectImport extends Command
146 $task->success_count += $success_count; 148 $task->success_count += $success_count;
147 $task->save(); 149 $task->save();
148 150
149 - $this->send_mail($task->user_id, $task->created_at, $task->type, $success_count, $repeat_count, ''); 151 + $this->send_mail($task->user_id, $task->created_at, $task->type, $success_count, $fail_count, $repeat_count, '');
150 152
151 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import end, total count: ' . $total_count . ', success count: ' . $success_count . PHP_EOL; 153 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import end, total count: ' . $total_count . ', success count: ' . $success_count . PHP_EOL;
152 154
@@ -190,7 +192,7 @@ class ProjectImport extends Command @@ -190,7 +192,7 @@ class ProjectImport extends Command
190 } 192 }
191 193
192 //发送站内通知 194 //发送站内通知
193 - protected function send_mail($user_list, $time, $type, $success_count, $repeat_count, $reason) 195 + protected function send_mail($user_list, $time, $type, $success_count, $repeat_count, $fail_count, $reason)
194 { 196 {
195 if ($type == ImportTask::TYPE_NEWS) { 197 if ($type == ImportTask::TYPE_NEWS) {
196 $type_content = '新闻'; 198 $type_content = '新闻';
@@ -202,6 +204,7 @@ class ProjectImport extends Command @@ -202,6 +204,7 @@ class ProjectImport extends Command
202 $title = '导入结果通知'; 204 $title = '导入结果通知';
203 $content = '您于 ' . $time . ' 添加的 ' . $type_content . ' 导入任务已执行完成, 成功导入数据:' . $success_count . ' 条'; 205 $content = '您于 ' . $time . ' 添加的 ' . $type_content . ' 导入任务已执行完成, 成功导入数据:' . $success_count . ' 条';
204 $repeat_count && $content .= ',过滤已存在数据:' . $repeat_count . ' 条'; 206 $repeat_count && $content .= ',过滤已存在数据:' . $repeat_count . ' 条';
  207 + $fail_count && $content .= ',导入失败:' . $fail_count . ' 条';
205 $reason && $content .= ',原因:' . $reason; 208 $reason && $content .= ',原因:' . $reason;
206 209
207 $mail_model = new Mail(); 210 $mail_model = new Mail();
@@ -311,7 +311,7 @@ class BlogLogic extends BaseLogic @@ -311,7 +311,7 @@ class BlogLogic extends BaseLogic
311 ] 311 ]
312 ); 312 );
313 //更新路由 313 //更新路由
314 - $route = RouteMap::setRoute($data[1] ?: $data[0], RouteMap::SOURCE_BLOG, $id, $project_id); 314 + $route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_BLOG, $id, $project_id);
315 $this->edit(['url' => $route], ['id' => $id]); 315 $this->edit(['url' => $route], ['id' => $id]);
316 316
317 return true; 317 return true;
@@ -310,7 +310,7 @@ class NewsLogic extends BaseLogic @@ -310,7 +310,7 @@ class NewsLogic extends BaseLogic
310 ] 310 ]
311 ); 311 );
312 //更新路由 312 //更新路由
313 - $route = RouteMap::setRoute($data[1] ?: $data[0], RouteMap::SOURCE_NEWS, $id, $project_id); 313 + $route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_NEWS, $id, $project_id);
314 $this->edit(['url' => $route], ['id' => $id]); 314 $this->edit(['url' => $route], ['id' => $id]);
315 315
316 return true; 316 return true;
@@ -469,7 +469,7 @@ class ProductLogic extends BaseLogic @@ -469,7 +469,7 @@ class ProductLogic extends BaseLogic
469 ] 469 ]
470 ); 470 );
471 //更新路由 471 //更新路由
472 - $route = RouteMap::setRoute($data[1] ?: $data[0], RouteMap::SOURCE_PRODUCT, $id, $project_id); 472 + $route = RouteMap::setRoute((isset($data[1]) && $data[1]) ? $data[1] : $data[0], RouteMap::SOURCE_PRODUCT, $id, $project_id);
473 $this->edit(['route' => $route], ['id' => $id]); 473 $this->edit(['route' => $route], ['id' => $id]);
474 474
475 return true; 475 return true;