|
@@ -5,6 +5,8 @@ namespace App\Http\Logic\Aside\Project; |
|
@@ -5,6 +5,8 @@ namespace App\Http\Logic\Aside\Project; |
|
5
|
use App\Models\Com\NoticeLog;
|
5
|
use App\Models\Com\NoticeLog;
|
|
6
|
use App\Models\Devops\ServerConfig;
|
6
|
use App\Models\Devops\ServerConfig;
|
|
7
|
use App\Models\Project\ProjectRenew;
|
7
|
use App\Models\Project\ProjectRenew;
|
|
|
|
8
|
+use App\Models\Template\BSettingTemplate;
|
|
|
|
9
|
+use App\Models\Template\Setting;
|
|
8
|
use App\Models\User\ProjectMenu;
|
10
|
use App\Models\User\ProjectMenu;
|
|
9
|
use App\Models\User\ProjectRole;
|
11
|
use App\Models\User\ProjectRole;
|
|
10
|
use App\Services\SyncService;
|
12
|
use App\Services\SyncService;
|
|
@@ -32,6 +34,7 @@ use Hashids\Hashids; |
|
@@ -32,6 +34,7 @@ use Hashids\Hashids; |
|
32
|
use App\Models\User\User as UserModel;
|
34
|
use App\Models\User\User as UserModel;
|
|
33
|
use Illuminate\Support\Facades\DB;
|
35
|
use Illuminate\Support\Facades\DB;
|
|
34
|
use Illuminate\Support\Facades\Log;
|
36
|
use Illuminate\Support\Facades\Log;
|
|
|
|
37
|
+use Illuminate\Support\Facades\Schema;
|
|
35
|
|
38
|
|
|
36
|
/**
|
39
|
/**
|
|
37
|
* Class ProjectLogic
|
40
|
* Class ProjectLogic
|
|
@@ -525,17 +528,104 @@ class ProjectLogic extends BaseLogic |
|
@@ -525,17 +528,104 @@ class ProjectLogic extends BaseLogic |
|
525
|
//复制初始项目
|
528
|
//复制初始项目
|
|
526
|
$data = $this->model::where('id', $this->param['project_id'])->first();
|
529
|
$data = $this->model::where('id', $this->param['project_id'])->first();
|
|
527
|
$data = $data->getAttributes();
|
530
|
$data = $data->getAttributes();
|
|
|
|
531
|
+ $data['type'] = 0;
|
|
|
|
532
|
+ $data['title'] = $data['title'].'-copy';
|
|
528
|
unset($data['id']);
|
533
|
unset($data['id']);
|
|
529
|
$project_id = $this->model->insertGetId($data);
|
534
|
$project_id = $this->model->insertGetId($data);
|
|
530
|
//复制部署表
|
535
|
//复制部署表
|
|
531
|
$buildModel = new DeployBuild();
|
536
|
$buildModel = new DeployBuild();
|
|
532
|
- $buildData = $buildModel::where('id', $this->param['project_id'])->first();
|
|
|
|
533
|
- $buildData = $buildData->getAttributes();
|
|
|
|
534
|
- $buildData['project_id'] = $project_id;
|
|
|
|
535
|
- unset($buildData['id']);
|
|
|
|
536
|
- $buildModel->insert($buildData);
|
537
|
+ $buildData = $buildModel::where('project_id', $this->param['project_id'])->first();
|
|
|
|
538
|
+ if(!empty($buildData)){
|
|
|
|
539
|
+ $buildData = $buildData->getAttributes();
|
|
|
|
540
|
+ $buildData['project_id'] = $project_id;
|
|
|
|
541
|
+ $hashids = new Hashids('test_domain', 5, 'abcdefghjkmnpqrstuvwxyz1234567890');
|
|
|
|
542
|
+ $code = $hashids->encode($project_id);
|
|
|
|
543
|
+ $buildData['test_domain'] = 'https://v6-' . $code . '.globalso.site/';
|
|
|
|
544
|
+ unset($buildData['id']);
|
|
|
|
545
|
+ $buildModel->insert($buildData);
|
|
|
|
546
|
+ }
|
|
537
|
//复制优化表
|
547
|
//复制优化表
|
|
538
|
$optimizeModel = new DeployOptimize();
|
548
|
$optimizeModel = new DeployOptimize();
|
|
|
|
549
|
+ $optimizeData = $optimizeModel::where('project_id', $this->param['project_id'])->first();
|
|
|
|
550
|
+ if(!empty($optimizeData)){
|
|
|
|
551
|
+ $optimizeData = $optimizeData->getAttributes();
|
|
|
|
552
|
+ unset($optimizeData['id'],$optimizeData['domain']);
|
|
|
|
553
|
+ $optimizeData['project_id'] = $project_id;
|
|
|
|
554
|
+ $optimizeModel->insert($optimizeData);
|
|
|
|
555
|
+ }
|
|
|
|
556
|
+ //复制付费表
|
|
|
|
557
|
+ $paymentModel = new Payment();
|
|
|
|
558
|
+ $paymentData = $paymentModel::where('project_id', $this->param['project_id'])->first();
|
|
|
|
559
|
+ if(!empty($paymentData)){
|
|
|
|
560
|
+ $paymentData = $paymentData->getAttributes();
|
|
|
|
561
|
+ unset($paymentData['id']);
|
|
|
|
562
|
+ $paymentData['project_id'] = $project_id;
|
|
|
|
563
|
+ $paymentModel->insert($paymentData);
|
|
|
|
564
|
+ }
|
|
|
|
565
|
+ //复制用户
|
|
|
|
566
|
+ $userModel = new UserModel();
|
|
|
|
567
|
+ $userData = $userModel::where('project_id', $this->param['project_id'])->where('role_id',0)->first();
|
|
|
|
568
|
+ if(!empty($userData)){
|
|
|
|
569
|
+ $userData = $userData->getAttributes();
|
|
|
|
570
|
+ unset($userData['id']);
|
|
|
|
571
|
+ $userData['project_id'] = $project_id;
|
|
|
|
572
|
+ $userModel->insert($userData);
|
|
|
|
573
|
+ }
|
|
|
|
574
|
+ //复制设置的模版
|
|
|
|
575
|
+ $settingTemplateModel = new Setting();
|
|
|
|
576
|
+ $settingData = $settingTemplateModel::where('project_id', $this->param['project_id'])->first();
|
|
|
|
577
|
+ if(!empty($settingData)){
|
|
|
|
578
|
+ $settingData = $settingData->getAttributes();
|
|
|
|
579
|
+ unset($settingData['id']);
|
|
|
|
580
|
+ $settingData['project_id'] = $project_id;
|
|
|
|
581
|
+ $settingTemplateModel->insert($settingData);
|
|
|
|
582
|
+ }
|
|
|
|
583
|
+ $this->copyMysql($this->param['project_id'],$project_id);
|
|
539
|
return $this->success($data);
|
584
|
return $this->success($data);
|
|
540
|
}
|
585
|
}
|
|
|
|
586
|
+
|
|
|
|
587
|
+ //复制数据库
|
|
|
|
588
|
+ public function copyMysql($project_id,$new_project_id){
|
|
|
|
589
|
+ //切换数据库配置
|
|
|
|
590
|
+ $project = ProjectServer::useProject($new_project_id);
|
|
|
|
591
|
+ //创建数据库
|
|
|
|
592
|
+ ProjectServer::createDatabase($project);
|
|
|
|
593
|
+ //创建表
|
|
|
|
594
|
+ $this->initTable($project_id,$new_project_id);
|
|
|
|
595
|
+ }
|
|
|
|
596
|
+
|
|
|
|
597
|
+
|
|
|
|
598
|
+ /**
|
|
|
|
599
|
+ * @param $project
|
|
|
|
600
|
+ * @return bool
|
|
|
|
601
|
+ * @author zbj
|
|
|
|
602
|
+ * @date 2023/4/23
|
|
|
|
603
|
+ */
|
|
|
|
604
|
+ public function initTable($project_id,$news_project_id)
|
|
|
|
605
|
+ {
|
|
|
|
606
|
+ config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_'.$project_id]);
|
|
|
|
607
|
+ $database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
|
|
|
|
608
|
+ $tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
|
|
|
|
609
|
+ $tables = array_column($tables, 'Tables_in_' . $database_name);
|
|
|
|
610
|
+ foreach ($tables as $table) {
|
|
|
|
611
|
+ $has_table = Schema::connection('custom_mysql')->hasTable($table);
|
|
|
|
612
|
+ if (!$has_table) {
|
|
|
|
613
|
+ $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}");
|
|
|
|
614
|
+ DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
|
|
|
|
615
|
+ }
|
|
|
|
616
|
+ DB::connection('custom_mysql')->table($table)->truncate(); // 清空目标表数据
|
|
|
|
617
|
+ DB::connection('custom_mysql')->table($table)->insertUsing(
|
|
|
|
618
|
+ [], // 列名数组,留空表示插入所有列
|
|
|
|
619
|
+ function ($query) use ($table,$project_id) {
|
|
|
|
620
|
+ $name = 'gl_data_'.$project_id.'.'.$table;
|
|
|
|
621
|
+ $query->select('*')->from("{$name}");
|
|
|
|
622
|
+ }
|
|
|
|
623
|
+ );
|
|
|
|
624
|
+ if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
|
|
|
|
625
|
+ DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
|
|
|
|
626
|
+ }
|
|
|
|
627
|
+ }
|
|
|
|
628
|
+ return true;
|
|
|
|
629
|
+ }
|
|
|
|
630
|
+
|
|
541
|
} |
631
|
} |