Commit f0d3d502 authored by Sara Arjona's avatar Sara Arjona
Browse files

MDL-65809 upgrade: remove upgrade_theme_is_from_family

These functions and setting were used only by deleted upgrade steps
so it's safe to proceed with straight deletion, considering
them internal. Deletion has been documented in corresponding
upgrade.txt files:

- upgrade_theme_is_from_family()
- upgrade_find_theme_location()
- linkcoursesectionsupgradescriptwasrun setting
parent c2303069
......@@ -4,6 +4,9 @@ This files describes API changes in /admin/*.
* The following functions, previously used (exclusively) by upgrade steps are not available anymore because of the upgrade cleanup performed for this version. See MDL-65809 for more info:
- upgrade_fix_block_instance_configuration()
- upgrade_theme_is_from_family()
- upgrade_find_theme_location()
- linkcoursesectionsupgradescriptwasrun setting
=== 3.8 ===
......
......@@ -922,22 +922,6 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2017082200.01);
}
if ($oldversion < 2017082300.01) {
// This script in included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->linkcoursesectionsupgradescriptwasrun)) {
// Check if the site is using a boost-based theme.
// If value of 'linkcoursesections' is set to the old default value, change it to the new default.
if (upgrade_theme_is_from_family('boost', $CFG->theme)) {
set_config('linkcoursesections', 1);
}
set_config('linkcoursesectionsupgradescriptwasrun', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2017082300.01);
}
if ($oldversion < 2017082500.00) {
// Handle FKs for the table 'analytics_models_log'.
$table = new xmldb_table('analytics_models_log');
......@@ -3813,5 +3797,11 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2019121800.00);
}
if ($oldversion < 2019122000.01) {
// Clean old upgrade setting not used anymore.
unset_config('linkcoursesectionsupgradescriptwasrun');
upgrade_main_savepoint(true, 2019122000.01);
}
return true;
}
......@@ -783,44 +783,6 @@ class core_upgradelib_testcase extends advanced_testcase {
return \org\bovigo\vfs\vfsStream::url('themes');
}
/**
* Test finding theme locations.
*/
public function test_upgrade_find_theme_location() {
global $CFG;
$this->resetAfterTest();
$CFG->themedir = $this->create_testthemes();
$this->assertSame($CFG->dirroot . '/theme/boost', upgrade_find_theme_location('boost'));
$this->assertSame($CFG->dirroot . '/theme/classic', upgrade_find_theme_location('classic'));
$this->assertSame($CFG->themedir . '/testtheme', upgrade_find_theme_location('testtheme'));
$this->assertSame($CFG->themedir . '/childoftesttheme', upgrade_find_theme_location('childoftesttheme'));
}
/**
* Test figuring out if theme is or is a child of a certain theme.
*/
public function test_upgrade_theme_is_from_family() {
global $CFG;
$this->resetAfterTest();
$CFG->themedir = $this->create_testthemes();
$this->assertTrue(upgrade_theme_is_from_family('boost', 'boost'), 'Boost is a boost theme');
$this->assertTrue(upgrade_theme_is_from_family('boost', 'classic'), 'Classic is a boost base theme');
$this->assertFalse(upgrade_theme_is_from_family('classic', 'boost'), 'Boost is not a classic theme');
$this->assertTrue(upgrade_theme_is_from_family('testtheme', 'childoftesttheme'), 'childoftesttheme is a testtheme');
$this->assertFalse(upgrade_theme_is_from_family('testtheme', 'orphantheme'), 'ofphantheme is not a testtheme');
$this->assertTrue(upgrade_theme_is_from_family('testtheme', 'infinite'), 'Infinite loop with testtheme parent is true');
$this->assertFalse(upgrade_theme_is_from_family('testtheme', 'loop'), 'Infinite loop without testtheme parent is false');
$this->assertTrue(upgrade_theme_is_from_family('testtheme', 'themewithbrokenparent'), 'No error on broken parent');
}
/**
* Data provider of serialized string.
*
......
......@@ -2671,66 +2671,3 @@ function upgrade_fix_config_auth_plugin_defaults($plugin) {
}
}
}
/**
* Search for a given theme in any of the parent themes of a given theme.
*
* @param string $needle The name of the theme you want to search for
* @param string $themename The name of the theme you want to search for
* @param string $checkedthemeforparents The name of all the themes already checked
* @return bool True if found, false if not.
*/
function upgrade_theme_is_from_family($needle, $themename, $checkedthemeforparents = []) {
global $CFG;
// Once we've started checking a theme, don't start checking it again. Prevent recursion.
if (!empty($checkedthemeforparents[$themename])) {
return false;
}
$checkedthemeforparents[$themename] = true;
if ($themename == $needle) {
return true;
}
if ($themedir = upgrade_find_theme_location($themename)) {
$THEME = new stdClass();
require($themedir . '/config.php');
$theme = $THEME;
} else {
return false;
}
if (empty($theme->parents)) {
return false;
}
// Recursively search through each parent theme.
foreach ($theme->parents as $parent) {
if (upgrade_theme_is_from_family($needle, $parent, $checkedthemeforparents)) {
return true;
}
}
return false;
}
/**
* Finds the theme location and verifies the theme has all needed files.
*
* @param string $themename The name of the theme you want to search for
* @return string full dir path or null if not found
* @see \theme_config::find_theme_location()
*/
function upgrade_find_theme_location($themename) {
global $CFG;
if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
$dir = "$CFG->dirroot/theme/$themename";
} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
$dir = "$CFG->themedir/$themename";
} else {
return null;
}
return $dir;
}
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2019122000.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2019122000.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.9dev (Build: 20191220)'; // Human-friendly version name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment