Unverified Commit 28a4595a authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(systems) Fix setting interfaces through webservice

issue #6143
Showing with 25 additions and 8 deletions
+25 -8
......@@ -24,7 +24,7 @@
*/
class InterfacesAttribute extends DialogOrderedArrayAttribute
{
function __construct (string $label, string $description, string $ldapName, bool $required = FALSE, $defaultValue = '', string $acl = '')
function __construct (string $label, string $description, string $ldapName, bool $required = FALSE, $defaultValue = [], string $acl = '')
{
\FusionDirectory\Core\SimplePlugin\Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
$this->setInLdap(FALSE);
......@@ -44,6 +44,7 @@ class InterfacesAttribute extends DialogOrderedArrayAttribute
function setValue ($value)
{
$this->checkValue($value);
return $this->plugin->setNetworkInterfaces($value);
}
......
......@@ -423,7 +423,7 @@ class interfacesManagement extends management implements SimpleTab
return [];
}
public function setNetworkInterfaces ($interfaces = NULL)
public function setNetworkInterfaces (array $interfaces = NULL)
{
if ($interfaces !== NULL) {
$this->filter->loadTemplateValues($interfaces);
......@@ -434,24 +434,40 @@ class interfacesManagement extends management implements SimpleTab
$this->listing->setSortColumn(0, FALSE);
$entryIterator = $this->listing->getIterator();
ksort($this->interfaces);
reset($this->interfaces);
/* Build an index of interfaces cn */
$interfacesCnIndex = array_flip(array_filter(array_map(
function ($interface) {
if ($interface !== NULL) {
return $interface->getBaseObject()->cn;
} else {
return NULL;
}
},
$this->interfaces
)));
foreach ($entryIterator as $entry) {
$key = key($this->interfaces);
if ($key === NULL) {
if (isset($interfacesCnIndex[$entry['cn'][0]])) {
$key = $interfacesCnIndex[$entry['cn'][0]];
unset($interfacesCnIndex[$entry['cn'][0]]);
} else {
if ($this->is_template) {
$this->interfaces[$entry->dn] = objects::createTemplate($entry->getTemplatedType());
} else {
$this->interfaces[$entry->dn] = objects::create($entry->getTemplatedType());
}
$key = $entry->dn;
} else {
next($this->interfaces);
}
/* Push values from cache to the object */
$this->filter->resetFromCache($entry->dn, $this->interfaces[$key]);
$this->interfaces[$key]->getBaseObject()->base = $this->getInterfacesBase();
}
/* Set to NULL the rest of the interfaces array to delete the unused objects upon save */
foreach ($interfacesCnIndex as $key) {
$this->interfaces[$key] = NULL;
}
/* Fill ip/mac fields of main tab */
$this->update();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment