作者 李宇航

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

修改复制项目设置



查看合并请求 !1847
... ... @@ -69,7 +69,6 @@ class CopyProject extends Command
$item->status = NoticeLog::STATUS_FAIL;
$item->save();
}
sleep(60);
try {
$this->copyMysql($old_project_id,$project_id);
$this->output('CopyProjectJob end, old project_id: ' . $old_project_id . ', new project_id: ' . $project_id);
... ... @@ -210,6 +209,7 @@ class CopyProject extends Command
}
//复制数据库
public function copyMysql($project_id,$new_project_id){
echo '进入复制数据:'.PHP_EOL;
//切换数据库配置
$project = ProjectServer::useProject($new_project_id);
//创建数据库
... ... @@ -239,25 +239,16 @@ class CopyProject extends Command
foreach ($tables as $table) {
// 1. 删除目标数据库中的表
DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}");
// 2. 重新创建表
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}");
// 2. 复制建表 SQL
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`");
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
// 3. 跳过指定的表
if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form'])) {
continue;
}
try {
// 4. 重新插入数据
DB::connection('custom_mysql')->table($table)->insertUsing(
[], // 插入所有列
function ($query) use ($table, $project_id) {
$name = 'gl_data_' . $project_id . '.' . $table;
$query->select('*')->from("{$name}");
}
);
}catch (\Exception $e){
continue;
}
// 4. 原生 SQL 插入数据(完全复制)
$insert_sql = "INSERT INTO `{$table}` SELECT * FROM `gl_data_{$project_id}`.`{$table}`";
DB::connection('custom_mysql')->statement($insert_sql);
// 5. 更新 project_id(如果存在)
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
... ...
... ... @@ -195,6 +195,7 @@ class TranslateLogic extends BaseLogic
$texts = $dom->find("text");
$description = $dom->find("meta[name=description]",0);
$keywords = $dom->find("meta[name=keywords]",0);
$placeholders = $dom->find("[placeholder]");
// 组装需要翻译的内容 HTML内文案、meta description、meta keywords
$need_tran = [];
foreach ($texts as $k=>$text) {
... ... @@ -217,6 +218,12 @@ class TranslateLogic extends BaseLogic
$need_tran[] = htmlspecialchars_decode(html_entity_decode($string));
}
}
foreach ($placeholders as $placeholder) {
$placeholderText = trim($placeholder->placeholder);
if ($placeholderText) {
$need_tran[] = $placeholderText;
}
}
$need_tran[] = $description ? $description->attr['content'] : '';
$need_tran[] = $keywords ? $keywords->attr['content'] : '';
$need_tran = array_values(array_unique($need_tran));
... ...