UpdateController.php
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* @remark :
* @name :UpdateController.php
* @author :lyh
* @method :post
* @time :2023/8/19 9:08
*/
namespace App\Http\Controllers\Aside\Com;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Com\UpdateLog;
use App\Models\Domain\DomainInfo;
use App\Models\Project\ProjectUpdateTdk;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* @remark :b端网站更新相关
* @name :UpdateController
* @author :lyh
* @method :post
* @time :2023/8/19 9:08
*/
class UpdateController extends BaseController
{
/**
* @remark :一键更新所有tdk
* @name :updateSeoTdk
* @author :lyh
* @method :post
* @time :2023/8/19 9:25
*/
public function updateSeoTdk()
{
$this->request->validate([
'project_id' => 'required',
], [
'project_id.required' => 'project_id不能为空',
]);
ProjectUpdateTdk::add_task($this->param['project_id']);
$this->response('任务添加成功');
}
/**
* 采集项目所有内容
* @author Akun
* @date 2023/11/24 11:33
*/
public function dataCollect()
{
$this->request->validate([
'project_id' => 'required',
'type' => 'required',
], [
'project_id.required' => 'project_id不能为空',
'type.required' => '采集类型不能为空',
]);
$collect_un = UpdateLog::where('project_id', $this->param['project_id'])->where('collect_status', 0)->get();
if ($collect_un->count() > 0) {
$this->fail('项目正在采集中');
}
$project = ProjectServer::useProject($this->param['project_id']);
if (!$project) {
$this->fail('项目不存在');
}
if ($project->is_upgrade != 1) {
$this->fail('非升级无法进行采集操作');
}
try {
DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source` WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'");
DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = ''");
} catch (\Exception $e) {
errorLog('重新采集升级项目数据', $this->param, $e);
$this->fail('采集任务添加失败');
}
//关闭数据库
DB::disconnect('custom_mysql');
//查看项目是否已上线
$domain_info = DomainInfo::where('project_id', $this->param['project_id'])->first();
$update = ['collect_status' => 0];
if ($this->param['type'] == 2 && !$domain_info) {
$update['status'] = 0;
}
UpdateLog::where('project_id', $this->param['project_id'])->whereIn('api_type', ['post', 'page', 'news', 'blog'])->update($update);
$this->response('采集任务添加成功');
}
}