no message
This commit is contained in:
parent
2a3b82fa35
commit
bb9e20bd9b
@ -5,6 +5,8 @@
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use App\Models\ArticleLikes;
|
use App\Models\ArticleLikes;
|
||||||
|
use App\Models\Categories;
|
||||||
|
use App\Models\Articles;
|
||||||
|
|
||||||
class ClearDb extends Command
|
class ClearDb extends Command
|
||||||
{
|
{
|
||||||
@ -15,11 +17,28 @@ public function handle(): void
|
|||||||
{
|
{
|
||||||
$this->info("开始清理过期数据...");
|
$this->info("开始清理过期数据...");
|
||||||
|
|
||||||
|
$this->article();
|
||||||
$this->articleLikes();
|
$this->articleLikes();
|
||||||
|
|
||||||
$this->info("数据清理完成 !");
|
$this->info("数据清理完成 !");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function article()
|
||||||
|
{
|
||||||
|
$aCateId = Categories::whereIn("sSlug", ["freenode", "shadowrocketids"])->pluck("id")->toArray();
|
||||||
|
|
||||||
|
if (empty($aCateId)) {
|
||||||
|
$this->info("没有匹配的分类,跳过清理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sDate = date('Y-m-d', strtotime('-180 days'));
|
||||||
|
|
||||||
|
$i = Articles::whereIn("iCategoryId", $aCateId)->whereDate("created_at", "<", $sDate)->delete();
|
||||||
|
|
||||||
|
$this->info("清理 {$i} 条数据");
|
||||||
|
}
|
||||||
|
|
||||||
private function articleLikes()
|
private function articleLikes()
|
||||||
{
|
{
|
||||||
// 1. 确定 30 天前的时间点
|
// 1. 确定 30 天前的时间点
|
||||||
|
|||||||
98
app/Http/Controllers/Api/v1/GithubController.php
Executable file
98
app/Http/Controllers/Api/v1/GithubController.php
Executable file
@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api\v1;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
//use voku\helper\AntiXSS;
|
||||||
|
use App\Models\ArticleList as Article;
|
||||||
|
use App\Http\Services\FreenodeHelperService;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
class GithubController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function todayUpd()
|
||||||
|
{
|
||||||
|
|
||||||
|
$sCode = date("Ymd");
|
||||||
|
|
||||||
|
$bUpd = Article::where("code", $sCode)->exists();
|
||||||
|
|
||||||
|
return $bUpd;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLast()
|
||||||
|
{
|
||||||
|
// $sCode = date("Ymd");
|
||||||
|
|
||||||
|
$aToday = Article::orderBy("id", "desc")->first()->toArray();
|
||||||
|
|
||||||
|
echo json_encode($aToday);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 始终返回数据,今天没有就是前一天,前一天没有就是异常情况
|
||||||
|
public function getFnToday($sDate = false)
|
||||||
|
{
|
||||||
|
$sMasterUrl = "https://".$_ENV["url_master_base"];
|
||||||
|
$sSiteCodeShort = $_ENV["site_code_short"];
|
||||||
|
|
||||||
|
$oResponse = Http::withOptions([
|
||||||
|
'verify' => false, // 禁用 SSL 证书检查
|
||||||
|
])
|
||||||
|
->timeout(8)
|
||||||
|
->get($sMasterUrl."/api/v1/freenode/url_feed_today/".$sSiteCodeShort);
|
||||||
|
|
||||||
|
$aData = [];
|
||||||
|
$rcode = 400;
|
||||||
|
if ($oResponse->successful()) {
|
||||||
|
$aData = $oResponse->json();
|
||||||
|
$rcode = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aData["code"] = $rcode;
|
||||||
|
|
||||||
|
return $aData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// echo 1233;exit;
|
||||||
|
// if (!$sDate) {
|
||||||
|
// $sDate = date("Ymd");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $sCode = $sDate;
|
||||||
|
//
|
||||||
|
// //// test
|
||||||
|
// // 20250721 - 23 有数据
|
||||||
|
//// $sCode = "20250720";
|
||||||
|
//
|
||||||
|
// $bUpd = Article::where("code", $sCode)->exists();
|
||||||
|
//
|
||||||
|
// if ($bUpd === true) {
|
||||||
|
// $sCodeTrue = $sCode;
|
||||||
|
// } else {
|
||||||
|
// $sCodeTrue = date("Ymd", strtotime("-1 day"));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $sFilePathClash = "sub/".$sCodeTrue."-clash.yaml";
|
||||||
|
// $sFilePathV2ray = "sub/".$sCodeTrue."-v2ray.txt";
|
||||||
|
//
|
||||||
|
// $sFileClash = file_get_contents($sFilePathClash);
|
||||||
|
// $sFileV2ray = file_get_contents($sFilePathV2ray);
|
||||||
|
//
|
||||||
|
// $aData = [
|
||||||
|
// "code" => "100",
|
||||||
|
// "clash" => $sFileClash,
|
||||||
|
// "v2ray" => $sFileV2ray
|
||||||
|
// ];
|
||||||
|
//
|
||||||
|
// echo json_encode($aData);
|
||||||
|
//
|
||||||
|
// exit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -5,6 +5,11 @@
|
|||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\Api\Tg\HookController;
|
use App\Http\Controllers\Api\Tg\HookController;
|
||||||
use App\Http\Controllers\Api\Nasa\V1\CategoryBaseController as NasaV1CategoryBaseController;
|
use App\Http\Controllers\Api\Nasa\V1\CategoryBaseController as NasaV1CategoryBaseController;
|
||||||
|
use App\Http\Controllers\Api\v1\GithubController;
|
||||||
|
|
||||||
|
Route::get('/github/todayupd', [GithubController::class, 'todayUpd']);
|
||||||
|
Route::get('/github/getlast', [GithubController::class, 'getLast']);
|
||||||
|
Route::get('/github/getfntoday/{date?}', [GithubController::class, 'getFnToday']);
|
||||||
|
|
||||||
Route::prefix('nasa/v1')->middleware('nasa.auth')->group(function () {
|
Route::prefix('nasa/v1')->middleware('nasa.auth')->group(function () {
|
||||||
|
|
||||||
|
|||||||
@ -10,39 +10,6 @@
|
|||||||
$this->comment(Inspiring::quote());
|
$this->comment(Inspiring::quote());
|
||||||
})->purpose('Display an inspiring quote');
|
})->purpose('Display an inspiring quote');
|
||||||
|
|
||||||
Artisan::command('db:reCreate {sTableName?}', function ($sTableName = null) {
|
|
||||||
// 1. 没传参数?直接亮红牌!
|
|
||||||
if (empty($sTableName)) {
|
|
||||||
$this->error('错误:必须指定要重建的表名!我可不想乱开火。');
|
|
||||||
$this->info('用法示例:php artisan db:reCreate slave_sites');
|
|
||||||
return; // 直接撤退,不往下走
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 确定目标
|
|
||||||
$sTable = $sTableName;
|
|
||||||
|
|
||||||
// 3. 检查表是否存在(不存在炸个寂寞?)
|
|
||||||
if (!Schema::hasTable($sTable)) {
|
|
||||||
$this->warn("目标表 [{$sTable}] 本就不存在,但我还是会清理迁移记录并尝试重建。");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 物理抹除表
|
|
||||||
Schema::dropIfExists($sTable);
|
|
||||||
|
|
||||||
// 5. 撕掉迁移记录
|
|
||||||
// 针对你的匈牙利命名或标准命名,用 snake 匹配最稳
|
|
||||||
$sMatch = Str::snake($sTable);
|
|
||||||
DB::table('migrations')->where('migration', 'like', "%{$sMatch}%")->delete();
|
|
||||||
|
|
||||||
$this->warn("已爆破表及记录: {$sTable}");
|
|
||||||
|
|
||||||
// 6. 重新集结
|
|
||||||
$this->comment('正在根据迁移文件重新创建表...');
|
|
||||||
Artisan::call('migrate');
|
|
||||||
|
|
||||||
$this->info("表 [{$sTable}] 重建成功!任务完成!");
|
|
||||||
})->purpose('定点爆破并重建指定的表,不带参数不动手');
|
|
||||||
|
|
||||||
// 每周一凌晨 2:00 准时开跑,避开流量高峰
|
// 每周一凌晨 2:00 准时开跑,避开流量高峰
|
||||||
Schedule::command('stat:tags-cloud')->weeklyOn(1, '02:00'); // 没到时间我想测试,如何直接触发
|
Schedule::command('stat:tags-cloud')->weeklyOn(1, '02:00'); // 没到时间我想测试,如何直接触发
|
||||||
|
|
||||||
@ -51,3 +18,37 @@
|
|||||||
Schedule::command('clear_db')->dailyAt('03:00');
|
Schedule::command('clear_db')->dailyAt('03:00');
|
||||||
|
|
||||||
Schedule::command('article:sync-likes')->everyFiveMinutes();
|
Schedule::command('article:sync-likes')->everyFiveMinutes();
|
||||||
|
|
||||||
|
|
||||||
|
//Artisan::command('db:reCreate {sTableName?}', function ($sTableName = null) {
|
||||||
|
// // 1. 没传参数?直接亮红牌!
|
||||||
|
// if (empty($sTableName)) {
|
||||||
|
// $this->error('错误:必须指定要重建的表名!我可不想乱开火。');
|
||||||
|
// $this->info('用法示例:php artisan db:reCreate slave_sites');
|
||||||
|
// return; // 直接撤退,不往下走
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 2. 确定目标
|
||||||
|
// $sTable = $sTableName;
|
||||||
|
//
|
||||||
|
// // 3. 检查表是否存在(不存在炸个寂寞?)
|
||||||
|
// if (!Schema::hasTable($sTable)) {
|
||||||
|
// $this->warn("目标表 [{$sTable}] 本就不存在,但我还是会清理迁移记录并尝试重建。");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 4. 物理抹除表
|
||||||
|
// Schema::dropIfExists($sTable);
|
||||||
|
//
|
||||||
|
// // 5. 撕掉迁移记录
|
||||||
|
// // 针对你的匈牙利命名或标准命名,用 snake 匹配最稳
|
||||||
|
// $sMatch = Str::snake($sTable);
|
||||||
|
// DB::table('migrations')->where('migration', 'like', "%{$sMatch}%")->delete();
|
||||||
|
//
|
||||||
|
// $this->warn("已爆破表及记录: {$sTable}");
|
||||||
|
//
|
||||||
|
// // 6. 重新集结
|
||||||
|
// $this->comment('正在根据迁移文件重新创建表...');
|
||||||
|
// Artisan::call('migrate');
|
||||||
|
//
|
||||||
|
// $this->info("表 [{$sTable}] 重建成功!任务完成!");
|
||||||
|
//})->purpose('定点爆破并重建指定的表,不带参数不动手');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user