| @@ -67,9 +67,10 @@ | ||
| 67 | 67 | $has_unique_field = true; |
| 68 | 68 | $key = $this->importer->get_iwp_reference_meta_key(); |
| 69 | 69 | |
| 70 | 70 | $value = $data->getValue($key, 'iwp'); |
| 71 | - if (!$value) { | |
| 71 | + // 0 / "0" are valid identifiers — only treat missing/blank as empty. | |
| 72 | + if (!$this->has_identifier_value($value)) { | |
| 72 | 73 | $value = ''; |
| 73 | 74 | } |
| 74 | 75 | |
| 75 | 76 | $meta_args[] = array( |
| @@ -119,8 +120,20 @@ | ||
| 119 | 120 | { |
| 120 | 121 | return $this->unique_indentifier_data; |
| 121 | 122 | } |
| 122 | 123 | |
| 124 | + /** | |
| 125 | + * Whether a unique identifier value is present. | |
| 126 | + * Note: 0 and "0" are valid identifiers (PHP empty()/falsy checks treat them as empty). | |
| 127 | + * | |
| 128 | + * @param mixed $value | |
| 129 | + * @return bool | |
| 130 | + */ | |
| 131 | + public function has_identifier_value($value) | |
| 132 | + { | |
| 133 | + return !(null === $value || false === $value || '' === $value); | |
| 134 | + } | |
| 135 | + | |
| 123 | 136 | public function getUniqueIdentifiers($unique_fields = []) |
| 124 | 137 | { |
| 125 | 138 | |
| 126 | 139 | // set via importer interface |
| @@ -148,9 +161,9 @@ | ||
| 148 | 161 | public function find_unique_field_in_data($data, $field) |
| 149 | 162 | { |
| 150 | 163 | // TODO: this should only be done once per update |
| 151 | 164 | $unique_value = $data->getValue($field, '*'); |
| 152 | - if (empty($unique_value)) { | |
| 165 | + if (!$this->has_identifier_value($unique_value)) { | |
| 153 | 166 | $cf = $data->getData('custom_fields'); |
| 154 | 167 | if (!empty($cf)) { |
| 155 | 168 | $cf_index = intval($cf['custom_fields._index']); |
| 156 | 169 | if ($cf_index > 0) { |