diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 3cbe5a4732fc..beb2d85a4d84 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -56,11 +56,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/BaseModel.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in &&, string given on the right side\\.$#', - 'count' => 7, - 'path' => __DIR__ . '/system/BaseModel.php', -]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in a ternary operator condition, array\\|null given\\.$#', 'count' => 1, @@ -2628,7 +2623,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in &&, string given on the right side\\.$#', - 'count' => 3, + 'count' => 2, 'path' => __DIR__ . '/system/Model.php', ]; $ignoreErrors[] = [ diff --git a/system/BaseModel.php b/system/BaseModel.php index 80baaf3fb024..e8e746e64c25 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -770,11 +770,11 @@ public function insert($data = null, bool $returnID = true) // Set created_at and updated_at with same time $date = $this->setDate(); - if ($this->useTimestamps && $this->createdField && ! array_key_exists($this->createdField, $data)) { + if ($this->useTimestamps && $this->createdField !== '' && ! array_key_exists($this->createdField, $data)) { $data[$this->createdField] = $date; } - if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $data)) { + if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, $data)) { $data[$this->updatedField] = $date; } @@ -857,11 +857,11 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch // Set created_at and updated_at with same time $date = $this->setDate(); - if ($this->useTimestamps && $this->createdField && ! array_key_exists($this->createdField, $row)) { + if ($this->useTimestamps && $this->createdField !== '' && ! array_key_exists($this->createdField, $row)) { $row[$this->createdField] = $date; } - if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $row)) { + if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, $row)) { $row[$this->updatedField] = $date; } } @@ -929,7 +929,7 @@ public function update($id = null, $data = null): bool throw DataException::forEmptyDataset('update'); } - if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $data)) { + if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, $data)) { $data[$this->updatedField] = $this->setDate(); } @@ -1014,7 +1014,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc $row[$index] = $updateIndex; } - if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $row)) { + if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, $row)) { $row[$this->updatedField] = $this->setDate(); } } @@ -1147,7 +1147,7 @@ public function replace(?array $data = null, bool $returnSQL = false) return false; } - if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, (array) $data)) { + if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, (array) $data)) { $data[$this->updatedField] = $this->setDate(); } diff --git a/system/Model.php b/system/Model.php index e53c0aae4bd1..1873804a3c2d 100644 --- a/system/Model.php +++ b/system/Model.php @@ -435,7 +435,7 @@ protected function doDelete($id = null, bool $purge = false) $set[$this->deletedField] = $this->setDate(); - if ($this->useTimestamps && $this->updatedField) { + if ($this->useTimestamps && $this->updatedField !== '') { $set[$this->updatedField] = $this->setDate(); } diff --git a/user_guide_src/source/models/model.rst b/user_guide_src/source/models/model.rst index db4ecd80b59d..6a2700520fd0 100644 --- a/user_guide_src/source/models/model.rst +++ b/user_guide_src/source/models/model.rst @@ -180,13 +180,13 @@ $createdField ^^^^^^^^^^^^^ Specifies which database field to use for data record create timestamp. -Leave it empty to avoid updating it (even if ``$useTimestamps`` is enabled). +Leave it empty (``''``) to avoid updating it (even if ``$useTimestamps`` is enabled). $updatedField ^^^^^^^^^^^^^ Specifies which database field should use for keep data record update timestamp. -Leave it empty to avoid update it (even ``$useTimestamps`` is enabled). +Leave it empty (``''``) to avoid updating it (even ``$useTimestamps`` is enabled). $deletedField ^^^^^^^^^^^^^