Fix possible upgrade failures when writing to db fields which may not yet exist
authorColeman Watts <coleman@civicrm.org>
Sat, 6 Nov 2021 21:47:43 +0000 (17:47 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 6 Nov 2021 21:47:43 +0000 (17:47 -0400)
Fixes dev/core#2550

CRM/Core/DAO.php

index 2a375fbca14d621081e35ac2f5f895258d39d1c7..f6ee6f1c84d080e0bab536adbef98576d839e496 100644 (file)
@@ -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);