Skip to content

Commit

Permalink
Add some logging if cache fails to write and also fix removing temp f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
paladox authored Dec 3, 2023
1 parent a2633d6 commit 544739b
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions includes/CreateWikiJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BagOStuff;
use Config;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use Miraheze\CreateWiki\Hooks\CreateWikiHookRunner;
use ObjectCache;
Expand Down Expand Up @@ -268,11 +269,23 @@ private function generateDatabasesJsonFile( array $databaseLists ) {
if ( $tmpFile ) {
if ( file_put_contents( $tmpFile, json_encode( $contents ) ) ) {
if ( !rename( $tmpFile, "{$this->cacheDir}/{$name}.json" ) ) {
unlink( $tmpFile );
LoggerFactory::getInstance( 'CreateWiki' )->error(
'Database cache failure: failure to rename {name} temp fle on disk.',
[
'name' => $tmpFile
]
);
}
} else {
unlink( $tmpFile );
LoggerFactory::getInstance( 'CreateWiki' )->error(
'Database cache failure: failure to write cache to disk at {name}.',
[
'name' => "{$this->cacheDir}/{$name}.json"
]
);
}

unlink( $tmpFile );
}
}
}
Expand Down Expand Up @@ -344,11 +357,23 @@ private function generateWiki() {
if ( $tmpFile ) {
if ( file_put_contents( $tmpFile, json_encode( $jsonArray ) ) ) {
if ( !rename( $tmpFile, "{$this->cacheDir}/{$this->wiki}.json" ) ) {
unlink( $tmpFile );
LoggerFactory::getInstance( 'CreateWiki' )->error(
'Wiki cache failure: failure to rename {name} temp fle on disk.',
[
'name' => $tmpFile
]
);
}
} else {
unlink( $tmpFile );
LoggerFactory::getInstance( 'CreateWiki' )->error(
'Database cache failure: failure to write cache to disk at {name}.',
[
'name' => "{$this->cacheDir}/{$this->wiki}.json"
]
);
}

unlink( $tmpFile );
}
}

Expand Down

0 comments on commit 544739b

Please sign in to comment.