phpMyFAQ Fatal error Uncaught exception: 'TypeError' on Staff FAQ

Please report bugs here!

Moderator: Thorsten

Post Reply
iconicperformances
Posts: 92
Joined: Fri Sep 15, 2017 8:49 am

phpMyFAQ Fatal error Uncaught exception: 'TypeError' on Staff FAQ

Post by iconicperformances »

Some staff, David Phillips in general are not able to / unable to access the FAQ link sent to him today and following is the error message
I got
phpMyFAQ Fatal error Uncaught exception: 'TypeError' Message: 'phpMyFAQ\Helper\FaqHelper::renderMarkupContent(): Argument #1 ($answer) must be of type string, null given, called in /home/iconicprod/public_html/Staff/KB/faq.php on line 107' Stack trace: #0 /home/iconicprod/public_html/Staff/KB/faq.php(107): phpMyFAQ\Helper\FaqHelper->renderMarkupContent(NULL) #1 /home/iconicprod/public_html/Staff/KB/index.php(803): require('/home/iconicpro...') #2 {main} Thrown in '/home/iconicprod/public_html/Staff/KB/src/phpMyFAQ/Helper/FaqHelper.php' on line
55
Our company developer found the issue and fixed it from our end.
The main issue was that staff members were not redirected to the login page when they entered the URL directly. If a user hasn't signed in and tries to access an FAQ, they should be redirected to the login page. After signing in, they can view the content of the URL. However, in some cases, they were not redirected and instead received error messages.
For example:
https://staff.iconic.productions/KB/ind ... on_id=1218
https://staff.iconic.productions/KB/ind ... on_id=1377
https://staff.iconic.productions/KB/ind ... on_id=1369
If you try to access these URLs without signing in, you would encounter a fatal error.
The issue occurred because phpMyFAQ returned a NULL query result, leading to the fatal error. I fixed the bug by redirecting users to the sign-in page whenever the query result is NULL.
Since this is a third-party app, unless they address their potential issues, we will need to fix these bugs after each update.
If you can please correct this in the next update so that we don't have to always fix this bug.
Thorsten
Posts: 15627
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: phpMyFAQ Fatal error Uncaught exception: 'TypeError' on Staff FAQ

Post by Thorsten »

Hi,

can you post the fix here?

Thanks in advance!

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
iconicperformances
Posts: 92
Joined: Fri Sep 15, 2017 8:49 am

Re: phpMyFAQ Fatal error Uncaught exception: 'TypeError' on Staff FAQ

Post by iconicperformances »

Hi Thorsten,
I have asked our junior developer Oleh, to provide you with the fix he found. At some time soon he will reply on this thread with the fix.
Thanks for your work mate.

Good luck, and thank you for your continue work.
Regards
Nikolas Harrington
(IT/Web Development Supervisor for Iconic Productions and Iconic Performances)
oleh.kruk
Posts: 2
Joined: Mon Oct 28, 2024 3:40 am

Re: phpMyFAQ Fatal error Uncaught exception: 'TypeError' on Staff FAQ

Post by oleh.kruk »

Hi Thoresten,

Let me post again.

Best regards,
Last edited by oleh.kruk on Tue Oct 29, 2024 5:56 am, edited 2 times in total.
Thorsten
Posts: 15627
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: phpMyFAQ Fatal error Uncaught exception: 'TypeError' on Staff FAQ

Post by Thorsten »

Hi,

maybe it's faster to discuss it via Discord: https://discord.gg/wszhTceuNM

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
oleh.kruk
Posts: 2
Joined: Mon Oct 28, 2024 3:40 am

Re: phpMyFAQ Fatal error Uncaught exception: 'TypeError' on Staff FAQ

Post by oleh.kruk »

Hi Thorsten,

Sorry for my late response.
Let me explain about the solution I found.
When user directly accesses the urls mentioned in bug without signing in , Fatal error message appears.
This error happens because the function "getRecordBysolutionId" returns NULL and reference to NULL makes unexpectedly error.

Look for the file KB/src/phpMyFAQ/Faq.php

You can find the function named "getRecordBysolutionId".
When you directly accesses, this function returns NULL because the there is no query result.
Before signing in, you can't know the role of the user and group permission.
So if the user directly accesses the urls mentioned before signing in, he is redirected to the signing in page.

I made the change in the SQL query, so that the query return the result not NULL.

public function getRecordBySolutionId(int $solutionId): void
{
$query = sprintf(
'SELECT
*
FROM
%sfaqdata fd
LEFT JOIN
%sfaqdata_group fdg
ON
fd.id = fdg.record_id
LEFT JOIN
%sfaqdata_user fdu
ON
fd.id = fdu.record_id
WHERE
fd.solution_id = %d
%s',
Database::getTablePrefix(),
Database::getTablePrefix(),
Database::getTablePrefix(),
$solutionId,
$this->queryPermission($this->groupSupport)
);
$result = $this->config->getDb()->query($query);

if ($row = $this->config->getDb()->fetchObject($result)) {
$question = nl2br((string) $row->thema);
$content = $row->content;
$active = ('yes' == $row->active);
$expired = (date('YmdHis') > $row->date_end);

if (!$active) {
$content = Translation::get('err_inactiveArticle');
}
if ($expired) {
$content = Translation::get('err_expiredArticle');
}

$this->faqRecord = [
'id' => $row->id,
'lang' => $row->lang,
'solution_id' => $row->solution_id,
'revision_id' => $row->revision_id,
'active' => $row->active,
'sticky' => $row->sticky,
'keywords' => $row->keywords,
'title' => $question,
'content' => $content,
'author' => $row->author,
'email' => $row->email,
'comment' => $row->comment,
'date' => Date::createIsoDate($row->updated),
'dateStart' => $row->date_start,
'dateEnd' => $row->date_end,
'notes' => $row->notes
];
}
}
I changed the $query.
$query = sprintf(
'SELECT
fd.*, COALESCE(fdg.group_id, -1) AS group_id, fdu.user_id
FROM
%sfaqdata fd
LEFT JOIN
(
SELECT record_id, group_id
FROM %sfaqdata_group fdg
WHERE fdg.group_id <> -1

UNION ALL

SELECT fd.id AS record_id, -1 AS group_id
FROM %sfaqdata fd
WHERE fd.solution_id = %d
) AS fdg
ON
fd.id = fdg.record_id
LEFT JOIN
%sfaqdata_user fdu
ON
fd.id = fdu.record_id
WHERE
fd.solution_id = %d
%s',
Database::getTablePrefix(),
Database::getTablePrefix(),
Database::getTablePrefix(),
$solutionId,
Database::getTablePrefix(),
$solutionId,
$this->queryPermission($this->groupSupport)
);

That's all.
I hope this will help you.
Thorsten
Posts: 15627
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: phpMyFAQ Fatal error Uncaught exception: 'TypeError' on Staff FAQ

Post by Thorsten »

Hi,

thanks, I added this fix to the upcoming 3.2.10, 4.0.0 and 4.1.0 releases.Thanks you very much!

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply