PDA

View Full Version : Inserting a template via SQL Query


Artashes
08-31-2011, 07:53 PM
Hello

I am trying to insert new templates via SQL from an external application with the vb database as its database.

The template itself is being inserted correctly into the database. I have made it so that if the template name i supply my script with matches a template name in the database it copies the code (template and template_un), otherwise the template is blank.

This is all acting as I want it.

However, when I make modifications to a template which has the same name as a vb default, it does not result in any of the changes being made to the theme. In fact, when I go to the style manager in the admincp, it does not seem to realise that there is a customised version of the template (it is not red). When I make modifications to the one in the style manager it says that there is already a template and any modifications will override it.

Am I missing something here? How do I get vB to realise that there is a customised version of a default template?

Thanks,

kh99
08-31-2011, 08:18 PM
Looking at admincp/template.php in the "if ($_POST['do'] == 'updatetemplate')" section (around line 2236), it looks like if you are changing .css templates you need to call build_style() after (in includes/adminfunctions_template.php). Also if you change a template starting with 'bbcode_' you need to truncate the 'postparsed' table (but I'm guessing that's not part of the problem you're having).

Artashes
08-31-2011, 08:39 PM
Aye. That's where I've been looking. The templates are neither bbcode nor css, so it doesn't apply :(

I do everything that template.php does, I think!

This is the data I'm entering:

$data = array(
'templateid' => '',
'styleid' => $tStyleId,
'title' => $name,
'template' => $tTemplate,
'template_un' => $tTemplateUn,
'templatetype' => 'template',
'dateline' => $tTime,
'username' => 'Artashes',
'version' => '4.1.5',
'product' => 'vbulletin',
'mergestatus' => 'none'
);

if($this->db->insert('template', $data)){
return TRUE;
} else {
return FALSE;
}

The app uses CodeIgniter's database driver.

But I don't think this is the problem: everything is entered fine. I'll try entering a row into the adminlog.

kh99
08-31-2011, 08:51 PM
I was looking at the wrong section. When you're modifying a template for a style that was inheriting that template, $_POST['do'] is set to 'inserttemplate'. In that section of the code it always calls print_build_style().

Edit: Specifically, it looks like the style table has a list of template ids for all templates in that style. Looks like a serialized array of arrays, so maybe if you don't want to call build_style you could try just updating that field.

Artashes
08-31-2011, 09:03 PM
You know what? I just discovered that myself! Coincidence much!? Just trying to get it to work now!

--------------- Added 1314837575 at 1314837575 ---------------

Neither worked for me :(