替换域名
This commit is contained in:
parent
ed4e4c02a7
commit
762e93bd33
|
|
@ -943,9 +943,15 @@ class SurveyController extends BaseController{
|
|||
// 获取全部数据库列表
|
||||
$tables = $this->getAllTable();
|
||||
// 获取存在数据的表
|
||||
$hasTable = $this->getHasDataTable($tables,$notCleanUp);
|
||||
// $hasTable = $this->getHasDataTable($tables,$notCleanUp);
|
||||
// debug($hasTable);
|
||||
|
||||
|
||||
|
||||
// 域名替换
|
||||
// $this->domainNameReplacement($tables,[]);
|
||||
// debug("结束");
|
||||
|
||||
debug($hasTable);
|
||||
// 执行清除操作
|
||||
// foreach($tables as $name){
|
||||
// if(!in_array($name,$notCleanUp)){
|
||||
|
|
@ -1000,6 +1006,60 @@ debug($hasTable);
|
|||
|
||||
return $count > 0;
|
||||
}
|
||||
// 数据库处理 - 域名替换 - 开始处理
|
||||
private function domainNameReplacement($tables,$notCleanUp){
|
||||
$tableList = [];
|
||||
foreach($tables as $tableName){
|
||||
if(!in_array($tableName,$notCleanUp)){
|
||||
echo "{$tableName}\n\r";
|
||||
// 获取字段信息
|
||||
$allFieldDesc = \DB::select("show columns from {$tableName}");
|
||||
$allField = array_column($allFieldDesc,'Field');
|
||||
// if($this->isHasSpecifyData($allField,$name)) $tableList[] = $name;
|
||||
|
||||
|
||||
$res = $this->isHasSpecifyData($allField,$tableName);
|
||||
echo $res ? "存在\n\r" : "不存在\n\r";
|
||||
if($res){
|
||||
// 批量替换
|
||||
$query = "UPDATE {$tableName} SET ";
|
||||
$handleFieldNum = 0;
|
||||
foreach($allFieldDesc as $fieldInfo){
|
||||
if(strpos($fieldInfo['Type'], 'int') !== false || $fieldInfo['Key'] == 'PRI') continue;
|
||||
|
||||
$fieldName = $fieldInfo['Field'];
|
||||
$query .= "`{$fieldName}` = REPLACE(`{$fieldName}`,'testbzt.cdlfjy.com','shuizhi.test.cdlfjy.com'),";
|
||||
++$handleFieldNum;
|
||||
}
|
||||
$query = trim($query);
|
||||
$query = trim($query,',');
|
||||
$query = trim($query);
|
||||
echo "SQL({$handleFieldNum}):{$query}\n";
|
||||
if($handleFieldNum > 0) \DB::select($query);
|
||||
}
|
||||
|
||||
echo "\n\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $tableList;
|
||||
}
|
||||
// 数据库处理 - 域名替换 - 生成sql
|
||||
private function isHasSpecifyData($allField,$tableName){
|
||||
$query = "select * from {$tableName} where (";
|
||||
foreach($allField as $fieldName){
|
||||
$query .= "`{$fieldName}` like '%testbzt.cdlfjy.com%' OR ";
|
||||
}
|
||||
$query = trim($query);
|
||||
$query = trim($query,'OR');
|
||||
$query = trim($query) . ")";
|
||||
|
||||
$result = \DB::select($query);
|
||||
if($result) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue