合优网对象存储附件合并及域名替换方案
2024-08-22合优网打野哥285°c
A+ A-原域名:p1.cqhc.cn
替换为:img.app.cqhc.cn
存储位置:均为七牛对象存储(在控制台进行跨区域同步)
1、修改现有所有的包含原域名的程序配置为新域名
2、对象储存跨局域同步/数据迁移
3、创建原域名站点,使用301跳转到新域名(两个作用:跳转、检测是否替换完)
4、使用Navicat全表查询原域名,对有此域名的数据表进行分析
5、正常替换命令:
update 表名 set 字段 = replace(字段,'需要被替换的内容','替换后的内容')
注意:序列化、二进制(暂时只遇到这两种) 保存的数据不能使用上方命令替换
对于 序列化 数据,参考以下方式(thinkphp):
public function index()
{
if (request()->isAjax()) {
$table = 'pre_xigua_sp_order';
$field = 'goodinfo';
$host = 'p1.cqhc.cn';
$new_host = 'img.app.cqhc.cn';
$kid = 'id'; // 主键id
$starttime = microtime(1);
//$data = Db::table($table)->where($field, 'like', "%$host%")->find();
$id = cache($table. '_kid');
$data = Db::table($table)->where($kid,'>', $id ? $id : 0)->where($field, 'like', "%$host%")->order($kid, 'asc')->find();
if ($data) {
//sleep(1); // 1000ms
//usleep(100000); // 100ms
//echo $data[$field];
$d_json = json_encode(unserialize($data[$field]),JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
$d_json = str_replace('http://'.$host.'/', 'https://'.$new_host.'/', $d_json);
$d_json = str_replace('https://'.$host.'/', 'https://'.$new_host.'/', $d_json);
$in_data = serialize(json_decode($d_json, true));
Db::table($table)->where($kid, $data[$kid])->update([$field => $in_data]);
cache($table. '_kid', $data[$kid], 60);
return json(['code' => 200, 'msg' => 'success_' . $data[$kid] . '_' . number_format((microtime(1) - $starttime) * 1000,1), 'data' => json_encode($in_data,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE)]);
}
return json(['code' => 1, 'msg' => 'success_end_' . number_format((microtime(1) - $starttime) * 1000,1), 'data' => json_encode($data,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE)]);
}
return view();
}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>music cron</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script src="https://cdn.heyou.vip/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body style="background-color: black;">
<div id="content" style="color: #00d640;font-size: 12px;">
</div>
</body>
<script>
$("#content").prepend('<p> >> 任务开始执行,请稍后。。。</p>');
check();
function check(){
$.ajax({
'type': 'get',
'success': function(s){
var content = '<p>' + s.code + '_' + s.msg + '_' + s.data + '</p>';
if(($("#content").html()).length > 3000){
$("#content").html('<p>--------清----除--------</p>');
}
$("#content").prepend(content);
if(s.code == 200){
check();
}else{
$("#content").prepend('<p> >> 任务结束</p>');
}
},
error: function(){
$("#content").prepend('<p> >> 遇到了什么错误....</p>');
$("#content").prepend('<p> >> 任务结束</p>');
}
});
}
</script>
</html>6、替换完成后,使用数据库全表查询或者跳转站点日志来判断是否有没有替换的链接。
未定义标签



