froxlor / Froxlor

The server administration software for your needs - The official Froxlor development Git repository
http://www.froxlor.org
GNU General Public License v2.0
1.63k stars 458 forks source link

task fails on rebuilding DNS, wrong return type of getMainSubdomainIds #1202

Closed mameier closed 10 months ago

mameier commented 10 months ago

Describe the bug After upgrade to froxlor 2.1.0-1 on bookworm, changing a domain resulted in this error during the cron task:

PHP Fatal error: Uncaught TypeError: Froxlor\Domain\Domain::getMainSubdomainIds(): Return value must be of type array, int returned in /var/www/html/froxlor/lib/Froxlor/Domain/Domain.php:261

A clear and concise description of what the bug is.

System information

Cause

The new function getMainSubdomainIds is expected to return an array of ids.
Line 259 replaces the array by an integer, so an integer is returned

public static function getMainSubdomainIds(int $id): array
{
    $result_stmt = Database::prepare("
        SELECT id
        FROM `" . TABLE_PANEL_DOMAINS . "`
        WHERE
        isbinddomain = 1 AND
        domain LIKE CONCAT('%.', ( SELECT d.domain FROM `" . TABLE_PANEL_DOMAINS . "` AS d WHERE d.id = :id ))
    ");
    Database::pexecute($result_stmt, [
        'id' => $id
    ]);
    $result = [];
    while ($entry = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
        $result = $entry['id']; // $result is replaced instead of extended
    }
    return $result;
}

Patch

Just fix line 259 from

$result = $entry['id'];

to

$result[] = $entry['id];
d00p commented 10 months ago

Yup, just got that reported from a user on Discord, confirmed. Patch:

diff --git a/lib/Froxlor/Domain/Domain.php b/lib/Froxlor/Domain/Domain.php
index 82616d37..d919f8d5 100644
--- a/lib/Froxlor/Domain/Domain.php
+++ b/lib/Froxlor/Domain/Domain.php
@@ -256,7 +256,7 @@ class Domain
                ]);
                $result = [];
                while ($entry = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
-                       $result = $entry['id'];
+                       $result[] = $entry['id'];
                }
                return $result;
        }

Bugfix release will follow this weekend. Thanks for reporting.

mameier commented 10 months ago

Das soll Dir erst einmal einer nach machen: Issue innerhalb von einer Minute zu korrigieren und nach 4 Minuten zu schließen ;-) Vielen Dank