Plugins' Master stylesheets deleted on core upgrade
#1
For a while now I've noticed that often after upgrading MyBB to the latest version, some of my plugins lose their styling.

After digging around in the code, I think I've identified why, although I haven't done any testing to confirm this.

It looks as though Master stylesheets are unconditionally deleted on line 222 of admin/inc/functions_themes.php, in the function import_theme_xml():

$db->delete_query("themestylesheets", "tid='{$options['tid']}'");

...as called on line 487 of install/upgrade.php, in the function upgradethemes():

import_theme_xml($contents, array("tid" => 1, "no_templates" => 1, "version_compat" => 1));

By "unconditionally" deleted I mean that all Master stylesheets, including those of plugins and not just those of core, are deleted. If the admin hasn't modified any of these stylesheets for any theme such that inheritance is overridden and the theme has its own copy, then the stylesheet is lost.

Assuming that I've diagnosed this issue correctly, what do other plugin developers do to work around it?

To work around it myself, I've started to add (re)creation of (Master) stylesheets in my plugins' _activate() function rather than in their _install() function, so that an admin can simply deactivate and then reactivate the plugins to get styling back after a core upgrade.

Is there a better way?

Is this even intended behaviour, or is it a bug, and if it is a bug, then could the fix be to add a method of marking stylesheets as either belonging to core or a plugin, and for import_theme_xml() to only conditionally delete core stylesheets, and leave plugin stylesheets alone?
Reply
#2
This user has been denied support. This user has been denied support.
Quote:To work around it myself, I've started to add (re)creation of (Master) stylesheets in my plugins' _activate() function rather than in their _install() function, so that an admin can simply deactivate and then reactivate the plugins to get styling back after a core upgrade.

That's what I do as well, also for settings. Since uninstalling usually stands for losing data (removing database table, settings, themes including customized ones, etc.), uninstall removes all traces of the plugin, so that only leaves deactivate/activate for updating.

That said, I was not aware of this issue. You should report a bug.
Reply
#3
(2020-10-03, 05:59 PM)Laird Wrote: For a while now I've noticed that often after upgrading MyBB to the latest version, some of my plugins lose their styling.

Yes, I noticed the same behaviour.


(2020-10-03, 05:59 PM)Laird Wrote: To work around it myself, I've started to add (re)creation of (Master) stylesheets in my plugins' _activate() function rather than in their _install() function, so that an admin can simply deactivate and then reactivate the plugins to get styling back after a core upgrade.

I have implemented a similar solution in my plugins. I put the stylesheet creation in a seperate function which is still called in _install(), but I added a check in _activate() whether the stylesheet still exists and if not, the creation function is called, so that the admin can just deactivate and activate the plugin after a core upgrade.
Reply
#4
Thanks for your comments, guys. I've reported this as a bug:

https://community.mybb.com/thread-229633.html
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)