diff --git a/lam/lib/import.inc b/lam/lib/import.inc index 995a527f..ed474d01 100644 --- a/lam/lib/import.inc +++ b/lam/lib/import.inc @@ -267,6 +267,14 @@ class Importer { } else { $type = $firstAttribute[Importer::VALUE]; + if ($type === 'add') { + $attributes = array(); + foreach ($entry as $line) { + $lineData = $this->getLineKeyValue($line); + $attributes[$lineData[Importer::KEY]][] = $lineData[Importer::VALUE]; + } + return new AddEntryTask($dn, $attributes); + } $changes = array(); $subtasks = array(); $currentLines = array(); @@ -286,7 +294,7 @@ class Importer { $currentLines[] = $line; } $subtasks[] = $this->getChangeTypeTask($dn, $currentLines, $type); - return new MultiTask($subtasks); + return new MultiTask($subtasks, $dn); } } @@ -305,7 +313,7 @@ class Importer { $attributes[$lineData[Importer::KEY]][] = $lineData[Importer::VALUE]; } if ($type === 'add') { - return new AddAttributesTask($dn, $attributes); + return new AddEntryTask($dn, $attributes); } throw new LAMException(_('Invalid data'), htmlspecialchars($dn) . ' - ' . Importer::CHANGETYPE . ': ' . htmlspecialchars($type)); } @@ -414,13 +422,19 @@ class MultiTask implements ImporterTask { */ private $tasks = array(); + /** + * @var string DN + */ + private $dn = null; + /** * Constructor * * @param ImporterTask[] $tasks tasks */ - public function __construct($tasks) { + public function __construct($tasks, $dn) { $this->tasks = $tasks; + $this->dn = $dn; } /** diff --git a/lam/tests/lib/importTest.php b/lam/tests/lib/importTest.php index caa5f6b5..3c8caf62 100644 --- a/lam/tests/lib/importTest.php +++ b/lam/tests/lib/importTest.php @@ -2,6 +2,7 @@ use \LAM\TOOLS\IMPORT_EXPORT\Importer; use LAM\TOOLS\IMPORT_EXPORT\MultiTask; use LAM\TOOLS\IMPORT_EXPORT\AddAttributesTask; +use LAM\TOOLS\IMPORT_EXPORT\AddEntryTask; /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) @@ -157,10 +158,8 @@ class ImporterTest extends PHPUnit_Framework_TestCase { $importer = new Importer(); $tasks = $importer->getTasks($lines); $this->assertEquals(1, sizeof($tasks)); - $multiTask = $tasks[0]; - $this->assertEquals(MultiTask::class, get_class($multiTask)); - $this->assertEquals(1, sizeof($multiTask->getTasks())); - $this->assertEquals(AddAttributesTask::class, get_class($multiTask->getTasks()[0])); + $task = $tasks[0]; + $this->assertEquals(AddEntryTask::class, get_class($task)); } }