diff --git a/library/Icinga/Web/Dashboard/DashboardHome.php b/library/Icinga/Web/Dashboard/DashboardHome.php index c3cfb23f1..e9aa49812 100644 --- a/library/Icinga/Web/Dashboard/DashboardHome.php +++ b/library/Icinga/Web/Dashboard/DashboardHome.php @@ -192,7 +192,9 @@ class DashboardHome extends BaseDashboard implements Sortable /** @var Pane $pane */ foreach ($panes as $pane) { $uuid = Dashboard::getSHA1($user->getUsername() . $this->getName() . $pane->getName()); - if (! $this->hasEntry($pane->getName()) && (! $origin || ! $origin->hasEntry($pane->getName()))) { + $movePane = $origin && $origin->hasEntry($pane->getName()); + + if (! $this->hasEntry($pane->getName()) && ! $movePane) { $conn->insert(Pane::TABLE, [ 'id' => $uuid, 'home_id' => $this->getUuid(), @@ -200,7 +202,7 @@ class DashboardHome extends BaseDashboard implements Sortable 'label' => $pane->getTitle(), 'priority' => $order++ ]); - } elseif (! $this->hasEntry($pane->getName()) || ! $origin || ! $origin->hasEntry($pane->getName())) { + } elseif (! $this->hasEntry($pane->getName()) || ! $movePane) { $filterCondition = [ 'id = ?' => $pane->getUuid(), 'home_id = ?' => $this->getUuid() @@ -217,7 +219,7 @@ class DashboardHome extends BaseDashboard implements Sortable 'id' => $uuid, 'home_id' => $this->getUuid(), 'label' => $pane->getTitle(), - 'priority' => $pane->getPriority() + 'priority' => $movePane ? $order++ : $pane->getPriority() ], $filterCondition); } else { // Failed to move the pane! Should have been handled already by the caller diff --git a/library/Icinga/Web/Dashboard/Pane.php b/library/Icinga/Web/Dashboard/Pane.php index d7d7d0b86..ff68a83f4 100644 --- a/library/Icinga/Web/Dashboard/Pane.php +++ b/library/Icinga/Web/Dashboard/Pane.php @@ -183,8 +183,9 @@ class Pane extends BaseDashboard implements Sortable $url = $dashlet->getUrl(); $url = is_string($url) ?: $url->getRelativeUrl(); $uuid = Dashboard::getSHA1($user . $home->getName() . $this->getName() . $dashlet->getName()); + $moveDashlet = $origin && $origin->hasEntry($dashlet->getName()); - if (! $this->hasEntry($dashlet->getName()) && (! $origin || ! $origin->hasEntry($dashlet->getName()))) { + if (! $this->hasEntry($dashlet->getName()) && ! $moveDashlet) { $conn->insert(Dashlet::TABLE, [ 'id' => $uuid, 'dashboard_id' => $this->getUuid(), @@ -211,8 +212,7 @@ class Pane extends BaseDashboard implements Sortable 'module_dashlet_id' => $systemUuid ]); } - } elseif (! $this->hasEntry($dashlet->getName()) || ! $origin - || ! $origin->hasEntry($dashlet->getName())) { + } elseif (! $this->hasEntry($dashlet->getName()) || ! $moveDashlet) { $filterCondition = [ 'id = ?' => $dashlet->getUuid(), 'dashboard_id = ?' => $this->getUuid() @@ -230,7 +230,7 @@ class Pane extends BaseDashboard implements Sortable 'dashboard_id' => $this->getUuid(), 'label' => $dashlet->getTitle(), 'url' => $url, - 'priority' => $dashlet->getPriority(), + 'priority' => $moveDashlet ? $order++ : $dashlet->getPriority(), 'disabled' => DBUtils::bool2BoolEnum($dashlet->isDisabled()) ], $filterCondition); } else {