From 436a279dec8d837db77c7eb963e5fea0134095e4 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 16 Jun 2023 15:11:39 +0100 Subject: [PATCH] MDL-76953 mod: deprecate libxml library method wrappers. The `libxml_disable_entity_loader` method is deprecated since PHP8.0, which is our minimum required version so we no longer need to support calls to it using the current wrappers. --- mod/imscp/locallib.php | 10 +++------- mod/imscp/upgrade.txt | 4 ++++ mod/lti/locallib.php | 8 +++----- mod/lti/service.php | 3 --- mod/lti/upgrade.txt | 4 ++++ 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/mod/imscp/locallib.php b/mod/imscp/locallib.php index eed37bf3dad..434eeb1d2eb 100644 --- a/mod/imscp/locallib.php +++ b/mod/imscp/locallib.php @@ -117,11 +117,9 @@ function imscp_parse_structure($imscp, $context) { */ function imscp_parse_manifestfile($manifestfilecontents, $imscp, $context) { $doc = new DOMDocument(); - $oldentities = imscp_libxml_disable_entity_loader(true); if (!$doc->loadXML($manifestfilecontents, LIBXML_NONET)) { return null; } - imscp_libxml_disable_entity_loader($oldentities); // We put this fake URL as base in order to detect path changes caused by xml:base attributes. $doc->documentURI = 'http://grrr/'; @@ -221,11 +219,9 @@ function imscp_recursive_href($manifestfilename, $imscp, $context) { } $doc = new DOMDocument(); - $oldentities = imscp_libxml_disable_entity_loader(true); if (!$doc->loadXML($manifestfile->get_content(), LIBXML_NONET)) { return null; } - imscp_libxml_disable_entity_loader($oldentities); $xmlresources = $doc->getElementsByTagName('resource'); foreach ($xmlresources as $res) { @@ -283,11 +279,11 @@ function imscp_recursive_item($xmlitem, $level, $resources) { * * @param bool $value * @return bool + * + * @deprecated since Moodle 4.3 */ function imscp_libxml_disable_entity_loader(bool $value): bool { - if (PHP_VERSION_ID < 80000) { - return (bool)libxml_disable_entity_loader($value); - } + debugging(__FUNCTION__ . '() is deprecated, please do not use it any more', DEBUG_DEVELOPER); return true; } diff --git a/mod/imscp/upgrade.txt b/mod/imscp/upgrade.txt index b6758283857..b150f3efe6f 100644 --- a/mod/imscp/upgrade.txt +++ b/mod/imscp/upgrade.txt @@ -1,5 +1,9 @@ This files describes API changes in the imscp code. +=== 4.3 === + +* The `imscp_libxml_disable_entity_loader` method is deprecated, as it is no longer required from PHP 8.0 + === 3.0 === * External function mod_imscp_external::get_imscps_by_courses returned parameter "name" has been changed to PARAM_RAW, diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index a6164466b2e..40f7fdc5b09 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -4477,7 +4477,6 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) { // TODO MDL-46023 Replace this code with a call to the new library. $origerrors = libxml_use_internal_errors(true); - $origentity = lti_libxml_disable_entity_loader(true); libxml_clear_errors(); $document = new DOMDocument(); @@ -4489,7 +4488,6 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) { libxml_clear_errors(); libxml_use_internal_errors($origerrors); - lti_libxml_disable_entity_loader($origentity); if (count($errors) > 0) { $message = 'Failed to load cartridge.'; @@ -4584,10 +4582,10 @@ function lti_new_access_token($typeid, $scopes) { * * @param bool $value * @return bool + * + * @deprecated since Moodle 4.3 */ function lti_libxml_disable_entity_loader(bool $value): bool { - if (PHP_VERSION_ID < 80000) { - return (bool)libxml_disable_entity_loader($value); - } + debugging(__FUNCTION__ . '() is deprecated, please do not use it any more', DEBUG_DEVELOPER); return true; } diff --git a/mod/lti/service.php b/mod/lti/service.php index cc940230834..ebc356ad453 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -70,13 +70,10 @@ if ($consumerkey === false) { } // TODO MDL-46023 Replace this code with a call to the new library. -$origentity = lti_libxml_disable_entity_loader(true); $xml = simplexml_load_string($rawbody); if (!$xml) { - lti_libxml_disable_entity_loader($origentity); throw new Exception('Invalid XML content'); } -lti_libxml_disable_entity_loader($origentity); $body = $xml->imsx_POXBody; foreach ($body->children() as $child) { diff --git a/mod/lti/upgrade.txt b/mod/lti/upgrade.txt index dfef7d68b37..2b84c3f2887 100644 --- a/mod/lti/upgrade.txt +++ b/mod/lti/upgrade.txt @@ -1,5 +1,9 @@ This files describes API changes in the lti code. +=== 4.3 === + +* The `lti_libxml_disable_entity_loader` method is deprecated, as it is no longer required from PHP 8.0 + === 4.2 === * get_jwt_claim_mappings() function has been added to service_base class. It allows a service subplugin to be