Repository navigation
Conversation
URL 名称(filename)原先被当成全局唯一,多语言站点下产生两个问题:
一、静默改名导致 404
ContentSortController 与 ContentController 在新增/修改时,遇到重复的
filename 不报错,而是循环追加随机后缀:
while ($this->model->checkFilename($filename)) {
$filename = $filename . '-' . mt_rand(1, 20);
}
而 checkFilename() 查的是全表、不带 acode。中文已有 about 栏目时,给英文站
也填 about,入库变成 about-7,管理员以为 URL 是 /about,实际访问 404。
二、同名记录并存时语言错乱
getSort() / getContent() 按 scode OR filename 匹配且不限语言,find() 返回
第一行;随后 IndexController::switchLg() 把语言切成该行所属语言。历史数据或
直接改库产生的同名记录,会让 en 站访问 /about 命中 id 更小的 cn 行并跳回中文。
改动:
- checkFilename() 加 acode 维度,改为同一数据区域内唯一,三个语言可各自使用
about;顺带把 filename 从字面量拼接改为参数绑定
- 重复时改为 alert_back() 明确报错,不再静默追加随机后缀,URL 与管理员填写的
保持一致
- getSort() / getContent() 改为优先在当前语言内匹配,当前语言没有时再跨语言
查一次,既消除歧义又保留 switchLg() 的跨语言自愈能力(后台预览跨语言跳转、
站内贴了别语言的链接都依赖它)
注意:存量数据中已被追加随机后缀的 filename 不会自动还原,需要在后台手动改回。
SortPagingRouteRegexTest 原断言「后缀必须用横线而非下划线」(下划线会被分页
正则当作 about_2 即 about 栏目第 2 页),后缀取消后更新为断言不产生任何随机
后缀,保证强于原来。
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
URL 名称(filename)原先被当成全局唯一,多语言站点下产生两个问题:
一、静默改名导致 404
ContentSortController 与 ContentController 在新增/修改时,遇到重复的 filename 不报错,而是循环追加随机后缀:
而 checkFilename() 查的是全表、不带 acode。中文已有 about 栏目时,给英文站 也填 about,入库变成 about-7,管理员以为 URL 是 /about,实际访问 404。
二、同名记录并存时语言错乱
getSort() / getContent() 按 scode OR filename 匹配且不限语言,find() 返回 第一行;随后 IndexController::switchLg() 把语言切成该行所属语言。历史数据或 直接改库产生的同名记录,会让 en 站访问 /about 命中 id 更小的 cn 行并跳回中文。
改动:
注意:存量数据中已被追加随机后缀的 filename 不会自动还原,需要在后台手动改回。
SortPagingRouteRegexTest 原断言「后缀必须用横线而非下划线」(下划线会被分页 正则当作 about_2 即 about 栏目第 2 页),后缀取消后更新为断言不产生任何随机
后缀,保证强于原来。