<?php
namespace plugins\timing\task;
use think\Db;
/**
* 定时发布「到点自动上线」任务
* 由系统计划任务(qb_timed_task)周期调用:run()
*
* 唤醒方式(齐博自带):
* 1) 有人访问网站前台时,layout_body_foot 钩子会 AJAX 触发 index/task/index(最快 2 分钟一次)
* 2) 服务器计划任务 / 命令行:php index.php index/task/dos (推荐,最准时)
*
* ⚠️ 防双写铁律:此处只 UPDATE 内容状态(status 0 -> 1),绝不 INSERT 内容行。
* 内容已在发布时由核心写入一次,这里只是「翻牌」显示,结构上不可能出现第二条内容。
*/
class Autopublish
{
public function run($ext = [])
{
$now = time();
$list = Db::name('timing_task')->where('done', 0)->where('posttime', '<=', $now)->select();
if (empty($list)) {
return;
}
$changed = 0;
foreach ($list as $rs) {
$base = $rs['module'] . '_content';
// 内容还在不在?被删了就直接清计划,避免死循环
try {
$exists = Db::name($base)->where('id', $rs['aid'])->find();
} catch (\Exception $e) {
$exists = null;
}
if (!$exists) {
Db::name('timing_task')->where('id', $rs['id'])->delete();
continue;
}
// 只更新状态,把内容从「未审核」翻成「已审核」
try {
Db::name($base)->where('id', $rs['aid'])->update(['status' => 1, 'list' => $now]);
Db::name($base . $rs['mid'])->where('id', $rs['aid'])->update(['status' => 1]);
Db::name('timing_task')->where('id', $rs['id'])->update(['done' => 1]);
$changed++;
} catch (\Exception $e) {
// 单条失败不影响其它计划
}
}
if ($changed) {
// 清掉前台标签缓存,让新上线的内容立刻出现在列表里
function_exists('cache2') && cache2('qbTagCacheKey__*', null);
}
}
}
<?php
namespace plugins\timing\task;
use think\Db;
/**
* 定时发布「到点自动上线」任务
* 由系统计划任务(qb_timed_task)周期调用:run()
*
* 唤醒方式(齐博自带):
* 1) 有人访问网站前台时,layout_body_foot 钩子会 AJAX 触发 index/task/index(最快 2 分钟一次)
* 2) 服务器计划任务 / 命令行:php index.php index/task/dos (推荐,最准时)
*
* ⚠️ 防双写铁律:此处只 UPDATE 内容状态(status 0 -> 1),绝不 INSERT 内容行。
* 内容已在发布时由核心写入一次,这里只是「翻牌」显示,结构上不可能出现第二条内容。
*/
class Autopublish
{
public function run($ext = [])
{
$now = time();
$list = Db::name('timing_task')->where('done', 0)->where('posttime', '<=', $now)->select();
if (empty($list)) {
return;
}
$changed = 0;
foreach ($list as $rs) {
$base = $rs['module'] . '_content';
// 内容还在不在?被删了就直接清计划,避免死循环
try {
$exists = Db::name($base)->where('id', $rs['aid'])->find();
} catch (\Exception $e) {
$exists = null;
}
if (!$exists) {
Db::name('timing_task')->where('id', $rs['id'])->delete();
continue;
}
// 只更新状态,把内容从「未审核」翻成「已审核」
try {
Db::name($base)->where('id', $rs['aid'])->update(['status' => 1, 'list' => $now]);
Db::name($base . $rs['mid'])->where('id', $rs['aid'])->update(['status' => 1]);
Db::name('timing_task')->where('id', $rs['id'])->update(['done' => 1]);
$changed++;
} catch (\Exception $e) {
// 单条失败不影响其它计划
}
}
if ($changed) {
// 清掉前台标签缓存,让新上线的内容立刻出现在列表里
function_exists('cache2') && cache2('qbTagCacheKey__*', null);
}
}
}
<?php
namespace plugins\timing\task;
use think\Db;
/**
* 定时发布「到点自动上线」任务
* 由系统计划任务(qb_timed_task)周期调用:run()
*
* 唤醒方式(齐博自带):
* 1) 有人访问网站前台时,layout_body_foot 钩子会 AJAX 触发 index/task/index(最快 2 分钟一次)
* 2) 服务器计划任务 / 命令行:php index.php index/task/dos (推荐,最准时)
*
* ⚠️ 防双写铁律:此处只 UPDATE 内容状态(status 0 -> 1),绝不 INSERT 内容行。
* 内容已在发布时由核心写入一次,这里只是「翻牌」显示,结构上不可能出现第二条内容。
*/
class Autopublish
{
public function run($ext = [])
{
$now = time();
$list = Db::name('timing_task')->where('done', 0)->where('posttime', '<=', $now)->select();
if (empty($list)) {
return;
}
$changed = 0;
foreach ($list as $rs) {
$base = $rs['module'] . '_content';
// 内容还在不在?被删了就直接清计划,避免死循环
try {
$exists = Db::name($base)->where('id', $rs['aid'])->find();
} catch (\Exception $e) {
$exists = null;
}
if (!$exists) {
Db::name('timing_task')->where('id', $rs['id'])->delete();
continue;
}
// 只更新状态,把内容从「未审核」翻成「已审核」
try {
Db::name($base)->where('id', $rs['aid'])->update(['status' => 1, 'list' => $now]);
Db::name($base . $rs['mid'])->where('id', $rs['aid'])->update(['status' => 1]);
Db::name('timing_task')->where('id', $rs['id'])->update(['done' => 1]);
$changed++;
} catch (\Exception $e) {
// 单条失败不影响其它计划
}
}
if ($changed) {
// 清掉前台标签缓存,让新上线的内容立刻出现在列表里
function_exists('cache2') && cache2('qbTagCacheKey__*', null);
}
}
}