Form php plugin causes "0 Class "Factory" not found" error

I've updated a J3 F3 PHP7 installation to J4.2.9 F4.0gamma3 PHP8.1 following the "Upgrading from Fabrik3.10 to Fabrik4" instructions. In general it's working but there are some problems.

I've got a problem with (I believe) a php form plugin which is throwing an error: 0 Class "Factory" not found and displaying a "the requested page can't be found" error which seems odd as there's no redirect. I believe this plugin is the problem as the form works fine when the plugin is disabled.

The form is to create a subscription for a member (user) and the purpose of the plugin is to unblock the user if they have been blocked. If they are not blocked then there should be no action.

The plugin process script is "OnAfterProcess" and the code is:
Code:
$mydb = version_compare(\Joomla\CMS\Version::MAJOR_VERSION, "4", ">=") ? Factory::getContainer()->get('DatabaseDriver') : Factory::getDbo();

$my_user_id = '{subscriptions___member_raw}';

$mydb->setQuery("UPDATE #__users SET block='0' WHERE id = ".$mydb->Quote($my_user_id));
$mydb->execute();
$mydb->setQuery("UPDATE members SET block_user = '0' WHERE id = ".$mydb->Quote($my_user_id));
$mydb->execute();

I've checked through the PHP manual comparing PHP7 to PHP8 but can't find anything that helps. I've also viewed the backward compatibility issues of J3 to J4 and searched this forum.

This works OK in J3 F3 PHP7, but couldn't check when it works in J3 F3 PHP8 as earlier errors appeared. So not sure whether this is a PHP8 or J4/F4 issue, hence I'm posting it here rather than Bugs and Issues.

Can anybody offer any suggestions please? Thanks.
 
You need to declare
use Joomla\CMS\Factory; (It's a bit above in the upgrade instructions)

or do
\Joomla\CMS\Factory::getContainer()->get('DatabaseDriver')

You are now at J!4 so no need to compare the version.
 
Thanks @troester
I misunderstood the instructions, but my php knowledge is very limited so I'm still unclear exactly what I should put where. I tried a few different permutations but I'm getting different errors now.

In J3 F3 my first line read:
Code:
$mydb = JFactory::getDBO();

So, what should it read now?
Code:
$mydb = \Joomla\CMS\Factory::getDBO();

Or
Code:
$mydb = \Joomla\CMS\Factory::$mydb = \Joomla\CMS\Factory::getDBO();

Or something else?
Sorry :(
 
Hi @troester
The other errors were due to autofill plugins losing their data.
I'm now getting an error "0 Undefined constant "‘DatabaseDriver’". This is due again to the php plugin as it goes away when I disable the plugin.
That's a bit weird, isn't it?
 
No, I copy and pasted from your message.
I suspect there might be some deeper problem with my installation. My autofill form plugins lost their data and now the form plugins are refusing to load; they're just spinning.

Update: I just realised I had error reporting switched on. Switched it off and the plugins are now loading. However, one of the autofill plugins has lost its data again. Could this be due to switching error reporting on and off? But if so, why has only one autofill plugin lost its data?

Update again: I found the original problem: the php plugin had changed to a default of On: Both instead of On:New. Corrected and the form processes with no errors.

So now my question is: why have these form plugins lost data? Related to switching error reporting on and off?
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top