Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved: 4 Years, 4 Weeks ago Problem theme database
#1
Solved: 4 Years, 4 Weeks ago
Hi,

I have a problem with my theme database.
It does not use the last version of the template files. For example, I have three different template files for "editpost_first" in my database and it is using the version from mybb 1.6 to display the theme. But If I go in the administration panel and I edit this template, it is showing a later version.
Here an image of the three "editpost_first" lines in the database:
   

The problem is not only for this one but also other template files.

I already have installed some plugin but I think I will have to remove them and make a complete reinstallation of the templates before putting them back on.

However, I don't know how to make a fresh install of these templates files, if I click on "Find updated template" it says everything is fine cause it is checking the latest version available and not the ones that are used.
Reply
#2
Solved: 4 Years, 4 Weeks ago
In my opinion there is a problem with these templates. The templates with sid = -2 are from the basic set, which cannot be edited. These are shown in the template listings under the default template set. When you make a change in one of these, they get a sid = 1.

The sid = -1 templates are user defined templates, these can never have the same name as existing templates So that looks like an anomaly in your listing. Also because editpost_first is not a standard template, so it can never have an entry with sid = -2.

This is what I have understood from template versions until now. Perhaps I'm wrong, but then I will be corrected by a staff member I hope. This is then an opportunity to learn things again.
Regards, Ad Bakker (NL)
Reply
#3
Solved: 4 Years, 4 Weeks ago
I did not check again these values but yes this column shows if a template was edited or not (and I did not remember if I find this in a mybb topic or not, can't find it again).

The thing is that I would like to go back with the default templates for mybb 1.8 but as the "Find updated template" does not work, I don't know how to do it if it is not by doing a fresh install and coping all templates in the present database after having deleting all previous templates.

But I don't know why there is different version of the template files and if some column values are related to other values in other tables.
Reply
#4
Solved: 4 Years, 4 Weeks ago
But for the example you give (template editpost_first) there is no default, because this is not a standard template. This must come from a theme, and when you don't want to use this theme anymore, you can delete all 3 versions.

For existing (default) templates, you go back to the original MyBB set by deleting all versions except the sid = -2. That can be done by a single MySQL Query:

DELETE FROM TABLE templates WHERE sid > -2

And delete all rows of table templatesets, except that for sid = 1 (Default templates)

From table themes delete all rows, except thet for tid = 1 (MyBB Master style)

For table themestylesheets execute the MySQL query:

DELETE FROM TABLE themestylesheets WHERE tid > 2

Then you should have a complete clean install of MyBB 1.8.5 (assuming you have installed/upgraded to 1.8.5)

I would consider a complete fresh install. That's not much work either, isn't it?
Regards, Ad Bakker (NL)
Reply
#5
Solved: 4 Years, 4 Weeks ago
Thanks for your detailed reply Ad Bakker.

Is you solution is equal to this :
Creating a fresh install of MyBB 1.8 with test_ prefix for the database and runnning the following queries:

DELETE FROM mybb_templategroups;
DELETE FROM mybb_templates;
DELETE FROM mybb_templatesets;
DELETE FROM mybb_themes;
DELETE FROM mybb_themestylesheets;
INSERT mybb_templategroups SELECT * FROM test_templategroups;
INSERT mybb_templates SELECT * FROM test_templates;
INSERT mybb_templatesets SELECT * FROM test_templatesets;
INSERT mybb_themes SELECT * FROM test_themes;
INSERT mybb_themestylesheets SELECT * FROM test_themestylesheets;

I will first try your queries as I'm not sure how importing a template configuration from another MyBB installation won't create any configuration conflicts.

Edit : Here is what I've done to run what you mentionned:
DELETE FROM mybb_templates WHERE `sid` > '-2';
DELETE FROM mybb_templatesets WHERE `sid` <> '1';
DELETE FROM mybb_themes WHERE `tid` <> '1';
DELETE FROM mybb_themestylesheets WHERE `tid` > '2';


I have some problem regarding default image in template and the SCEditor is not showing properly. I will try running my above queries as well.

Edit2:
Seems it worked for the frontend the editor is here and the theme seems to be displayed properly. However, I have now an issue with the administration panel and more precisely with the cache manager where I have a mportant amount of duplicate "stats" line :

   

Edit3:
http://community.mybb.com/thread-113427.html
From this above topic, I should also copy the datacache from the fresh install to solve this. Let's try it Smile

DELETE FROM mybb_datacache;
INSERT mybb_datacache SELECT * FROM test_datacache;
And rebuild everything after I think ^^"

Edit4:
Not solved.
Everything is duplicated everytime I run the "Rebuild and reload all".
I think I will go back from the beginning and try again this upgrade...
Reply
#6
Solved: 4 Years, 4 Weeks ago
This all seems rather chaotic to me, and I do not understand the intentions anymore. Did you make a proper backup before starting this?

When you want to load database tables form a test install, make a backup of these tables as a .sql file, then change the table prefix test_ into mybb_ by find and replace with a text editor and store it again as a text file with .sql extension, drop all tables which you want to replace and then import the backup.
Regards, Ad Bakker (NL)
Reply
#7
Solved: 4 Years, 4 Weeks ago
Finally I have used the following method:
  • upgrade to 1.8
  • parallel installation of a new forum 1.8 (fofov2)
  • delete category and forum automatically created in this new forum
  • merging these two forum (importing the updated one to fofov2)
  • change the old admin to super admin and delete super admin of the new install
  • tada !
However, I had some problem regarding the attachment merging.
In my forum the attachment names are on the following pattern: "201111/post_9_1321102841_e1277b1817f0bd78db546dc3ce4c0450.attach" and same for the thumbnail. In the mybb merging file for attachment, it is considering a name on this pattern: "201111/post_9_1321102841".attach" so I had some duplicate attachment names. It also did not keep the directory path.
So I manage to change the "merge\boards\mybb\attachments.php" file and the following code seems to give proper result:

<?php
/**
 * MyBB 1.8 Merge System
 * Copyright 2014 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybb.com
 * License: http://www.mybb.com/download/merge-system/license/
 */

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

class MYBB_Converter_Module_Attachments extends Converter_Module_Attachments {

    var $settings = array(
        'friendly_name' => 'attachments',
        'progress_column' => 'aid',
        'default_per_screen' => 20,
    );

    function pre_setup()
    {
        global $import_session, $output, $mybb;

        // Set uploads path
        if(!isset($import_session['uploadspath']))
        {
            $query = $this->old_db->simple_select("settings", "value", "name = 'bburl'", array('limit' => 1));
            $bburl = $this->old_db->fetch_field($query, 'value');
            $this->old_db->free_result($query);

            $query = $this->old_db->simple_select("settings", "value", "name = 'uploadspath'", array('limit' => 1));
            $import_session['uploadspath'] = str_replace('./', $bburl.'/', $this->old_db->fetch_field($query, 'value'));
            $this->old_db->free_result($query);
        }

        $this->check_attachments_dir_perms();

        if($mybb->input['uploadspath'])
        {
            // Test our ability to read attachment files from the forum software
            $this->test_readability("attachments", "attachname");
        }
    }

    function import()
    {
        global $import_session;

        $query = $this->old_db->simple_select("attachments", "*", "", array('limit_start' => $this->trackers['start_attachments'], 'limit' => $import_session['attachments_per_screen']));
        while($attachment = $this->old_db->fetch_array($query))
        {
            $this->insert($attachment);
        }
    }

    function convert_data($data)
    {
        global $db, $import_session, $mybb, $error_notice, $insert_data;
        static $field_info;

        if(!isset($field_info))
        {
            // Get columns so we avoid any 'unknown column' errors
            $field_info = $db->show_fields_from("attachments");
        }

        $insert_data = array();

        foreach($field_info as $key => $field)
        {
            if($field['Extra'] == 'auto_increment')
            {
                if($db->type != "sqlite")
                {
                    unset($insert_data[$field['Field']]);
                }
                continue;
            }

            if(isset($data[$field['Field']]))
            {
                $insert_data[$field['Field']] = $data[$field['Field']];
            }
        }

        // MyBB 1.8 values
        $insert_data['import_aid'] = $data['aid'];
        $insert_data['pid'] = $this->get_import->pid($data['pid']);
        $insert_data['uid'] = $this->get_import->uid($data['uid']);

        $arr = explode("/", $data['attachname']);
        $first_path = $arr[0];
        $second_name = $arr[1];
        $attachname_array = explode('_', str_replace('.attach', '', $second_name));
        $insert_data['attachname'] = $first_path.'/post_'.$this->get_import->uid($attachname_array[1]).'_'.$attachname_array[2].'_'.$attachname_array[3].'.attach';

        if($data['thumbnail'])
        {
            $ext = get_extension($data['thumbnail']);
            $insert_data['thumbnail'] = str_replace(".attach", "_thumb.$ext", $insert_data['attachname']);
        }

        return $insert_data;
    }

    function after_insert($data, $insert_data, $aid)
    {
        global $mybb, $db, $import_session, $lang;

        $thumb_not_exists = $error_notice = "";
        if($data['thumbnail'])
        {
            // Check if the thumbnail directory (YYYYMM) exists, if not, create it
            $check_dir = explode("/", $insert_data['thumbnail']);
            $directory = $check_dir[0];
            $full_name = $check_dir[1];
            if([email protected]_dir($mybb->settings['uploadspath']."/".$directory))
                {
                @mkdir($mybb->settings['uploadspath']."/".$directory);
                }
            // Transfer attachment thumbnail
            $attachment_thumbnail_file = merge_fetch_remote_file($import_session['uploadspath'].'/'.$insert_data['thumbnail']);

            if(!empty($attachment_thumbnail_file))
            {
                $attachrs = @fopen($mybb->settings['uploadspath'].'/'.$insert_data['thumbnail'], 'w');
                if($attachrs)
                {
                    @fwrite($attachrs, $attachment_thumbnail_file);
                }
                else
                {
                    $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_thumbnail_error, $aid));
                }
                @fclose($attachrs);
                @my_chmod($mybb->settings['uploadspath'].'/'.$insert_data['thumbnail'], '0777');
            }
            else
            {
                $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_thumbnail_found, $aid));
            }
        }

        // Check if the attachment directory (YYYYMM) exists, if not, create it
        $check_dir_at = explode("/", $data['attachname']);
        $dir_attachment = $check_dir_at[0];
        $full_name_at = $check_dir_at[1];
        if([email protected]_dir($mybb->settings['uploadspath']."/".$dir_attachment))
            {
            @mkdir($mybb->settings['uploadspath']."/".$dir_attachment);
            }
        
        // Transfer attachment
        $attachment_file = merge_fetch_remote_file($import_session['uploadspath'].'/'.$data['attachname']);
        if(!empty($attachment_file))
        {
            $attachrs = @fopen($mybb->settings['uploadspath'].'/'.$insert_data['attachname'], 'w');
            if($attachrs)
            {
                @fwrite($attachrs, $attachment_file);
                @fclose($attachrs);
            }
            else
            {
                $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_error, $aid));
            }

            @my_chmod($mybb->settings['uploadspath'].'/'.$insert_data['attachname'], '0777');
        }
        else
        {
            $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_not_found, $aid));
        }

        // Restore connection
        $query = $db->simple_select("posts", "message", "pid = '{$insert_data['pid']}'");
        $message = $db->fetch_field($query, 'message');
        $db->free_result($query);
        $message = str_replace('[attachment='.$data['aid'].']', '[attachment='.$aid.']', $message);
    }

    function print_attachments_per_screen_page()
    {
        global $import_session, $lang;

        echo '<tr>
<th colspan="2" class="first last">'.$lang->sprintf($lang->module_attachment_link, $this->plain_bbname).':</th>
</tr>
<tr>
<td><label for="uploadspath"> '.$lang->module_attachment_label.':</label></td>
<td width="50%"><input type="text" name="uploadspath" id="uploadspath" value="'.$import_session['uploadspath'].'" style="width: 95%;" /></td>
</tr>';
    }

    function fetch_total()
    {
        global $import_session;

        // Get number of attachments
        if(!isset($import_session['total_attachments']))
        {
            $query = $this->old_db->simple_select("attachments", "COUNT(*) as count");
            $import_session['total_attachments'] = $this->old_db->fetch_field($query, 'count');
            $this->old_db->free_result($query);
        }

        return $import_session['total_attachments'];
    }
}

