Page 1 of 1

LISE in UDT gives 500 error

Posted: Thu Aug 22, 2024 1:05 pm
by webform
Trying to use a Smarty tag in a UDT gives almost always an 500 error.

I've tested with this UDT and a LISE Instance and get an 500 error:

Code: Select all

$smarty_data = "{LISEEmployees category='assets' xs_issued='1' template_summary='total'}";
$smarty->display('eval:'.$smarty_data);
Error log says

Code: Select all

PHP Notice: Trying to access array offset on value of type null in /lib/smarty/sysplugins/smarty_resource_recompiled.php(52) : eval()'d code on line 18\n
I've also tested with CustomGS module and it also fails but with another error when trying to save the UDT:

Code: Select all

$smarty_data = "{$CustomGS.META_Keywords}";
$smarty->display('eval:'.$smarty_data);
Error message:

Code: Select all

Invalid code entered.
syntax error, unexpected '.', expecting :: (T_PAAMAYIM_NEKUDOTAYIM)
This is tested on:

Code: Select all

Cms Version: 2.2.21
phpversion: 7.4.33
I've also tested on an old Cms Version: 2.2.10 with phpversion: 5.6.40 and here the UDTs working. So maybe the PHP version is to blame?

So what do i have to do different to use Smarty tags in an UDT?

Re: LISE in UDT gives 500 error

Posted: Sat Aug 24, 2024 4:19 pm
by Jo Morg
Hard to say without access or more info, but it seems like the total template is the one giving an error. If possible post here the template.

Re: LISE in UDT gives 500 error

Posted: Mon Aug 26, 2024 7:03 am
by webform
It's just a simple template I use to test with, which only contains {$totalcount}.

An error occurs regardless of whether I use the default template or any other template and regardless of which Smarty tag such as LISE, MAMS or CustomGS.

It has worked before in previous versions of CMSMS, so I thought maybe the way you call Smarty Tags in an UDT had changed?

I have previously used this guide to call a Smarty Tag in an UDT: https://cmscanbesimple.org/blog/call-a- ... from-a-udt

Re: LISE in UDT gives 500 error

Posted: Mon Aug 26, 2024 8:17 am
by gusfring
webform wrote: Mon Aug 26, 2024 7:03 am It's just a simple template I use to test with, which only contains {$totalcount}.

An error occurs regardless of whether I use the default template or any other template and regardless of which Smarty tag such as LISE, MAMS or CustomGS.

It has worked before in previous versions of CMSMS, so I thought maybe the way you call Smarty Tags in an UDT had changed?

I have previously used this guide to call a Smarty Tag in an UDT: https://cmscanbesimple.org/blog/call-a- ... from-a-udt my perfect hotel
it works

Re: LISE in UDT gives 500 error

Posted: Mon Aug 26, 2024 2:13 pm
by webform
It would appear that it might be a "bug" in Cms Version: 2.2.21.

I have done a clean installation of Cms Version: 2.2.21 and here the UDT fails with server error 500.
But I have also done a clean installation of Cms Version: 2.2.19 and here the UDT saves without error and I get an output.

UDT i'm testing:

Code: Select all

$smarty_data = "{MyLISEInstance}";
$smarty->display('eval:'.$smarty_data);

Re: LISE in UDT gives 500 error

Posted: Mon Aug 26, 2024 2:29 pm
by DIGI3
If you look at the error in the log, there's actually a clue:

Code: Select all

PHP Fatal error:  Uncaught  --> Smarty Compiler: Syntax error in template "eval:{MyLISEInstance}"  on line 1 "{MyLISEInstance}" unknown tag 'MyLISEInstance' <-- 
  thrown in 55d51468d3078225bb6d6ffb7a3ff94222bdf22a on line 1
Short tags to modules aren't registered in admin, so you need to use

Code: Select all

{cms_module module='MyLISEInstance'}
instead.

Re: LISE in UDT gives 500 error

Posted: Mon Aug 26, 2024 4:54 pm
by webform
Thanks! It's working:

Code: Select all

$smarty_data = "{cms_module module='MyLISEInstance'}";
$smarty->display('eval:'.$smarty_data);
Just strange that this works in Cms version 2.2.19 but not in Cms version 2.2.21

Code: Select all

$smarty_data = "{MyLISEInstance}";
$smarty->display('eval:'.$smarty_data);
And using {CustomGS} no longer works in either Cms version 2.2.19 or Cms version 2.2.21, but works in an old Cms version 2.2.10

Code: Select all

