Closed lairdshaw closed 1 year ago
My preference would be for a custom MyAlerts specific hook that gets ram wherever needed, and then documenting this hook. Only downside would be the possible breakage of existing integrations. On 16 Jul 2023, at 13:46, Laird @.***> wrote: Unfortunately, the fix in (the now merged) PR #290 causes its own problem, which is perhaps not unsurprising, because it was a bit of a hack. That hack was to run the global_start hook in myalerts_xmlhttp(), which itself runs during the xmlhttp hook called from xmlhttp.php. This is because that (global_start) is the hook that most client plugins use to register their MyAlerts formatters, which typically (for client plugins) aren't otherwise registered during xmlhttp.php, leading to unformatted alerts being returned during dynamic updates. The problem this in turn causes is due to at least one plugin - PHP and Template Conditionals - calling the same code - the phptpl_run() function in this case - from both the global_start and xmlhttp hooks, both of which now run for the xmlhttp.php script when MyAlerts is active. The problem this results in is that phptpl_run() declares a class, and in PHP the same class cannot be declared more than once, which is exactly what calling this function twice results in, leading to an error message being appended to the output from xmlhttp.php. I can see three possible alternative solutions which avoid this problem:
Make no changes to MyAlerts but require (via documentation and publicity) all client plugins to ensure that their formatters are correctly registered for xmlhttp.php too, whether via adding an additional hook-in to the xmlhttp hook or, e.g., hooking in solely to pre_session_load, which runs for all scripts, xmlhttp.php and otherwise. Provide a normative MyAlerts-specific hook into which client plugins should hook to register their formatters, and ensure that it runs no matter which script is called, perhaps by itself being run from a hook-in to the pre_session_load hook. Shift all dynamic MyAlerts calls from xmlhttp.php to alerts.php, appending a query parameter ajax=1 as is common in the MyBB codebase to indicate that the call is dynamic. Maintain the hook-in to xmlhttp so as to redirect, via HTTP, requests at the old locations to requests at the new locations, for backwards compatibility.
My preferred option is the third and last, because it is backwards compatible and doesn't require plugin authors to make any changes. Its only drawback is that it sacrifices the slight performance boost of xmlhttp.php, which avoids the more expensive require of global.php. Unless anybody objects, or has improvements to suggest, then I'll implement this solution (and revert the existing hacky solution) after PR #282 is merged, because it will build on that PR. So as for all of this to occur fairly swiftly, I'll in turn merge that PR myself fairly shortly in the absence of any objections or suggested improvements if it's not otherwise merged fairly shortly.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you modified the open/close state.Message ID: @.***>
My preference would be for a custom MyAlerts specific hook that gets ram wherever needed, and then documenting this hook. Only downside would be the possible breakage of existing integrations.
Implemented in #297. I don't think there'll actually be any breakages because the formatter wasn't being used in xmlhttp.php
calls anyway (or, at least, those usages were broken per my comment in #284).
Also, I've added text to the README indicating a recommended approach to backwards compatibility (which assumes that we'll update the version number after merging that PR, if approved).
Please note that I had to force push to that PR to add the commit removing the prior fix, because I'd forgotten to pull from master before forking the refix branch originally.
I don't think there'll actually be any breakages because the formatter wasn't being used in
xmlhttp.php
calls anyway (or, at least, those usages were broken per my comment in #284).
On reconsideration, there will be breakages with respect to the new functionality "Mark all read" in the modal for client plugins that haven't yet been updated to use the new hook (or to add a hook in to xmlhttp
). That was what I was hoping to avoid via my preferred option, the third I listed.
On reconsideration, there will be breakages with respect to the new functionality "Mark all read" in the modal for client plugins that haven't yet been updated to use the new hook (or to add a hook in to
xmlhttp
). That was what I was hoping to avoid via my preferred option, the third I listed.
I have a plan to minimise this breakage: introduce a new plugin setting something like "Backwards compatibility mode". When turned on, an alternative set of templates will be used, which call alerts.php
rather than xmlhttp.php
.
In the absence of objections, especially from you, @euantorano, I'll implement this plan after PRs #282 and #297 are merged.
In the absence of objections or @euantorano doing so first, I'll shortly merge those two PRs myself.
Given eight days (including a weekend) without objections, I've now merged them. Now to start work on the backwards compatibility mode.
Done in #299 - and it turned out not to need any alternative templates, just an addition to the js_popup
template.
Unfortunately, the fix in (the now merged) PR #290 causes its own problem, which is perhaps not unsurprising, because it was a bit of a hack.
That hack was to run the
global_start
hook inmyalerts_xmlhttp()
, which itself runs during thexmlhttp
hook called fromxmlhttp.php
. This is because that (global_start
) is the hook that most client plugins use to register their MyAlerts formatters, which typically (for client plugins) aren't otherwise registered duringxmlhttp.php
, leading to unformatted alerts being returned during dynamic updates.The problem this in turn causes is due to at least one plugin - PHP and Template Conditionals - calling the same code - the
phptpl_run()
function in this case - from both theglobal_start
andxmlhttp
hooks, both of which now run for thexmlhttp.php
script when MyAlerts is active.The problem this results in is that
phptpl_run()
declares a class, and in PHP the same class cannot be declared more than once, which is exactly what calling this function twice results in, leading to an error message being appended to the output fromxmlhttp.php
.I can see three possible alternative solutions which avoid this problem:
xmlhttp.php
too, whether via adding an additional hook-in to thexmlhttp
hook or, e.g., hooking in solely topre_session_load
, which runs for all scripts,xmlhttp.php
and otherwise.pre_session_load
hook.xmlhttp.php
toalerts.php
, appending a query parameterajax=1
as is common in the MyBB codebase to indicate that the call is dynamic. Maintain the hook-in toxmlhttp
so as to redirect, via HTTP, requests at the old locations to requests at the new locations, for backwards compatibility (i.e., when board admins fail to update their MyAlerts templates).My preferred option is the third and last, because it is backwards compatible and doesn't require plugin authors to make any changes. Its only drawback is that it sacrifices the slight performance boost of
xmlhttp.php
, which avoids the more expensiverequire
ofglobal.php
.Unless anybody objects, or has improvements to suggest, then I'll implement this solution (and revert the existing hacky solution) after PR #282 is merged, because it will build on that PR. So as for all of this to occur fairly swiftly, I'll in turn merge that PR myself fairly shortly in the absence of any objections or suggested improvements if it's not otherwise merged fairly shortly.