From 8ee3c2008853e56e342171e732c92879446ccdd9 Mon Sep 17 00:00:00 2001 From: Roxel Lay Date: Sun, 3 Mar 2024 20:18:49 +0100 Subject: [PATCH] Check valid deleted_at and updated_at columns --- src/Mpociot/Versionable/VersionableTrait.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Mpociot/Versionable/VersionableTrait.php b/src/Mpociot/Versionable/VersionableTrait.php index 174096d..cb02e60 100644 --- a/src/Mpociot/Versionable/VersionableTrait.php +++ b/src/Mpociot/Versionable/VersionableTrait.php @@ -263,11 +263,13 @@ private function purgeOldVersions() */ private function isValidForVersioning() { - $dontVersionFields = isset( $this->dontVersionFields ) ? $this->dontVersionFields : []; - $removeableKeys = array_merge($dontVersionFields, [$this->getUpdatedAtColumn()]); + $removeableKeys = isset( $this->dontVersionFields ) ? $this->dontVersionFields : []; + if (($updatedAt = $this->getUpdatedAtColumn()) !== null) { + $removeableKeys[] = $updatedAt; + } - if (method_exists($this, 'getDeletedAtColumn')) { - $removeableKeys[] = $this->getDeletedAtColumn(); + if (method_exists($this, 'getDeletedAtColumn') && ($deletedAt = $this->getDeletedAtColumn() !== null)) { + $removeableKeys[] = $deletedAt; } return ( count(array_diff_key($this->versionableDirtyData, array_flip($removeableKeys))) > 0 );