From d665bccaa9ea9af94342a4fa96be545dc1dcd571 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 16 Nov 2010 18:03:03 -0200 Subject: Trying to avoid duplicate entries at addManyToManyEntities() --- lib/sfIsisImporter.class.php | 1 + lib/sfIsisImporterRelations.class.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/sfIsisImporter.class.php b/lib/sfIsisImporter.class.php index 9b2273a..4b2d587 100644 --- a/lib/sfIsisImporter.class.php +++ b/lib/sfIsisImporter.class.php @@ -104,6 +104,7 @@ class sfIsisImporter extends sfIsisImporterRelations { if (!$this->hasDeniedCombinations($base_model, $field)) { + $this->log("Calling $method for field ". $field['name'] .'.', 'debug'); $this->{$method}($model, $field); } } diff --git a/lib/sfIsisImporterRelations.class.php b/lib/sfIsisImporterRelations.class.php index bf41120..248bf99 100644 --- a/lib/sfIsisImporterRelations.class.php +++ b/lib/sfIsisImporterRelations.class.php @@ -151,9 +151,19 @@ class sfIsisImporterRelations extends sfIsisImporterEntities { */ public function addManyToManyEntities(&$model, array $values, $relation, $key = 'name') { + $existing = array(); + foreach ($values as $value) { - $this->addManyToMany($model, $value, $relation, $key); + // Prevent duplicate entries. + if (!in_array($value, $existing)) + { + $existing[] = $value; + $this->addManyToMany($model, $value, $relation, $key); + } + else { + $this->log("Found duplicate entry $value for relation $key.", 'debug'); + } } } -- cgit v1.2.3