MyBB Community Forums

Full Version: Google Analytics Plugin Error when trying to activate
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I've tried to install following Google Analytics Plugin: https://community.mybb.com/mods.php?action=view&pid=62


After fixing some chmod permission errors i tried to activate it, which gave me following php error:
Fatal error: Uncaught Error: Call to a member function read() on null in /var/www/html/recreate_tables/inc/plugins/googleanalytics.php:73 Stack trace: #0 /var/www/html/recreate_tables/admin/modules/config/plugins.php(435): googleanalytics_activate() #1 /var/www/html/recreate_tables/admin/index.php(830): require('/var/www/html/r...') #2 {main} thrown in /var/www/html/recreate_tables/inc/plugins/googleanalytics.php on line 73

i then opend the File in which the error appear inside an editor (/var/www/html/recreate_tables/inc/plugins/googleanalytics.php).
It appear to happen on line 73 which is following: $CacheData = $cache->read('googleanalytics_versionhistory');

line 73 is inside a function called 'googleanalytics_activate()'

Here the whole function mentioned above:
// This function runs when the plugin is activated.
function googleanalytics_activate()
{
	global $db, $lang;
	$lang->load('googleanalytics');
	
	$CacheData = $cache->read('googleanalytics_versionhistory');
	$OldVersion = $CacheData['versioncode'];
	
	$PluginData = googleanalytics_info();
	$contents = array(
		'version' => $PluginData['version'],
		'versioncode' => $PluginData['versioncode']
	);	
	$cache->update('googleanalytics_versionhistory', $contents);

Personally, I've never really worked in PHP so if someone could provide me with an fixed version or Infos how i can fix it myself, would be really kind.
I assume that I've provided enough Informations but if other Informations are needed, don't hestiate to let me know and i will provide them.

Regards,
Infinimonster
change this line
 global $db, $lang;

to this
 global $db, $lang,$cache;
(2023-05-02, 08:04 AM)Mostafa.Shiraali Wrote: [ -> ]change this line
 global $db, $lang;

to this
 global $db, $lang,$cache;

Thankt was the Solution. Thank you!