MyBB Community Forums

Full Version: PluginLibrary 13
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
I'm using this for a plugin I'm currently working on and have noticed a few small issues you may want to check.
  • Sometimes when activating/deactivating the plugin all the templates are deleted when I use $PL->templates_delete('myalerts');
  • The templates function doesn't seem to quite work. When I modify a template inserted using PL via the ACP, the changed version doesn't appear to be loaded at all by the $templates->get method. When I checked the database, there were two versions of the template in the database with different sid versions - one of -2 and the other of 1
@euantor:
If there is a bug in PluginLibrary, I will fix it. But I can't reproduce either issue right now. Can you provide me with a code snippet that will expose the faulty behaviour? Also, which PHP version and database are you using

Quote:Sometimes when activating/deactivating the plugin all the templates are deleted when I use $PL->templates_delete('myalerts');

There's only one way I see templates_delete could delete all templates and that's by $PL->templates_delete('', true). Because empty prefix in greedy mode matches all template groups. You're supposed to be calling this function with a unique prefix used by your plugin only.

Quote:When I checked the database, there were two versions of the template in the database with different sid versions - one of -2 and the other of 1

That's intentional, -2 is the master template, 1 your edited version. This way you can revert edits in the ACP same as stock templates. $templates->get always loads the edited version for me, though, so I wonder why it does not work for you
(2012-05-29, 10:48 AM)frostschutz Wrote: [ -> ]@euantor:
If there is a bug in PluginLibrary, I will fix it. But I can't reproduce either issue right now. Can you provide me with a code snippet that will expose the faulty behaviour? Also, which PHP version and database are you using

Quote:Sometimes when activating/deactivating the plugin all the templates are deleted when I use $PL->templates_delete('myalerts');

There's only one way I see templates_delete could delete all templates and that's by $PL->templates_delete('', true). Because empty prefix in greedy mode matches all template groups. You're supposed to be calling this function with a unique prefix used by your plugin only.

Quote:When I checked the database, there were two versions of the template in the database with different sid versions - one of -2 and the other of 1

That's intentional, -2 is the master template, 1 your edited version. This way you can revert edits in the ACP same as stock templates. $templates->get always loads the edited version for me, though, so I wonder why it does not work for you

You can see all the code here: https://github.com/euantor/MyAlerts/blob...alerts.php

I'm using PHP 5.3.10 with MySQL 5.5.16
OK, I found the reason for all templates getting deleted. It's a bug in PluginLibrary - when the to be deleted template group does not exist (already deleted), it would end up using an empty WHERE condition, which matches everything. Thus all templates gone. Whoops.

This issue did not come up in my testing because I only delete templates on uninstall. Since the template group exists while the plugin is installed, the missing template group case never came up and I didn't think of it.

Your plugin however seems to delete template groups on deactivate already - which I advise against doing since deactivate/activate should work without data loss. So if you deactivate your plugin, the template group is gone. If you uninstall it afterwards, it tries to delete template groups again, and that's where the bug bit you, because the template group was already gone at that point.

I still can not reproduce your other issue with templates. Editing and reverting your MyAlert templates seems to work fine for me, with your current plugin code. Can you still reproduce this issue and give me more detailed instructions? Only thing I can think of right now is that you tried to call $templates->get() before MyBB itself decided which template set to use for this user.
I'll move the template addition/deletion code to the install/uninstall functions then. I'm calling the template from the global_start hook as I need to be able to use the template globally. I'm pretty sure the template set should have been chosen by then.
(2012-05-29, 02:40 PM)euantor Wrote: [ -> ]I'll move the template addition/deletion code to the install/uninstall functions then.

Feel free to add templates and settings in the activate function. This way it will also update them as necessary when you deactivate/activate the plugin. Just move the deletion stuff to the uninstall. At least, that's how it works in my plugins.

Quote:I'm calling the template from the global_start hook as I need to be able to use the template globally. I'm pretty sure the template set should have been chosen by then.

Template and theme is chosen only after the global_start hook.

// Run global_start plugin hook now that the basics are set up
$plugins->run_hooks("global_start");

if(function_exists('mb_internal_encoding') && !empty($lang->settings['charset']))
{
        @mb_internal_encoding($lang->settings['charset']);
}

// Select the board theme to use.
$loadstyle = '';
$load_from_forum = 0;
$style = array();

// This user has a custom theme set in their profile
if(isset($mybb->user['style']) && intval($mybb->user['style']) != 0)
{
        $loadstyle = "tid='".$mybb->user['style']."'";
}
...
// After all of that no theme? Load the board default
if(empty($loadstyle))
{
        $loadstyle = "def='1'";
}

// Fetch the theme to load from the database
$query = $db->simple_select("themes", "name, tid, properties, stylesheets", $loadstyle, array('limit' => 1));
$theme = $db->fetch_array($query);
...
// Load Main Templates and Cached Templates
if(isset($templatelist))
{
        $templatelist .= ',';
}
$templatelist .= "css,headerinclude,header,footer,..."
$templatelist .= ",global_pending_joinrequests,nav,nav_sep,nav_bit,..."
$templates->cache($db->escape_string($templatelist));

So in global_start you don't load templates, but you can add templates to templatelist so they will be fetched along with the whopping big template cache query in global.php

The first hook after template initialization is probably the global_end hook.
Ah, that would explain it. Thanks a lot for the help.
Updated to version 7, which fixes the templates_delete() bug that could delete all templates of the forum if the group was already deleted...

Plugins using this function should update their version check to require version 7 or newer, to make sure that people don't run into this bug by using an old version of PluginLibrary.
(2012-05-30, 01:29 AM)labrocca Wrote: [ -> ]http://mods.mybb.com/view/pluginlibrary is a bad link btw.

Google searching yield this same link. It appears broken because frostschutz just updated the plugin. It still needs to approve.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16