web site was just updated from Joomla 3.x to Joomla 4.x - PHP 8.1
scripts that used to work after member login are now failing when script reaches statements using Factor:: functions.
original [inherited] script still used JFactory. After some changes based on articles found online, the script still fails.
1) manually inserting debug statements and selective commenting out Factory function calls all point to problems with the lines using Factory::
2) Factory.php message is "Failed to start application"
3) if all Factory functions commented out - enduser error stating "you must be logged in"
here's the code with original lines commented out and new lines identified as // attempt after joomla4 migration
***************************************** BEGIN CODE **********************************************************************************
// Get Joomla session
use Joomla\CMS\Factory; // attempt after joomla4 migration
define( '_JEXEC', 1 );
define( 'DS', '/' );
// IMPORTANT: adjust path based on folder or define it manually as string
// "myjoomlaroot" is name of your Joomla root folder
// $myjoomlaroot = (strpos($_SERVER["REQUEST_URI"],"") > 0) ? "" : "";
// define( 'JPATH_BASE', $_SERVER['DOCUMENT_ROOT'] . $myjoomlaroot );
define( 'JPATH_BASE', $_SERVER['DOCUMENT_ROOT'] );
// require_once ( JPATH_BASE .DS. 'includes' .DS. 'defines.php' ); // comment out for joomla4
// require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); // comment out for joomla4
require_once ( JPATH_BASE .'/includes/defines.php' ); // attempt after joomla4 migration
require_once ( JPATH_BASE .'/includes/framework.php' ); // attempt after joomla4 migration
// $mainframe = JFactory::getApplication('site'); // comment out for joomla4
// $app = JFactory::getApplication(); // comment out for joomla4
$mainframe = Factory::getApplication(); // attempt after joomla4 migration
$app = Factory::getApplication(); // attempt after joomla4 migration
$prefix = $app->get('dbprefix');
$mainframe->initialise();
jimport( 'joomla.user.user');
jimport( 'joomla.session.session');
jimport( 'joomla.user.authentication');
// get the database infor mation
// $appvars = JFactory::getApplication(); // connect will use this
$appvars = Factory::getApplication(); // connect will use this // attempt after joomla4 migration
// now get user object and 3 example user variables
//$user = JFactory::getUser();
$user = Factory::getUser(); // attempt after joomla4 migration
***************************************** END CODE **********************************************************************************
scripts that used to work after member login are now failing when script reaches statements using Factor:: functions.
original [inherited] script still used JFactory. After some changes based on articles found online, the script still fails.
1) manually inserting debug statements and selective commenting out Factory function calls all point to problems with the lines using Factory::
2) Factory.php message is "Failed to start application"
3) if all Factory functions commented out - enduser error stating "you must be logged in"
here's the code with original lines commented out and new lines identified as // attempt after joomla4 migration
***************************************** BEGIN CODE **********************************************************************************
// Get Joomla session
use Joomla\CMS\Factory; // attempt after joomla4 migration
define( '_JEXEC', 1 );
define( 'DS', '/' );
// IMPORTANT: adjust path based on folder or define it manually as string
// "myjoomlaroot" is name of your Joomla root folder
// $myjoomlaroot = (strpos($_SERVER["REQUEST_URI"],"") > 0) ? "" : "";
// define( 'JPATH_BASE', $_SERVER['DOCUMENT_ROOT'] . $myjoomlaroot );
define( 'JPATH_BASE', $_SERVER['DOCUMENT_ROOT'] );
// require_once ( JPATH_BASE .DS. 'includes' .DS. 'defines.php' ); // comment out for joomla4
// require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); // comment out for joomla4
require_once ( JPATH_BASE .'/includes/defines.php' ); // attempt after joomla4 migration
require_once ( JPATH_BASE .'/includes/framework.php' ); // attempt after joomla4 migration
// $mainframe = JFactory::getApplication('site'); // comment out for joomla4
// $app = JFactory::getApplication(); // comment out for joomla4
$mainframe = Factory::getApplication(); // attempt after joomla4 migration
$app = Factory::getApplication(); // attempt after joomla4 migration
$prefix = $app->get('dbprefix');
$mainframe->initialise();
jimport( 'joomla.user.user');
jimport( 'joomla.session.session');
jimport( 'joomla.user.authentication');
// get the database infor mation
// $appvars = JFactory::getApplication(); // connect will use this
$appvars = Factory::getApplication(); // connect will use this // attempt after joomla4 migration
// now get user object and 3 example user variables
//$user = JFactory::getUser();
$user = Factory::getUser(); // attempt after joomla4 migration
***************************************** END CODE **********************************************************************************
Statistics: Posted by ahollan1 — Thu Nov 21, 2024 11:22 pm