Merge pull request #23342 from eileenmcnaughton/import_map
[civicrm-core.git] / Civi / Api4 / Generic / AbstractSaveAction.php
index 50aa311c4657f3a109b0f6ffec8081cbeb5b3e95..d61718d646e0ea9acf229beadfd17ef64a07d723 100644 (file)
@@ -142,7 +142,13 @@ abstract class AbstractSaveAction extends AbstractAction {
       $where = [];
       foreach ($record as $key => $val) {
         if (isset($val) && in_array($key, $this->match, TRUE)) {
-          $where[] = [$key, '=', $val];
+          if ($val === '' || is_null($val)) {
+            // If we want to match empty string we have to match on NULL/''
+            $where[] = [$key, 'IS EMPTY'];
+          }
+          else {
+            $where[] = [$key, '=', $val];
+          }
         }
       }
       if (count($where) === count($this->match)) {
@@ -198,7 +204,7 @@ abstract class AbstractSaveAction extends AbstractAction {
       'action' => 'get',
       'where' => [
         ['type', 'IN', ['Field', 'Custom']],
-        ['name', 'NOT IN', CoreUtil::getInfoItem($this->getEntityName(), 'primary_key')],
+        ['name', 'NOT IN', (array) CoreUtil::getInfoItem($this->getEntityName(), 'primary_key')],
       ],
     ], ['name']);
   }