?>


The official code is the following:

<?php
/**
 * MyBB 1.8 Merge System
 * Copyright 2014 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybb.com
 * License: http://www.mybb.com/download/merge-system/license/
 */

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

class MYBB_Converter_Module_Attachments extends Converter_Module_Attachments {

    var $settings = array(
        'friendly_name' => 'attachments',
        'progress_column' => 'aid',
        'default_per_screen' => 20,
    );

    function pre_setup()
    {
        global $import_session, $output, $mybb;

        // Set uploads path
        if(!isset($import_session['uploadspath']))
        {
            $query = $this->old_db->simple_select("settings", "value", "name = 'bburl'", array('limit' => 1));
            $bburl = $this->old_db->fetch_field($query, 'value');
            $this->old_db->free_result($query);

            $query = $this->old_db->simple_select("settings", "value", "name = 'uploadspath'", array('limit' => 1));
            $import_session['uploadspath'] = str_replace('./', $bburl.'/', $this->old_db->fetch_field($query, 'value'));
            $this->old_db->free_result($query);
        }

        $this->check_attachments_dir_perms();

        if($mybb->input['uploadspath'])
        {
            // Test our ability to read attachment files from the forum software
            $this->test_readability("attachments", "attachname");
        }
    }

    function import()
    {
        global $import_session;

        $query = $this->old_db->simple_select("attachments", "*", "", array('limit_start' => $this->trackers['start_attachments'], 'limit' => $import_session['attachments_per_screen']));
        while($attachment = $this->old_db->fetch_array($query))
        {
            $this->insert($attachment);
        }
    }

