jenkins-bot has submitted this change and it was merged. Change subject: Backfill moderation (delete, suppress) logging that was dropped ......................................................................
Backfill moderation (delete, suppress) logging that was dropped Set timestamp of all Logger logs using the post's moderation timestamp. This applies to all moderation logging (though it shouldn't ordinarily be a big difference), not just this backfill script. Fixes T89504 Bug: T89428 Bug: T89504 Change-Id: I6a39ff8aa8f58c3366cd253011a4b619c3a102a9 --- M container.php M includes/Log/Logger.php M includes/Log/PostModerationLogger.php A maintenance/FlowAddMissingModerationLogs.php 4 files changed, 110 insertions(+), 2 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/container.php b/container.php index 39499b5..3ba5919 100644 --- a/container.php +++ b/container.php @@ -697,15 +697,18 @@ 'Flow\\Model\\PostRevision' => 'storage.post', 'PostRevision' => 'storage.post', + 'post' => 'storage.post', 'Flow\\Model\\PostSummary' => 'storage.post_summary', 'PostSummary' => 'storage.post_summary', + 'post-summary' => 'storage.post_summary', 'Flow\\Model\\TopicListEntry' => 'storage.topic_list', 'TopicListEntry' => 'storage.topic_list', 'Flow\\Model\\Header' => 'storage.header', 'Header' => 'storage.header', + 'header' => 'storage.header', 'BoardHistoryEntry' => 'storage.board_history', diff --git a/includes/Log/Logger.php b/includes/Log/Logger.php index a581a8b..9c1e5f9 100644 --- a/includes/Log/Logger.php +++ b/includes/Log/Logger.php @@ -45,7 +45,7 @@ } /** - * Adds an activity item to the log under the flow|suppress. + * Adds a moderation activity item to the log under the appropriate action * * @param PostRevision $post * @param string $action The action we'll be logging @@ -83,6 +83,8 @@ $logEntry->setPerformer( $this->user ); $logEntry->setParameters( $params ); $logEntry->setComment( $reason ); + $logEntry->setTimestamp( $post->getModerationTimestamp() ); + $logId = $logEntry->insert(); if ( $error ) { diff --git a/includes/Log/PostModerationLogger.php b/includes/Log/PostModerationLogger.php index 494202e..d096424 100644 --- a/includes/Log/PostModerationLogger.php +++ b/includes/Log/PostModerationLogger.php @@ -67,7 +67,7 @@ } } - protected static function getModerationChangeTypes() { + public static function getModerationChangeTypes() { static $changeTypes = false; if ( ! $changeTypes ) { diff --git a/maintenance/FlowAddMissingModerationLogs.php b/maintenance/FlowAddMissingModerationLogs.php new file mode 100644 index 0000000..9508319 --- /dev/null +++ b/maintenance/FlowAddMissingModerationLogs.php @@ -0,0 +1,103 @@ +<?php + +use Flow\Container; +use Flow\Log\PostModerationLogger; +use Flow\Model\UUID; + +require_once ( getenv( 'MW_INSTALL_PATH' ) !== false + ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php' + : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' ); + +/** + * Adjusts edit counts for all existing Flow data. + * + * @ingroup Maintenance + */ +class FlowAddMissingModerationLogs extends LoggedUpdateMaintenance { + public function __construct() { + parent::__construct(); + + $this->mDescription = 'Backfills missing moderation logs from flow_revision'; + + $this->addOption( 'start', 'rev_id of last moderation revision that was logged correctly before regression. Omit to backfill from the beginning', true, true ); + $this->addOption( 'stop', 'rev_id of first revision that was logged correctly after moderation logging fix. Omit to backfill up to the current moment', true, true ); + + $this->setBatchSize( 300 ); + } + + protected function getUpdateKey() { + return 'FlowAddMissingModerationLogs'; + } + + protected function doDBUpdates() { + $container = Container::getContainer(); + + $dbFactory = $container['db.factory']; + $dbw = $dbFactory->getDb( DB_MASTER ); + + $storage = $container['storage']; + + $moderationLogger = $container['storage.post.listeners.moderation_logger']; + + $rowIterator = new EchoBatchRowIterator( + $dbw, + /* table = */'flow_revision', + /* primary key = */'rev_id', + $this->mBatchSize + ); + + $rowIterator->setFetchColumns( array( + 'rev_id', + 'rev_type', + ) ); + + // Fetch rows that are a moderation action + $rowIterator->addConditions( array( + 'rev_change_type' => PostModerationLogger::getModerationChangeTypes(), + ) ); + + $start = $this->getOption( 'start' ); + $startId = UUID::create( $start ); + $rowIterator->addConditions( array( + 'rev_id > ' . $dbw->addQuotes( $startId->getBinary() ), + ) ); + + $stop = $this->getOption( 'stop' ); + $stopId = UUID::create( $stop ); + $rowIterator->addConditions( array( + 'rev_id < ' . $dbw->addQuotes( $stopId->getBinary() ), + ) ); + + $total = $fail = 0; + foreach ( $rowIterator as $batch ) { + $dbw->begin(); + foreach ( $batch as $row ) { + $total++; + $objectManager = $storage->getStorage( $row->rev_type ); + $revId = UUID::create( $row->rev_id ); + $obj = $objectManager->get( $revId ); + if ( !$obj ) { + $this->error( 'Could not load revision: ' . $revId->getAlphadecimal() ); + $fail++; + continue; + } + + $moderationLogger->onAfterInsert( $obj, array(), array() ); + } + + $dbw->commit(); + $storage->clear(); + $dbFactory->waitForSlaves(); + } + + $this->output( "Processed a total of $total moderation revisions.\n" ); + if ( $fail !== 0 ) { + $this->error( "Errors were encountered while processing $fail of them.\n" ); + } + + return true; + } +} + +$maintClass = 'FlowAddMissingModerationLogs'; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- To view, visit https://gerrit.wikimedia.org/r/191543 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6a39ff8aa8f58c3366cd253011a4b619c3a102a9 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: SG <shah...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits