From 74cc2f03ff9c672dde0ceb83c3aa7abfb4850bfd Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 8 Nov 2021 12:22:41 +0100 Subject: [PATCH] fix PHP 8.0 TypeError: Api\Accounts::username(): Argument #1 ($account_id) must be of type ?int, string given new method for account link-title not throwing an error, for non-numeric arguments and therefore stalling all titles --- api/src/Accounts.php | 14 ++++++++++++++ api/src/Link.php | 9 +++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/api/src/Accounts.php b/api/src/Accounts.php index f7cc06c5ae..2ec473a64c 100644 --- a/api/src/Accounts.php +++ b/api/src/Accounts.php @@ -612,6 +612,20 @@ class Accounts $account['account_firstname'] , $account['account_lastname'], $account_id); } + /** + * Return formatted username for Links, does NOT throw if $account_id is not int + * + * @param $account_id + */ + static function title($account_id) + { + if (empty($account_id) || !is_numeric($account_id) && !($id = self::getInstance()->name2id($account_id))) + { + return '#'.$account_id; + } + return self::username($id ?? $account_id); + } + /** * Format an email address according to the system standard * diff --git a/api/src/Link.php b/api/src/Link.php index 40a3bafeda..f86e96fd36 100644 --- a/api/src/Link.php +++ b/api/src/Link.php @@ -154,7 +154,7 @@ class Link extends Link\Storage 'name' => 'Accounts', 'icon' => 'addressbook/accounts', 'query' => 'EGroupware\\Api\\Accounts::link_query', - 'title' => 'EGroupware\\Api\\Accounts::username', + 'title' => 'EGroupware\\Api\\Accounts::title', 'view' => array('menuaction'=>'addressbook.addressbook_ui.view','ajax'=>'true'), 'view_id' => 'account_id' ), @@ -914,7 +914,12 @@ class Link extends Link\Storage } else { - $title = self::title($app,$id); // no titles method --> fallback to query each link separate + try { + $title = self::title($app, $id); // no titles method --> fallback to query each link separate + } + catch (\Throwable $e) { + $title = lang('Error').': '.$e->getMessage(); + } } } $titles[$id] = $title;