fix(task): task creation broke on save - task_kind could reach the database as null
A new Task's taskKind property defaulted to null (the 0.18.x task rework), while the task_kind column is NOT NULL: Doctrine writes every column explicitly, so the column's own default never applied and any save whose form field did not map failed with "1048 Column 'task_kind' cannot be null". - Task::$taskKind now defaults to TaskKind::Task, like $status: the property is never null anymore and the getter is straight - setTaskKind()/setStatus() accept null as "keep the current kind/status", so a missing form field can neither throw at mapping time nor wipe the value - TaskType defaults an absent or empty taskKind to a regular task on PRE_SUBMIT - regression tests: Tests/Unit/Entity/TaskTest.php
This commit is contained in:
1 parent
d6b3488cad
commit
603e564037
3 files changed
+110
-14
No files matched your search
+27
-14
@@ -66,7 +66,12 @@ class Task extends FormEntity implements DateRangeInterface
|
||||
|
||||
private TaskStatus $status = TaskStatus::New;
|
||||
|
||||
private ?TaskKind $taskKind = null;
|
||||
/**
|
||||
* Defaults to a regular task, like $status: Doctrine writes every column explicitly, so
|
||||
* the database column's own default never applies. A save whose form field didn't map
|
||||
* (a POST missing the kind) must never hit the NOT NULL column with null.
|
||||
*/
|
||||
private TaskKind $taskKind = TaskKind::Task;
|
||||
|
||||
private ?string $definitionOfDone = null;
|
||||
|
||||
@@ -291,32 +296,40 @@ class Task extends FormEntity implements DateRangeInterface
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(TaskStatus $status): static
|
||||
public function setStatus(?TaskStatus $status): static
|
||||
{
|
||||
if ($status !== $this->status) {
|
||||
// isChanged() can't log enums (they aren't stringable), so log the backing values.
|
||||
$this->addChange('status', [$this->status->value, $status->value]);
|
||||
$this->status = $status;
|
||||
// Null (a status field missing from the submitted form) never wipes the status: like
|
||||
// the kind, it keeps its default (New) or whatever the task already has.
|
||||
if (null === $status || $status === $this->status) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
// isChanged() can't log enums (they aren't stringable), so log the backing values.
|
||||
$this->addChange('status', [$this->status->value, $status->value]);
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTaskKind(): TaskKind
|
||||
{
|
||||
// Never null once stored (the column defaults to 'task'); a new entity reads as a plain task.
|
||||
return $this->taskKind ?? TaskKind::Task;
|
||||
// Never null: the property starts as a regular task and the column is NOT NULL.
|
||||
return $this->taskKind;
|
||||
}
|
||||
|
||||
public function setTaskKind(TaskKind $taskKind): static
|
||||
public function setTaskKind(?TaskKind $taskKind): static
|
||||
{
|
||||
if ($taskKind !== $this->taskKind) {
|
||||
// isChanged() can't log enums (they aren't stringable), so log the backing values.
|
||||
$this->addChange('taskKind', [$this->taskKind?->value, $taskKind->value]);
|
||||
$taskKind->enslaveDates($this);
|
||||
$this->taskKind = $taskKind;
|
||||
// Null (a kind field missing from the submitted form) never wipes the kind: a new
|
||||
// task keeps its regular-task default, an existing task keeps whatever it already has.
|
||||
if (null === $taskKind || $taskKind === $this->taskKind) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
// isChanged() can't log enums (they aren't stringable), so log the backing values.
|
||||
$this->addChange('taskKind', [$this->taskKind->value, $taskKind->value]);
|
||||
$taskKind->enslaveDates($this);
|
||||
$this->taskKind = $taskKind;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user