|
@@ -575,13 +575,13 @@ class ProjectLogic extends BaseLogic |
|
@@ -575,13 +575,13 @@ class ProjectLogic extends BaseLogic |
|
575
|
}
|
575
|
}
|
|
576
|
|
576
|
|
|
577
|
//复制数据库
|
577
|
//复制数据库
|
|
578
|
- public function copyMysql($new_project_id){
|
578
|
+ public function copyMysql($project_id,$new_project_id){
|
|
579
|
//切换数据库配置
|
579
|
//切换数据库配置
|
|
580
|
ProjectServer::useProject($new_project_id);
|
580
|
ProjectServer::useProject($new_project_id);
|
|
581
|
//创建数据库
|
581
|
//创建数据库
|
|
582
|
ProjectServer::createDatabase($new_project_id);
|
582
|
ProjectServer::createDatabase($new_project_id);
|
|
583
|
//创建表
|
583
|
//创建表
|
|
584
|
- $this->initTable();
|
584
|
+ $this->initTable($project_id,$new_project_id);
|
|
585
|
//初始数据
|
585
|
//初始数据
|
|
586
|
ProjectServer::saveInitParam($new_project_id);
|
586
|
ProjectServer::saveInitParam($new_project_id);
|
|
587
|
}
|
587
|
}
|
|
@@ -595,22 +595,21 @@ class ProjectLogic extends BaseLogic |
|
@@ -595,22 +595,21 @@ class ProjectLogic extends BaseLogic |
|
595
|
*/
|
595
|
*/
|
|
596
|
public function initTable($project_id,$news_project_id)
|
596
|
public function initTable($project_id,$news_project_id)
|
|
597
|
{
|
597
|
{
|
|
598
|
- config(['database.connections.custom_tmp_mysql.database' => 'gl_data_'.$project_id]);
|
|
|
|
599
|
- $database_name = DB::connection('custom_tmp_mysql')->getDatabaseName();
|
|
|
|
600
|
- $table = Schema::connection('custom_tmp_mysql')->getAllTables();
|
598
|
+ config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_'.$project_id]);
|
|
|
|
599
|
+ $database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
|
|
|
|
600
|
+ $table = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
|
|
601
|
$table = array_column($table, 'Tables_in_' . $database_name);
|
601
|
$table = array_column($table, 'Tables_in_' . $database_name);
|
|
602
|
foreach ($table as $v) {
|
602
|
foreach ($table as $v) {
|
|
603
|
$has_table = Schema::connection('custom_mysql')->hasTable($v);
|
603
|
$has_table = Schema::connection('custom_mysql')->hasTable($v);
|
|
604
|
if ($has_table) {
|
604
|
if ($has_table) {
|
|
605
|
continue;
|
605
|
continue;
|
|
606
|
}
|
606
|
}
|
|
607
|
- $sql = DB::connection('custom_tmp_mysql')->select("SHOW CREATE TABLE {$v}");
|
607
|
+ $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$v}");
|
|
608
|
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
|
608
|
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
|
|
609
|
Schema::table($v, function ($v) use ($news_project_id) {
|
609
|
Schema::table($v, function ($v) use ($news_project_id) {
|
|
610
|
$v->update(['project_id' => $news_project_id]);
|
610
|
$v->update(['project_id' => $news_project_id]);
|
|
611
|
});
|
611
|
});
|
|
612
|
}
|
612
|
}
|
|
613
|
- config(['database.connections.custom_tmp_mysql.database' => 'gl_data_tmp']);
|
|
|
|
614
|
return true;
|
613
|
return true;
|
|
615
|
}
|
614
|
}
|
|
616
|
|
615
|
|