Skip to content

Commit

Permalink
Issue planetteamspeak#186: Improve Host::permissionTree() function (p…
Browse files Browse the repository at this point in the history
…lanetteamspeak#189)

* Fetch permission list only once

This reduces the amount of executed `permissionlist` ServerQuery
commands, which also should improve the overall performance of
this function.

* Issue planetteamspeak#186: Fix offset error

Avoids the error `Trying to access array offset on value of type int`
by ensuring first, that the array has the required structure.

---------

Co-authored-by: sebastian_kraetzig <sebastian.kraetzig@4g-server.eu>
  • Loading branch information
Sebbo94BY and sebastian_kraetzig authored Aug 3, 2023
1 parent d754be6 commit 2d4690e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Node/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ public function permissionEnds(): array
*/
public function permissionTree(): array
{
$permissionList = $this->permissionList();

$permtree = [];

foreach ($this->permissionCats() as $val) {
Expand All @@ -659,7 +661,10 @@ public function permissionTree(): array
$permtree[$val]["permcatname"] = $permtree[$val]["permcatname"]->section("/", 1)->trim();
}

foreach ($this->permissionList() as $permission) {
foreach ($permissionList as $permission) {
if ((! array_key_exists("permid", $permission)) or (! array_key_exists("permcatid", $permission["permid"]))) {
continue;
}
if ($permission["permid"]["permcatid"] == $val) {
$permtree[$val]["permcatcount"]++;
}
Expand Down

0 comments on commit 2d4690e

Please sign in to comment.