Skip to content

Commit

Permalink
Fixed template versioning bug.
Browse files Browse the repository at this point in the history
Modded templates always showed up in the "Find Updated Templates"
listing, even after being saved.
  • Loading branch information
lairdshaw committed Feb 15, 2020
1 parent 9eebb6a commit 2d62837
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions inc/plugins/thankyoulike.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,28 +666,19 @@ function tyl_insert_templates()
</tr>"
);

$info = thankyoulike_info();
$plugin_version_code = $info['version_code'];
// Left-pad the version code with any zero that we forbade in thankyoulike_info(),
// where it would have been interpreted as octal.
while(strlen($plugin_version_code) < 6)
{
$plugin_version_code = '0'.$plugin_version_code;
}

// Insert templates into the Master group (sid=-2) with a (string) version set to a value that
// will compare greater than the current MyBB version_code. We set the version to this value so that
// the SQL comparison "m.version > t.version" in the query to find updated templates
// (in admin/modules/style/templates.php) is true for templates modified by the user:
// MyBB sets the version for modified templates to the value of $mybb->version_code.
$version = $mybb->version_code.'_'.$plugin_version_code;
foreach($tyl_templates as $template_title => $template_data)
{
// First, set the to zero the version of modified templates for this plugin.
// (i.e., those with an sid of other than -2). This ensures that Find Updated Templates
// detects them.
$db->update_query('templates', array('version' => 0), "title='{$template_title}' and sid <> -2");

// Now insert/update master templates with SID -2.
$insert_templates = array(
'title' => $db->escape_string($template_title),
'template' => $db->escape_string($template_data),
'sid' => "-2",
'version' => $version,
'version' => '1',
'dateline' => TIME_NOW
);
$db->insert_query('templates', $insert_templates);
Expand Down

0 comments on commit 2d62837

Please sign in to comment.