服务端:panel_save / Task::setAttrs 支持 repeat_rule (#83)

配合网页端与鸿蒙端把「循环」改成可编辑。

① Task::setAttrs() 新增 repeat_rule 分支
   只写 repeat_rule 一列(与 due_at / category_id / title / note 同一套
   按 `array_key_exists` 判"传没传"的逻辑)。
   ⚠️ 白名单校验:只接受 `self::REPEAT` 里有的键,其余一律存 NULL。
      不校验的话前端传个乱值就进库了,`repeatWord()` 会显示成空白,
      而且 `spawnNext` 那种"按规则生成下一次"的地方会静默不工作。
   ⚠️ 空串 = 不循环,存 NULL(与 `update()` 的 `?: null` 同口径)。

② index.php 的 tasks/panel_save 接收 repeat_rule
   同一套 `array_key_exists` 语义:表单没带就不动(保留原值),
   带了才更新 —— 这样"只改标题"的调用方不会把循环规则清掉。

实测:
  设 repeat_rule=week      => [week] ✅  标题未被破坏 ✅
  设非法值 hacked_value    => [NULL] ✅ 已拦下
  只改 due_at              => repeat_rule 不变 ✅ category_id 保留 ✅
This commit is contained in:
2026-11-05 20:15:18 +08:00
parent 255fb8a240
commit 50286e5327
2 changed files with 15 additions and 0 deletions
+10
View File
@@ -788,6 +788,16 @@ final class Task
$sets[] = 'category_id = ?';
$args[] = self::categoryIdOf($familyId, (int)($d['category_id'] ?? 0));
}
/* 🔴 #83(用户 2026-11-05):「分类和重复,也就是循环,都需要加上。」
⇒ 面板里改成可编辑之后,得有一条能只写 repeat_rule 的路径。
⚠️ 空串 = 不循环,存 NULL(与 `Task::update()` 的 `?: null` 同一口径)。
⚠️ 白名单校验:只接受 `REPEAT` 里有的键,其余一律当"不循环"。
不校验的话,前端传个乱值会进库,`repeatWord()` 那边就显示成空白。 */
if (array_key_exists('repeat_rule', $d)) {
$sets[] = 'repeat_rule = ?';
$rr = trim((string)($d['repeat_rule'] ?? ''));
$args[] = ($rr !== '' && isset(self::REPEAT[$rr])) ? $rr : null;
}
/* 🔴 #78(用户 2026-11-05):「现在在首页上点一个任务,直接就是编辑页面啊。
所以不需要再加一个编辑按钮了。」
⇒ 删掉「编辑」按钮后,标题/备注也得能在这里改。