MyBB Community Forums

Full Version: adding templates to new group
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I built a Garage plugin finally and am now working on the plugin setup. I've got all the functions created (info, install, uninstall, activate, deactivate) and need to figure out the best way to install 34 new templates into the default template set.

I have created them already and have the new group insert query done, but I am not sure of the best way to create/insert all 34 templates.

Should I install them with sid = -2 so that user edits are tracked and can be reversed and they are available to all template sets?

How should they be added, via .sql file that I supply and read via fopen or build a huge query in the install function inside the plugin file itself? The fopen option is cleaner, but there can be issues with read access.

Thanks for any help, this plugin is huge and has taken a long time to build. Almost done.
anyone have a suggestion?
Hmm, it's open to interpretation really. Personally, I haven't found "the best" way of doing it.

Adding them as a default template is fine, as long as you are going to remove all of them. Remember, a user could have 12 themes installed, and edited the templates 46 times, creating a headache in the database. Do some testing to see if you fully remove everything if you're going with the default option.

To install them, create an extra php file full of queries. For example, the file will look something like this:

$query = "{mysql_query}" ;// Clears $query for use
$query .= "{another mysql_query}";
$query .= "{yet another mysql_query}";

Then, in your plugin, have a require_once to the file, and fun the queries as one big query. MyBB uses this same technique when it installs, so take a look at its installer if you're not sure.
I exported the templates via phpMyAdmin and did simple insert type export so i built an array with each entry as an array item. Its at the bottom of the plugin outside any function, so I just walk that array and do a write_query() to insert them to the default templates (sid=-2) after deleting all templates that have the plugin prefix. This happens in the activate code.

However, I am not sure I want to delete any templates that may have already been edited. During activation, the plugin can delete the default garage templates (revert them) and leave the user edited ones in place.

My deactivate code does not delete any templates or templategroups as of yet. I'd hate to have my customized templates removed if I deactivated the plugin (on purpose or accidentally since there is no confirmation)