作者 李宇航

合并分支 'lyh-server' 到 'master'

修改复制项目设置



查看合并请求 !1847
@@ -69,7 +69,6 @@ class CopyProject extends Command @@ -69,7 +69,6 @@ class CopyProject extends Command
69 $item->status = NoticeLog::STATUS_FAIL; 69 $item->status = NoticeLog::STATUS_FAIL;
70 $item->save(); 70 $item->save();
71 } 71 }
72 - sleep(60);  
73 try { 72 try {
74 $this->copyMysql($old_project_id,$project_id); 73 $this->copyMysql($old_project_id,$project_id);
75 $this->output('CopyProjectJob end, old project_id: ' . $old_project_id . ', new project_id: ' . $project_id); 74 $this->output('CopyProjectJob end, old project_id: ' . $old_project_id . ', new project_id: ' . $project_id);
@@ -210,6 +209,7 @@ class CopyProject extends Command @@ -210,6 +209,7 @@ class CopyProject extends Command
210 } 209 }
211 //复制数据库 210 //复制数据库
212 public function copyMysql($project_id,$new_project_id){ 211 public function copyMysql($project_id,$new_project_id){
  212 + echo '进入复制数据:'.PHP_EOL;
213 //切换数据库配置 213 //切换数据库配置
214 $project = ProjectServer::useProject($new_project_id); 214 $project = ProjectServer::useProject($new_project_id);
215 //创建数据库 215 //创建数据库
@@ -239,25 +239,16 @@ class CopyProject extends Command @@ -239,25 +239,16 @@ class CopyProject extends Command
239 foreach ($tables as $table) { 239 foreach ($tables as $table) {
240 // 1. 删除目标数据库中的表 240 // 1. 删除目标数据库中的表
241 DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}"); 241 DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}");
242 - // 2. 重新创建表  
243 - $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}"); 242 + // 2. 复制建表 SQL
  243 + $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`");
244 DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']); 244 DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
245 // 3. 跳过指定的表 245 // 3. 跳过指定的表
246 if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form'])) { 246 if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form'])) {
247 continue; 247 continue;
248 } 248 }
249 - try {  
250 - // 4. 重新插入数据  
251 - DB::connection('custom_mysql')->table($table)->insertUsing(  
252 - [], // 插入所有列  
253 - function ($query) use ($table, $project_id) {  
254 - $name = 'gl_data_' . $project_id . '.' . $table;  
255 - $query->select('*')->from("{$name}");  
256 - }  
257 - );  
258 - }catch (\Exception $e){  
259 - continue;  
260 - } 249 + // 4. 原生 SQL 插入数据(完全复制)
  250 + $insert_sql = "INSERT INTO `{$table}` SELECT * FROM `gl_data_{$project_id}`.`{$table}`";
  251 + DB::connection('custom_mysql')->statement($insert_sql);
261 // 5. 更新 project_id(如果存在) 252 // 5. 更新 project_id(如果存在)
262 if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) { 253 if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
263 DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]); 254 DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
@@ -195,6 +195,7 @@ class TranslateLogic extends BaseLogic @@ -195,6 +195,7 @@ class TranslateLogic extends BaseLogic
195 $texts = $dom->find("text"); 195 $texts = $dom->find("text");
196 $description = $dom->find("meta[name=description]",0); 196 $description = $dom->find("meta[name=description]",0);
197 $keywords = $dom->find("meta[name=keywords]",0); 197 $keywords = $dom->find("meta[name=keywords]",0);
  198 + $placeholders = $dom->find("[placeholder]");
198 // 组装需要翻译的内容 HTML内文案、meta description、meta keywords 199 // 组装需要翻译的内容 HTML内文案、meta description、meta keywords
199 $need_tran = []; 200 $need_tran = [];
200 foreach ($texts as $k=>$text) { 201 foreach ($texts as $k=>$text) {
@@ -217,6 +218,12 @@ class TranslateLogic extends BaseLogic @@ -217,6 +218,12 @@ class TranslateLogic extends BaseLogic
217 $need_tran[] = htmlspecialchars_decode(html_entity_decode($string)); 218 $need_tran[] = htmlspecialchars_decode(html_entity_decode($string));
218 } 219 }
219 } 220 }
  221 + foreach ($placeholders as $placeholder) {
  222 + $placeholderText = trim($placeholder->placeholder);
  223 + if ($placeholderText) {
  224 + $need_tran[] = $placeholderText;
  225 + }
  226 + }
220 $need_tran[] = $description ? $description->attr['content'] : ''; 227 $need_tran[] = $description ? $description->attr['content'] : '';
221 $need_tran[] = $keywords ? $keywords->attr['content'] : ''; 228 $need_tran[] = $keywords ? $keywords->attr['content'] : '';
222 $need_tran = array_values(array_unique($need_tran)); 229 $need_tran = array_values(array_unique($need_tran));