MyBB Community Forums

Full Version: Plugin Deactivation Issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Hello, i seem to be having a file issue. I dont really know how to start off explaining this without giving out information about my website. But the issue only happens when i try to deactivate certain plugins i have added. When i try, it gives me this:
Quote:Fatal error: Cannot redeclare find_replace_templatesets() (previously declared in /home/thecrims/public_html/[website].com/-----/inc/adminfunctions_templates.php:22) in /home/--------/public_html/[website].com/-----/inc/adminfunctions_templates.php on line 101
But when i remove the file, it gives me error reports from several other files. And i have no way of reverting it back to the way it was before. I know my explanation is sort of..bad but i dont really know any way of fixing it. Can someone please help me with this issue?

Also: I attempted to troubleshoot the file itself by looking at the file code, and the code shows this:
<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 *
 * $Id: adminfunctions_templates.php 5164 2010-08-02 03:35:35Z RyanGordon $
 */

/**
 * Find and replace a string in a particular template through every template set.
 *
 * @param string The name of the template
 * @param string The regular expression to match in the template
 * @param string The replacement string
 * @param int Set to 1 to automatically create templates which do not exist for that set (based off master) - Defaults to 1
 * @return bolean true if updated one or more templates, false if not.
 */

function find_replace_templatesets($title, $find, $replace, $autocreate=1)
{
	global $db, $mybb;
	
	$return = false;
	
	$template_sets = array(-2, -1);
	
	// Select all global with that title
	$query = $db->simple_select("templates", "tid, template", "title = '".$db->escape_string($title)."' AND sid='-1'");
	while($template = $db->fetch_array($query))
	{
		// Update the template if there is a replacement term or a change
		$new_template = preg_replace($find, $replace, $template['template']);
		if($new_template == $template['template'])
		{
			continue;
		}
		
		// The template is a custom template.  Replace as normal.
		$updated_template = array(
			"template" => $db->escape_string($new_template)
		);
		$db->update_query("templates", $updated_template, "tid='{$template['tid']}'");
	}
	
	// Select all other modified templates with that title
	$query = $db->simple_select("templates", "tid, sid, template", "title = '".$db->escape_string($title)."' AND sid > 0");
	while($template = $db->fetch_array($query))
	{
		// Keep track of which templates sets have a modified version of this template already
		$template_sets[] = $template['sid'];
		
		// Update the template if there is a replacement term or a change
		$new_template = preg_replace($find, $replace, $template['template']);
		if($new_template == $template['template'])
		{
			continue;
		}
		
		// The template is a custom template.  Replace as normal.
		$updated_template = array(
			"template" => $db->escape_string($new_template)
		);
		$db->update_query("templates", $updated_template, "tid='{$template['tid']}'");
		
		$return = true;
	}
	
	// Add any new templates if we need to and are allowed to
	if($autocreate != 0)
	{
		// Select our master template with that title
		$query = $db->simple_select("templates", "title, template", "title='".$db->escape_string($title)."' AND sid='-2'", array('limit' => 1));
		$master_template = $db->fetch_array($query);
		$master_template['new_template'] = preg_replace($find, $replace, $master_template['template']);
		
		if($master_template['new_template'] != $master_template['template'])
		{
			// Update the rest of our template sets that are currently inheriting this template from our master set			
			$query = $db->simple_select("templatesets", "sid", "sid NOT IN (".implode(',', $template_sets).")");
			while($template = $db->fetch_array($query))
			{
				$insert_template = array(
					"title" => $db->escape_string($master_template['title']),
					"template" => $db->escape_string($master_template['new_template']),
					"sid" => $template['sid'],
					"version" => $mybb->version_code,
					"status" => '',
					"dateline" => TIME_NOW
				);
				$db->insert_query("templates", $insert_template);
				
				$return = true;
			}
		}
	}
	
	$return;
} /**<---Line 101 */
?>
And yet i see no issue in the file, code, or file directory.

~Arctic_Winter
something (presumably the plugin) includes the file twice then when it shouldn't

see if it has a line like require adminfunctions_templates and change that to require_once
So theres a duplicate adminfunctions_templates.php file somewhere in my website DB?

  1. Well, what plugins are we talking about here?
  2. Have you tried uploading a new copy of inc/adminfunctions_templates.php?
  3. Have you opened the plugin file and looked inside for any lines referring to adminfunctions_templates.php?
    If so it/they should be in a require_once() call vs. a require() call.
  4. Doesn't it happen when you activate these plugins as well?
Search the following;
require MYBB_ROOT."/inc/adminfunctions_templates.php";

in both activation and de-activation part of plugin. If nothing found, then add this.
(2010-12-22, 01:00 PM)Yaldaram Wrote: [ -> ]Search the following;
require MYBB_ROOT."/inc/adminfunctions_templates.php";

in both activation and de-activation part of plugin. If nothing found, then add this.

Do not add that. Add require_once instead of require. Smile
The problem here is that it "cannot redeclare"

So open the plugin file find this (maybe a few instances, change all):
require MYBB_ROOT."/inc/adminfunctions_templates.php"; 

Change to:
require_once MYBB_ROOT."/inc/adminfunctions_templates.php"; 

EDIT: Dylan beat me to it Big Grin
It only happens on de-activation.
Out of all my plugins which i will list below, only the ones underlined bring up the message on de-activation

Akismet

Board Messages
Fading Announcements
Usergroup Legend by HSC Community
ModNotice+
ProStats
Registration Security Question
Rules
Spoiler MyCode
Thanks
Welcome Guest
yAnnnouncement

And id like to get a new copy of adminfunctions_templates.php to see if its the code.
(2010-12-22, 01:03 PM)Janota Wrote: [ -> ]EDIT: Dylan beat me to it Big Grin

Twice Wink
(2010-12-22, 01:05 PM)Arctic_Winter Wrote: [ -> ]It only happens on de-activation.
Out of all my plugins which i will list below, only the ones underlined bring up the message on de-activation
Akismet
Board Messages
Fading Announcements
Usergroup Legend by HSC Community
ModNotice+
ProStats
Registration Security Question
Rules
Spoiler MyCode
Thanks
Welcome Guest
yAnnnouncement

Akismet definitely should not be doing it.

Quote:And id like to get a new copy of adminfunctions_templates.php to see if its the code.

Just download MyBB from http://www.mybb.com/downloads/ again, open the zip file, and extract just the adminfunctions_templates.php from it.
Pages: 1 2 3 4