From 1d77a661663296359bb8cbc2218e684b21377667 Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Tue, 8 Oct 2024 01:19:00 +0800 Subject: [PATCH 1/3] Add hasChanges methods to helpers (#489) --- includes/Helpers/ManageWikiExtensions.php | 4 ++++ includes/Helpers/ManageWikiNamespaces.php | 4 ++++ includes/Helpers/ManageWikiPermissions.php | 4 ++++ includes/Helpers/ManageWikiSettings.php | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/includes/Helpers/ManageWikiExtensions.php b/includes/Helpers/ManageWikiExtensions.php index 37ad48359..8f706739b 100644 --- a/includes/Helpers/ManageWikiExtensions.php +++ b/includes/Helpers/ManageWikiExtensions.php @@ -132,6 +132,10 @@ public function overwriteAll( array $extensions ) { } } + public function hasChanges(): bool { + return (bool)$this->changes; + } + /** * Commits all changes made to extension lists to the database */ diff --git a/includes/Helpers/ManageWikiNamespaces.php b/includes/Helpers/ManageWikiNamespaces.php index 88790c446..6cafe7872 100644 --- a/includes/Helpers/ManageWikiNamespaces.php +++ b/includes/Helpers/ManageWikiNamespaces.php @@ -167,6 +167,10 @@ public function remove( int $id, int $newNamespace, bool $maintainPrefix = false $this->deleteNamespaces[] = $id; } + public function hasChanges(): bool { + return (bool)$this->changes; + } + /** * Commits all changes to database. Also files a job to move pages into or out of namespace * @param bool $runNamespaceMigrationJob|true diff --git a/includes/Helpers/ManageWikiPermissions.php b/includes/Helpers/ManageWikiPermissions.php index ac02296b8..c8eea7c41 100644 --- a/includes/Helpers/ManageWikiPermissions.php +++ b/includes/Helpers/ManageWikiPermissions.php @@ -142,6 +142,10 @@ public function remove( string $group ) { $this->deleteGroups[] = $group; } + public function hasChanges(): bool { + return (bool)$this->changes; + } + /** * Commits all changes to database */ diff --git a/includes/Helpers/ManageWikiSettings.php b/includes/Helpers/ManageWikiSettings.php index aee6ec46e..942dd1177 100644 --- a/includes/Helpers/ManageWikiSettings.php +++ b/includes/Helpers/ManageWikiSettings.php @@ -139,6 +139,10 @@ public function overwriteAll( array $settings, bool $remove = true ) { } } + public function hasChanges(): bool { + return (bool)$this->changes; + } + /** * Commits all changes to the database */ From 34ad8c59951f81e83c2ea427d9a34ace05c6a09f Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Tue, 8 Oct 2024 01:26:55 +0800 Subject: [PATCH 2/3] Use hasChanges --- includes/FormFactory/ManageWikiFormFactoryBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/FormFactory/ManageWikiFormFactoryBuilder.php b/includes/FormFactory/ManageWikiFormFactoryBuilder.php index fc0c49aba..c35359f25 100644 --- a/includes/FormFactory/ManageWikiFormFactoryBuilder.php +++ b/includes/FormFactory/ManageWikiFormFactoryBuilder.php @@ -836,10 +836,10 @@ public static function submissionHandler( throw new InvalidArgumentException( "{$module} not recognised" ); } - if ( $mwReturn->changes ) { + if ( $mwReturn->hasChanges() ) { $mwReturn->commit(); - if ( $module != 'permissions' ) { + if ( $module !== 'permissions' ) { $mwReturn->logParams['4::wiki'] = $dbName; } @@ -854,7 +854,7 @@ public static function submissionHandler( return [ [ 'managewiki-changes-none' => null ] ]; } - if ( $mwReturn->errors ?? [] && $module == 'permissions' ) { + if ( $mwReturn->errors ?? [] && $module === 'permissions' ) { return $mwReturn->errors; } From 1340cd3c632d98c9bd9ac6d362b9f10370309305 Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Tue, 8 Oct 2024 05:50:27 +0800 Subject: [PATCH 3/3] Fix potentially passing null to json_decode --- includes/Hooks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index 9ff8171ec..bba2af90a 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -67,13 +67,13 @@ public static function onCreateWikiDataFactoryBuilder( string $wiki, IReadableDa // Don't need to manipulate this much if ( ManageWiki::checkSetup( 'settings' ) ) { - $cacheArray['settings'] = json_decode( $setObject->s_settings, true ); + $cacheArray['settings'] = json_decode( $setObject->s_settings ?? '[]', true ); } // Let's create an array of variables so we can easily loop these to enable if ( ManageWiki::checkSetup( 'extensions' ) ) { $manageWikiExtensions = self::getConfig( 'ManageWikiExtensions' ); - foreach ( json_decode( $setObject->s_extensions, true ) as $ext ) { + foreach ( json_decode( $setObject->s_extensions ?? '[]', true ) as $ext ) { $cacheArray['extensions'][] = $manageWikiExtensions[$ext]['var'] ?? $manageWikiExtensions[$ext]['name']; }