$smarty_data = "{$CustomGS.MyTextField}";
$smarty->display('eval:'.$smarty_data);
My UDT's with the LISE API that insert data from a frontend form still work in Cms version 2.2.21, but I can no longer edit the UDT without getting errors such as:

Code: Select all

Notice: Undefined variable: params in /var/www/public_html/app/assetit/admin/editusertag.php(98) : eval()'d code on line 13
Notice: Trying to access array offset on value of type null in /var/www/public_html/app/assetit/admin/editusertag.php(98) : eval()'d code on line 13
Warning: Invalid argument supplied for foreach() in /var/www/public_html/app/assetit/admin/editusertag.php(98) : eval()'d code on line 34
And trying to save the UDT creates a blank record in the LISEInstance.
This is not happening in Cms version 2.2.19!

So I think there must be something wrong with UDT in Cms version 2.2.21 since I'm experiencing all those errors, right?

Re: LISE in UDT gives 500 error

Posted: Tue Aug 27, 2024 5:50 pm
by Jo Morg
There are changes to the way UDT's get parsed before being saved. Although that was not the goal, which was to parse any PHP syntax error on save, it seems that the UDT gets executed once. I'll have to revisit the code (tbh the original broken code also seemed to parse the code in a similar way without actually executing it). So it indeed seems to be a bug. If possible open a BR on CMSMS Core so that I remember to check that code out before next release. THX.

Re: LISE in UDT gives 500 error

Posted: Tue Aug 27, 2024 6:25 pm
by webform
Yeah! I did notice when i opened an UDT with mail handling i got sent an email from the script.

I'll file a bug report. Thanks.

p.s. I overcame some of the problem temporarily with the UDT by working with the code in the MySQL table directly, so that I didn't get error messages when I saved the UDT.

However, I have not yet found out how to use the module CustomGS in a UDT, as you could in previous CMS versions.

Re: LISE in UDT gives 500 error

Posted: Tue Aug 27, 2024 6:30 pm
by Jo Morg
It may be a different aspect of the same issue; as stated above by @DIGI3: "Short tags to modules aren't registered in admin", but parsing the UDT on save is done in admin, so it will trigger the error only on save. At least that's what it looks like without testing...
PS: using {cms_module .... should work with all modules though, as a workaround ...

Re: LISE in UDT gives 500 error

Posted: Tue Aug 27, 2024 6:39 pm
by webform
I've tried first with (which i've used in a dosen of older solutions):

Code: Select all

$smarty_data = "{$CustomGS.MyTextField}";
$smarty->display('eval:'.$smarty_data);
But get error:

Code: Select all

Invalid code entered.
syntax error, unexpected '.', expecting :: (T_PAAMAYIM_NEKUDOTAYIM)
And then i've tried:

Code: Select all

$smarty_data = "{cms_module module='$CustomGS.MyTextField'}";
$smarty->display('eval:'.$smarty_data);
Which result in the error:

Code: Select all

.MyTextField is not a module

Re: LISE in UDT gives 500 error

Posted: Wed Aug 28, 2024 10:36 am
by Jo Morg
webform wrote: Tue Aug 27, 2024 6:39 pm

Code: Select all

$smarty_data = "{cms_module module='$CustomGS.MyTextField'}";
cms_module only work for module tags, in fact it is meant to replace them for backend module calls, so of course that won't work.
webform wrote: Tue Aug 27, 2024 6:39 pm I've tried first with (which i've used in a dosen of older solutions):

Code: Select all

$smarty_data = "{$CustomGS.MyTextField}";
$smarty->display('eval:'.$smarty_data);
But get error:

Code: Select all

Invalid code entered.
syntax error, unexpected '.', expecting :: (T_PAAMAYIM_NEKUDOTAYIM)
This shouldn't even have worked before TBH... The PHP parser sees {$CustomGS.MyTextField} inside double quotes and evaluates it as a PHP variable so it complains about the dot in the middle. It's standard PHP syntax...
Try either:

Code: Select all

$smarty_data = '{$CustomGS.MyTextField}'; # <- single quotes here
# or
$smarty_data = "{$CustomGS.MyTextField }"; # adding a single with space may also work as the {} is what triggers PHP evaluation... didn't try though
 
$smarty->display('eval:'.$smarty_data);
HTH

Re: LISE in UDT gives 500 error

Posted: Wed Aug 28, 2024 11:42 am
by webform
It's embarrassing, but you're right! :-[

I'm a fool and remembered wrong! There are single quotes on my call of the CustomGS module when I look again in the old UDT.

Re: LISE in UDT gives 500 error

Posted: Wed Aug 28, 2024 11:46 am
by Jo Morg
No worries, it happens. :)