Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log updates to dump statuses #88

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,29 @@
},
"LogActionsHandlers": {
"datadump/delete": "LogFormatter",
"datadump/generate": "LogFormatter"
"datadump/generate": "LogFormatter",
"datadump/generate-completed": "LogFormatter",
"datadump/generate-failed": "LogFormatter",
"datadump/generate-in-progress": "LogFormatter"
},
"LogTypes": [
"datadump"
],
"ActionFilteredLogs": {
"datadump": {
"deletion": [
"delete"
],
"generation": [
"generate"
],
"status": [
"generate-completed",
"generate-failed",
"generate-in-progress"
]
}
},
"JobClasses": {
"DataDumpGenerateJob": "Miraheze\\DataDump\\Jobs\\DataDumpGenerateJob"
},
Expand Down
11 changes: 9 additions & 2 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"datadump-refresh": "Refresh page",
"datadump-table-column-completed": "Completed",
"datadump-table-column-failed": "Failed",
"datadump-table-column-in-progress": "In-Progress",
"datadump-table-column-in-progress": "In progress",
"datadump-table-column-queued": "Queued",
"datadump-table-header-date": "Date",
"datadump-table-header-delete": "Delete",
Expand All @@ -52,10 +52,17 @@
"datadump-type-invalid": "The backup type you have selected is invalid. Please inform your system administrator that DataDump may be configured incorrectly.",
"datadump-view": "View backups for this wiki",
"datadump-view-desc": "You can view a list of backups that have been generated and download them but you may not generate new ones.",
"log-action-filter-datadump": "Type of action:",
"log-action-filter-datadump-deletion": "Wiki backup deletion",
"log-action-filter-datadump-generation": "Wiki backup creations",
"log-action-filter-datadump-status": "Wiki backup status updates",
"log-description-datadump": "This log tracks all wiki backups being deleted or generated through [[Special:DataDump|DataDump]].",
"log-name-datadump": "Wiki backup log",
"logentry-datadump-delete": "$1 {{GENDER:$2|deleted}} backup '$4'",
"logentry-datadump-generate": "$1 {{GENDER:$2|initiated}} generation of a backup titled '$4'",
"logentry-datadump-generate": "$1 {{GENDER:$2|queued}} the generation of a backup titled '$4'",
"logentry-datadump-generate-completed": "The generation has completed for a backup titled '$4'",
"logentry-datadump-generate-failed": "An issue was encountered while generating backup '$4' and the backup was aborted",
"logentry-datadump-generate-in-progress": "The generation has initiated for a backup titled '$4'",
"right-delete-dump": "Delete wiki backups",
"right-generate-dump": "Generate wiki backups",
"right-view-dump": "View wiki backups"
Expand Down
8 changes: 8 additions & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@metadata": {
"authors": [
"Agent Isai",
"Amire80",
"Paladox",
"Robby",
Expand Down Expand Up @@ -50,10 +51,17 @@
"datadump-table-header-status": "{{identical|Status}}",
"datadump-table-header-type": "{{identical|Type}}",
"datadump-type-invalid": "Displayed to the user that the type for the dump that has been selected is not in the config.",
"log-action-filter-datadump": "Displayed in [[Special:Log]] as the description for the drop-down menu which allows log filtering.",
"log-action-filter-datadump-deletion": "Option for filtering in [[Special:Log]] that allows for filtering by backup deletion.",
"log-action-filter-datadump-generation": "Option for filtering in [[Special:Log]] that allows for filtering by backup creation.",
"log-action-filter-datadump-status": "Option for filtering in [[Special:Log]] that allows for filtering by backup status updates.",
"log-description-datadump": "Text in [[Special:Log/datadump]].",
"log-name-datadump": "{{doc-logpage}}\n\nThe name of the datadump log.",
"logentry-datadump-delete": "{{Logentry|[[Special:Log/datadump]]}}",
"logentry-datadump-generate": "{{Logentry|[[Special:Log/datadump]]}}",
"logentry-datadump-generate-completed": "{{Logentry|[[Special:Log/datadump]]}}",
"logentry-datadump-generate-failed": "{{Logentry|[[Special:Log/datadump]]}}",
"logentry-datadump-generate-in-progress": "{{Logentry|[[Special:Log/datadump]]}}",
"right-delete-dump": "{{doc-right|delete-dump}}",
"right-generate-dump": "{{doc-right|generate-dump}}",
"right-view-dump": "{{doc-right|view-dump}}"
Expand Down
27 changes: 25 additions & 2 deletions includes/Jobs/DataDumpGenerateJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace Miraheze\DataDump\Jobs;

use Job;
use ManualLogEntry;
use MediaWiki\Config\Config;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
use MediaWiki\Shell\Shell;
use MediaWiki\Title\Title;
use MediaWiki\User\User;
use MediaWiki\User\UserIdentity;
use Miraheze\DataDump\DataDump;

class DataDumpGenerateJob extends Job {
Expand All @@ -20,6 +24,19 @@ public function __construct( $title, $params ) {
$this->config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'DataDump' );
}

private function log( UserIdentity $user, string $action, string $fileName, string $comment = null ) {
$logEntry = new ManualLogEntry( 'datadump', $action );
$logEntry->setPerformer( $user );
$logEntry->setTarget( Title::newFromText( 'Special:DataDump' ) );

if ( $comment ) {
$logEntry->setComment( $comment );
}

$logEntry->setParameters( [ '4::filename' => $fileName ] );
$logEntry->publish( $logEntry->insert() );
}

public function run() {
$dataDumpConfig = $this->config->get( 'DataDump' );
$dataDumpLimits = $this->config->get( 'DataDumpLimits' );
Expand Down Expand Up @@ -96,10 +113,10 @@ public function run() {
}
}

return $this->setStatus( 'failed', $dbw, $directoryBackend, $fileName, __METHOD__ );
return $this->setStatus( 'failed', $dbw, $directoryBackend, $fileName, __METHOD__, $result ?? 'Something went wrong' );
}

private function setStatus( string $status, $dbw, string $directoryBackend, string $fileName, $fname ) {
private function setStatus( string $status, $dbw, string $directoryBackend, string $fileName, $fname, string $comment = null ) {
if ( $status === 'in-progress' ) {
$dbw->update(
'data_dump',
Expand All @@ -112,6 +129,8 @@ private function setStatus( string $status, $dbw, string $directoryBackend, stri
$fname
);
$dbw->commit( __METHOD__, 'flush' );
$this->log( User::newSystemUser( 'Maintenance script' ), 'generate-in-progress', $fileName );

} elseif ( $status === 'completed' ) {
if ( file_exists( wfTempDir() . '/' . $fileName ) ) {
// And now we remove the file from the temp directory, if it exists
Expand All @@ -132,6 +151,8 @@ private function setStatus( string $status, $dbw, string $directoryBackend, stri
$fname
);
$dbw->commit( __METHOD__, 'flush' );
$this->log( User::newSystemUser( 'Maintenance script' ), 'generate-completed', $fileName );

} elseif ( $status === 'failed' ) {
if ( file_exists( wfTempDir() . '/' . $fileName ) ) {
// If the file somehow exists in the temp directory,
Expand All @@ -152,6 +173,8 @@ private function setStatus( string $status, $dbw, string $directoryBackend, stri
$dbw->commit( __METHOD__, 'flush' );
}

$this->log( User::newSystemUser( 'Maintenance script' ), 'generate-failed', $fileName, 'Failed with the following error:' . $comment );

return true;
}
}
Loading