Skip to content

Commit

Permalink
Better module/template version check (#2994)
Browse files Browse the repository at this point in the history
  • Loading branch information
tadhgboyle committed Aug 7, 2022
1 parent 3726a17 commit cdd7d85
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
15 changes: 15 additions & 0 deletions core/classes/Core/Util.php
Expand Up @@ -524,4 +524,19 @@ public static function findBeforeAfter(array $items, string $current): array {
return [$before, $after];
}

/**
* Determine whether a module/template version is compatible with the current NamelessMC version.
* This ignores patch versions, and only checks major and minor versions.
* For example, 2.0.0 and 2.0.1 are compatible, but 2.0.0 and 2.1.0 are not.
* @param string $version Version of module/template to check
* @param string $nameless_version Current NamelessMC version
* @return bool Whether they are compatible or not
*/
public static function isCompatible(string $version, string $nameless_version): bool {
[$major, $minor, ] = explode('.', $version);
[$nameless_major, $nameless_minor, ] = explode('.', $nameless_version);

return $major == $nameless_major && $minor == $nameless_minor;
}

}
4 changes: 2 additions & 2 deletions modules/Core/pages/panel/modules.php
Expand Up @@ -54,10 +54,10 @@
'nameless_version' => Output::getClean($module->getNamelessVersion()),
'author' => Output::getPurified($module->getAuthor()),
'author_x' => $language->get('admin', 'author_x', ['author' => Output::getPurified($module->getAuthor())]),
'version_mismatch' => (($module->getNamelessVersion() != NAMELESS_VERSION) ? $language->get('admin', 'module_outdated', [
'version_mismatch' => !Util::isCompatible($module->getNamelessVersion(), NAMELESS_VERSION) ? $language->get('admin', 'module_outdated', [
'intendedVersion' => Text::bold(Output::getClean($module->getNamelessVersion())),
'actualVersion' => Text::bold(NAMELESS_VERSION)
]) : false),
]) : false,
'disable_link' => (($module->getName() != 'Core' && $item->enabled) ? URL::build('/panel/core/modules/', 'action=disable&m=' . urlencode($item->id)) : null),
'enable_link' => (($module->getName() != 'Core' && !$item->enabled) ? URL::build('/panel/core/modules/', 'action=enable&m=' . urlencode($item->id)) : null),
'enabled' => $item->enabled
Expand Down
11 changes: 4 additions & 7 deletions modules/Core/pages/panel/panel_templates.php
Expand Up @@ -46,13 +46,10 @@
'version' => Output::getClean($template->getVersion()),
'author' => $template->getAuthor(),
'author_x' => $language->get('admin', 'author_x', ['author' => $template->getAuthor()]),
'version_mismatch' => (($template->getNamelessVersion() != NAMELESS_VERSION)
? $language->get('admin', 'template_outdated', [
'intendedVersion' => Output::getClean($template->getNamelessVersion()),
'actualVersion' => NAMELESS_VERSION,
])
: false
),
'version_mismatch' => !Util::isCompatible($template->getNamelessVersion(), NAMELESS_VERSION) ? $language->get('admin', 'template_outdated', [
'intendedVersion' => Output::getClean($template->getNamelessVersion()),
'actualVersion' => NAMELESS_VERSION,
]) : false,
'enabled' => $item->enabled,
'activate_link' => (($item->enabled) ? null : URL::build('/panel/core/panel_templates/', 'action=activate&template=' . urlencode($item->id))),
'delete_link' => (($item->id == 1 || $item->enabled) ? null : URL::build('/panel/core/panel_templates/', 'action=delete&template=' . urlencode($item->id))),
Expand Down
11 changes: 4 additions & 7 deletions modules/Core/pages/panel/templates.php
Expand Up @@ -56,13 +56,10 @@
'version' => Output::getClean($template->getVersion()),
'author' => $template->getAuthor(),
'author_x' => $language->get('admin', 'author_x', ['author' => $template->getAuthor()]),
'version_mismatch' => (($template->getNamelessVersion() != NAMELESS_VERSION)
? $language->get('admin', 'template_outdated', [
'intendedVersion' => Text::bold(Output::getClean($template->getNamelessVersion())),
'actualVersion' => Text::bold(NAMELESS_VERSION)
])
: false
),
'version_mismatch' => !Util::isCompatible($template->getNamelessVersion(), NAMELESS_VERSION) ? $language->get('admin', 'template_outdated', [
'intendedVersion' => Text::bold(Output::getClean($template->getNamelessVersion())),
'actualVersion' => Text::bold(NAMELESS_VERSION)
]) : false,
'enabled' => $item->enabled,
'default_warning' => (Output::getClean($item->name) == 'Default') ? $language->get('admin', 'template_not_supported') : null,
'activate_link' => (($item->enabled) ? null : URL::build('/panel/core/templates/', 'action=activate&template=' . urlencode($item->id))),
Expand Down

0 comments on commit cdd7d85

Please sign in to comment.