    function convert_data($data)
    {
        global $db, $import_session, $mybb, $error_notice, $insert_data;
        static $field_info;

        if(!isset($field_info))
        {
            // Get columns so we avoid any 'unknown column' errors
            $field_info = $db->show_fields_from("attachments");
        }

        $insert_data = array();

        foreach($field_info as $key => $field)
        {
            if($field['Extra'] == 'auto_increment')
            {
                if($db->type != "sqlite")
                {
                    unset($insert_data[$field['Field']]);
                }
                continue;
            }

            if(isset($data[$field['Field']]))
            {
                $insert_data[$field['Field']] = $data[$field['Field']];
            }
        }

        // MyBB 1.8 values
        $insert_data['import_aid'] = $data['aid'];
        $insert_data['pid'] = $this->get_import->pid($data['pid']);
        $insert_data['uid'] = $this->get_import->uid($data['uid']);

        $attachname_array = explode('_', str_replace('.attach', '', $data['attachname']));
        $insert_data['attachname'] = 'post_'.$this->get_import->uid($attachname_array[1]).'_'.$attachname_array[2].'.attach';

        if($data['thumbnail'])
        {
            $ext = get_extension($data['thumbnail']);
            $insert_data['thumbnail'] = str_replace(".attach", "_thumb.$ext", $insert_data['attachname']);
        }

        return $insert_data;
    }

