|
...
|
...
|
@@ -575,13 +575,13 @@ class ProjectLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
//复制数据库
|
|
|
|
public function copyMysql($new_project_id){
|
|
|
|
public function copyMysql($project_id,$new_project_id){
|
|
|
|
//切换数据库配置
|
|
|
|
ProjectServer::useProject($new_project_id);
|
|
|
|
//创建数据库
|
|
|
|
ProjectServer::createDatabase($new_project_id);
|
|
|
|
//创建表
|
|
|
|
$this->initTable();
|
|
|
|
$this->initTable($project_id,$new_project_id);
|
|
|
|
//初始数据
|
|
|
|
ProjectServer::saveInitParam($new_project_id);
|
|
|
|
}
|
|
...
|
...
|
@@ -595,22 +595,21 @@ class ProjectLogic extends BaseLogic |
|
|
|
*/
|
|
|
|
public function initTable($project_id,$news_project_id)
|
|
|
|
{
|
|
|
|
config(['database.connections.custom_tmp_mysql.database' => 'gl_data_'.$project_id]);
|
|
|
|
$database_name = DB::connection('custom_tmp_mysql')->getDatabaseName();
|
|
|
|
$table = Schema::connection('custom_tmp_mysql')->getAllTables();
|
|
|
|
config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_'.$project_id]);
|
|
|
|
$database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
|
|
|
|
$table = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
|
|
|
|
$table = array_column($table, 'Tables_in_' . $database_name);
|
|
|
|
foreach ($table as $v) {
|
|
|
|
$has_table = Schema::connection('custom_mysql')->hasTable($v);
|
|
|
|
if ($has_table) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$sql = DB::connection('custom_tmp_mysql')->select("SHOW CREATE TABLE {$v}");
|
|
|
|
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$v}");
|
|
|
|
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
|
|
|
|
Schema::table($v, function ($v) use ($news_project_id) {
|
|
|
|
$v->update(['project_id' => $news_project_id]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
config(['database.connections.custom_tmp_mysql.database' => 'gl_data_tmp']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|