From 47555d7fde67dc3d1e2d5a62922c281cd0e806b3 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 6 Nov 2021 17:47:43 -0400 Subject: [PATCH] Fix possible upgrade failures when writing to db fields which may not yet exist Fixes dev/core#2550 --- CRM/Core/DAO.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 2a375fbca1..f6ee6f1c84 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -918,7 +918,9 @@ class CRM_Core_DAO extends DB_DataObject { \CRM_Utils_Hook::pre($hook, $entityName, $record['id'] ?? NULL, $record); $instance = new $className(); - $instance->copyValues($record); + // Ensure fields exist before attempting to write to them + $values = array_intersect_key($record, self::getSupportedFields()); + $instance->copyValues($values); $instance->save(); \CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); -- 2.25.1