    function after_insert($data, $insert_data, $aid)
    {
        global $mybb, $db, $import_session, $lang;

        $thumb_not_exists = $error_notice = "";
        if($data['thumbnail'])
        {
            // Transfer attachment thumbnail
            $attachment_thumbnail_file = merge_fetch_remote_file($import_session['uploadspath'].'/'.$insert_data['thumbnail']);

            if(!empty($attachment_thumbnail_file))
            {
                $attachrs = @fopen($mybb->settings['uploadspath'].'/'.$insert_data['thumbnail'], 'w');
                if($attachrs)
                {
                    @fwrite($attachrs, $attachment_thumbnail_file);
                }
                else
                {
                    $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_thumbnail_error, $aid));
                }
                @fclose($attachrs);
                @my_chmod($mybb->settings['uploadspath'].'/'.$insert_data['thumbnail'], '0777');
            }
            else
            {
                $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_thumbnail_found, $aid));
            }
        }

        // Transfer attachment
        $attachment_file = merge_fetch_remote_file($import_session['uploadspath'].'/'.$data['attachname']);
        if(!empty($attachment_file))
        {
            $attachrs = @fopen($mybb->settings['uploadspath'].'/'.$insert_data['attachname'], 'w');
            if($attachrs)
            {
                @fwrite($attachrs, $attachment_file);
                @fclose($attachrs);
            }
            else
            {
                $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_error, $aid));
            }

            @my_chmod($mybb->settings['uploadspath'].'/'.$insert_data['attachname'], '0777');
        }
        else
        {
            $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_not_found, $aid));
        }

        // Restore connection
        $query = $db->simple_select("posts", "message", "pid = '{$insert_data['pid']}'");
        $message = $db->fetch_field($query, 'message');
        $db->free_result($query);
        $message = str_replace('[attachment='.$data['aid'].']', '[attachment='.$aid.']', $message);
    }

    function print_attachments_per_screen_page()
    {
        global $import_session, $lang;

        echo '<tr>
<th colspan="2" class="first last">'.$lang->sprintf($lang->module_attachment_link, $this->plain_bbname).':</th>
</tr>
<tr>
<td><label for="uploadspath"> '.$lang->module_attachment_label.':</label></td>
<td width="50%"><input type="text" name="uploadspath" id="uploadspath" value="'.$import_session['uploadspath'].'" style="width: 95%;" /></td>
</tr>';
    }

    function fetch_total()
    {
        global $import_session;

        // Get number of attachments
        if(!isset($import_session['total_attachments']))
        {
            $query = $this->old_db->simple_select("attachments", "COUNT(*) as count");
            $import_session['total_attachments'] = $this->old_db->fetch_field($query, 'count');
            $this->old_db->free_result($query);
        }

        return $import_session['total_attachments'];
    }
}

?>

Now I have a fresh forum without any file from old plugins or old modifications~

Edit: Just to mention, avatars images were not imported, a simple copy of the files and it's working fine.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)