Skip to content

Commit

Permalink
MDL-72621 admin: Add environment check for admin deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Sep 29, 2021
1 parent 921bc07 commit a96d456
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
5 changes: 5 additions & 0 deletions admin/environment.xml
Expand Up @@ -3724,6 +3724,11 @@
</CUSTOM_CHECK>
<CUSTOM_CHECK file="lib/upgradelib.php" function="check_max_input_vars" level="optional">
</CUSTOM_CHECK>
<CUSTOM_CHECK file="lib/upgradelib.php" function="check_admin_dir_usage" level="optional">
<FEEDBACK>
<ON_CHECK message="iscustomadminwarnings" />
</FEEDBACK>
</CUSTOM_CHECK>
</CUSTOM_CHECKS>
</MOODLE>
</COMPATIBILITY_MATRIX>
1 change: 1 addition & 0 deletions lang/en/admin.php
Expand Up @@ -683,6 +683,7 @@
It is recommended to install local copy of free GeoLite2 City database from MaxMind.<br />
IP address location is displayed on simple map or using Google Maps. Please note that you need to have a Google account and apply for free Google Maps API key to enable interactive maps.';
$string['iplookupmaxmindnote'] = 'This product includes GeoLite2 data created by MaxMind, available from <a href="https://www.maxmind.com">https://www.maxmind.com</a>.';
$string['iscustomadminwarnings'] = 'It has been detected that your site is using a custom admin directory. This feature is no longer supported and will be removed after Moodle 4.2.';
$string['ishttpswarning'] = 'It has been detected that your site is not secured using HTTPS. It is strongly recommended to migrate your site to HTTPS for increased security and improved integration with other systems.';
$string['keeptagnamecase'] = 'Keep tag name casing';
$string['lang'] = 'Default language';
Expand Down
38 changes: 37 additions & 1 deletion lib/tests/upgradelib_test.php
Expand Up @@ -33,7 +33,7 @@
/**
* Tests various classes and functions in upgradelib.php library.
*/
class core_upgradelib_testcase extends advanced_testcase {
class upgradelib_test extends advanced_testcase {

/**
* Test the {@link upgrade_stale_php_files_present() function
Expand Down Expand Up @@ -1490,4 +1490,40 @@ public function test_upgrade_calendar_group_override_events_fix() {
// Since group override events do not set userid, these events should not be flagged to be fixed.
$this->assertEquals(0, $groupoverrideinfo->bad);
}

/**
* Test the admin_dir_usage check with no admin setting specified.
*/
public function test_admin_dir_usage_not_set(): void {
$result = new environment_results("custom_checks");

$this->assertNull(check_admin_dir_usage($result));
}

/**
* Test the admin_dir_usage check with the default admin setting specified.
*/
public function test_admin_dir_usage_is_default(): void {
global $CFG;

$CFG->admin = 'admin';

$result = new environment_results("custom_checks");
$this->assertNull(check_admin_dir_usage($result));
}

/**
* Test the admin_dir_usage check with a custom admin setting specified.
*/
public function test_admin_dir_usage_non_standard(): void {
global $CFG;

$this->resetAfterTest(true);
$CFG->admin = 'notadmin';

$result = new environment_results("custom_checks");
$this->assertInstanceOf(environment_results::class, check_admin_dir_usage($result));
$this->assertEquals('admin_dir_usage', $result->getInfo());
$this->assertFalse($result->getStatus());
}
}
25 changes: 25 additions & 0 deletions lib/upgradelib.php
Expand Up @@ -2689,3 +2689,28 @@ function check_max_input_vars(environment_results $result) {
}
return null;
}

/**
* Check whether the admin directory has been configured and warn if so.
*
* The admin directory has been deprecated since Moodle 4.0.
*
* @param environment_results $result
* @return null|environment_results
*/
function check_admin_dir_usage(environment_results $result): ?environment_results {
global $CFG;

if (empty($CFG->admin)) {
return null;
}

if ($CFG->admin === 'admin') {
return null;
}

$result->setInfo('admin_dir_usage');
$result->setStatus(false);

return $result;
}

0 comments on commit a96d456

Please sign in to comment.