1
This commit is contained in:
@@ -1156,7 +1156,7 @@ class Preaccept extends Base
|
||||
|
||||
// 若检测到引用删除,则进行全文扫描并标记未被引用条目的 is_used=0(含 table 内容)
|
||||
if ($hasCitationDeletion) {
|
||||
// $this->markUnusedReferencesForArticle(intval($am_info['article_id']));
|
||||
$this->markUnusedReferencesForArticle(intval($am_info['article_id']));
|
||||
}
|
||||
// return jsonSuccess([]);
|
||||
//返回更新数据 20260119 start
|
||||
@@ -1198,27 +1198,7 @@ class Preaccept extends Base
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function extractMyciteIds(string $text): array
|
||||
{
|
||||
if ($text === '') return [];
|
||||
$ids = [];
|
||||
if (preg_match_all('/<\s*mycite\b[^>]*\bdata-id\s*=\s*(["\'])(.*?)\1[^>]*>/iu', $text, $m)) {
|
||||
foreach ($m[2] as $raw) {
|
||||
$raw = trim((string)$raw);
|
||||
if ($raw === '') continue;
|
||||
$parts = preg_split('/\s*,\s*/', $raw);
|
||||
foreach ($parts as $p) {
|
||||
$p = trim((string)$p);
|
||||
if ($p === '') continue;
|
||||
$v = intval($p);
|
||||
if ($v > 0) $ids[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
$ids = array_values(array_unique($ids));
|
||||
sort($ids);
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 全文扫描(正文 + table),将 production_article_refer 未被引用的条目标记 is_used=0
|
||||
@@ -1226,62 +1206,7 @@ class Preaccept extends Base
|
||||
*
|
||||
* 注意:依赖 production_article_refer 表存在 is_used 字段(int/tinyint)
|
||||
*/
|
||||
private function markUnusedReferencesForArticle(int $articleId)
|
||||
{
|
||||
if ($articleId <= 0) return;
|
||||
|
||||
$production = Db::name('production_article')
|
||||
->where('article_id', $articleId)
|
||||
->where('state', 0)
|
||||
->field('p_article_id')
|
||||
->find();
|
||||
$pArticleId = intval($production['p_article_id'] ?? 0);
|
||||
if ($pArticleId <= 0) return;
|
||||
|
||||
// 1) 收集已使用的 p_refer_id
|
||||
$usedIds = [];
|
||||
|
||||
$mains = Db::name('article_main')
|
||||
->where('article_id', $articleId)
|
||||
->whereIn('state', [0, 2])
|
||||
->field('content')
|
||||
->select();
|
||||
foreach ($mains as $row) {
|
||||
$usedIds = array_merge($usedIds, $this->extractMyciteIds((string)($row['content'] ?? '')));
|
||||
}
|
||||
|
||||
$tables = Db::name('article_main_table')
|
||||
->where('article_id', $articleId)
|
||||
->where('state', 0)
|
||||
->field('table_data,html_data,title,note')
|
||||
->select();
|
||||
foreach ($tables as $row) {
|
||||
$usedIds = array_merge($usedIds, $this->extractMyciteIds((string)($row['table_data'] ?? '')));
|
||||
$usedIds = array_merge($usedIds, $this->extractMyciteIds((string)($row['html_data'] ?? '')));
|
||||
$usedIds = array_merge($usedIds, $this->extractMyciteIds((string)($row['title'] ?? '')));
|
||||
$usedIds = array_merge($usedIds, $this->extractMyciteIds((string)($row['note'] ?? '')));
|
||||
}
|
||||
|
||||
$usedIds = array_values(array_unique($usedIds));
|
||||
|
||||
// 2) 标记:先全置 0,再把用到的置 1
|
||||
try {
|
||||
Db::name('production_article_refer')
|
||||
->where('p_article_id', $pArticleId)
|
||||
->where('state', 0)
|
||||
->update(['is_used' => 0, 'update_time' => time()]);
|
||||
|
||||
if (!empty($usedIds)) {
|
||||
Db::name('production_article_refer')
|
||||
->where('p_article_id', $pArticleId)
|
||||
->where('state', 0)
|
||||
->whereIn('p_refer_id', $usedIds)
|
||||
->update(['is_used' => 1, 'update_time' => time()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 工具方法:不影响主流程,忽略异常(可按需改为记录日志)
|
||||
}
|
||||
}
|
||||
|
||||
public function getArticleMainsRecycle(){
|
||||
$data = $this->request->post();
|
||||
|
||||
Reference in New Issue
Block a user