diff --git a/app/Harvest/Importers/AbstractImporter.php b/app/Harvest/Importers/AbstractImporter.php index f9243679d..560e5d97f 100644 --- a/app/Harvest/Importers/AbstractImporter.php +++ b/app/Harvest/Importers/AbstractImporter.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Support\Facades\DB; abstract class AbstractImporter { @@ -109,8 +110,11 @@ protected function processHasMany(Model $model, $field, array $relatedRows, $all foreach ($relatedRows as $relatedRow) { $data = $this->mappers[$field]->map($relatedRow); $conditions = $this->getConditions($field, $data); - $instance = $model->$field()->firstOrNew($conditions); - $instance->forceFill($data); + $query = $model->$field(); + foreach ($conditions as $column => $value) { + $query->where(DB::raw("BINARY $column"), $value); + } + $instance = $query->firstOrNew()->forceFill($data); $instance->save(); $updateIds[] = $instance->getKey(); } @@ -139,7 +143,11 @@ protected function processBelongsToMany(Model $model, $field, array $relatedRows foreach ($relatedRows as $relatedRow) { $data = $this->mappers[$field]->map($relatedRow); $conditions = $this->getConditions($field, $data); - $relatedModel = $relatedModelClass::where($conditions)->first(); + $query = $relatedModelClass::query(); + foreach ($conditions as $column => $value) { + $query->where(DB::raw("BINARY $column"), $value); + } + $relatedModel = $query->first(); if (!$relatedModel && !$allowCreate) { continue; diff --git a/tests/Harvest/Importers/AuthorityImporterTest.php b/tests/Harvest/Importers/AuthorityImporterTest.php index c3b00efde..045b0d746 100644 --- a/tests/Harvest/Importers/AuthorityImporterTest.php +++ b/tests/Harvest/Importers/AuthorityImporterTest.php @@ -88,4 +88,22 @@ public function testRelatedButNotExisting() $authority = $this->importer->import($row, new Progress()); $this->assertEquals(0, $authority->relationships->count()); } + + public function testAccentSensitivity() + { + $row = FakeRecordFactory::buildAuthority([ + 'names' => [ + [ + 'name' => ['Mařák, Július'], + 'prefered' => [false], + ], + [ + 'name' => ['Marak, Julius'], + 'prefered' => [false], + ], + ], + ]); + $authority = $this->importer->import($row, new Progress()); + $this->assertCount(2, $authority->names); + } }