From 7bd997e97c5877346d7d9850d4f708b2b02c2aec Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 29 Jan 2026 07:28:29 +0800 Subject: [PATCH] MDL-87716 testing: Stop installing composer if in a composer install --- public/lib/testing/lib.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/public/lib/testing/lib.php b/public/lib/testing/lib.php index 568674c22fe..92379db5155 100644 --- a/public/lib/testing/lib.php +++ b/public/lib/testing/lib.php @@ -184,6 +184,19 @@ function testing_error($errorcode, $text = '') { * @param bool $updatedependencies Upgrade dependencies */ function testing_update_composer_dependencies(bool $selfupdate = true, bool $updatedependencies = true): void { + // Check if we are running inside another project that already loaded composer. + if (class_exists(\Composer\InstalledVersions::class)) { + // The Composer library is already loaded. + // Check to see if Moodle is the root package. + $rootpackage = \Composer\InstalledVersions::getRootPackage(); + if ($rootpackage['name'] !== 'moodle/moodle') { + // Assume that the user has already run the composer commands manually. + echo " Composer library is already loaded by another project ({$rootpackage['name']}).\n"; + echo " Skipping composer self-update and dependency update.\n"; + return; + } + } + // To restore the value after finishing. $cwd = getcwd();