From de1dbd70ec18e35c68aa35d8878d4e910d492b6a Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Fri, 28 Jul 2023 16:44:29 +0200 Subject: [PATCH] Make EventLogging code more robust This code started to fail when executing the FileImporter tests. FileImporter triggers a hook that ends here. Two suggestions: * I think we don't need/don't want to have log entries for PHPUnit test runs. * In test scenarios getSkin() might return null. Since getSkinName is also allowed to be null I believe it's fine when we log null in such a situation. Bug: T337270 Change-Id: I9bf946c150d99ab97b4cdf128fac87158c633331 --- includes/Hooks.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index 20877f1d..767e9386 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -121,6 +121,10 @@ class Hooks implements * @return void */ public function doEventLogging( $action, $article, $data = [] ) { + if ( defined( 'MW_PHPUNIT_TEST' ) ) { + return; + } + $extensionRegistry = ExtensionRegistry::getInstance(); if ( !$extensionRegistry->isLoaded( 'EventLogging' ) || !$extensionRegistry->isLoaded( 'WikimediaEvents' ) ) { return; @@ -157,7 +161,7 @@ class Hooks implements 'user_is_temp' => $user->isTemp(), 'user_editcount' => $this->userEditTracker->getUserEditCount( $user ) ?: 0, 'mw_version' => MW_VERSION, - 'skin' => $skin->getSkinName(), + 'skin' => $skin ? $skin->getSkinName() : null, 'is_bot' => $user->isRegistered() && $user->isBot(), 'is_anon' => $user->isAnon(), 'wiki' => WikiMap::getCurrentWikiId(),