Mattflaschen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/191543
Change subject: WIP: Backfill moderation (delete, suppress) logging that was
dropped
......................................................................
WIP: Backfill moderation (delete, suppress) logging that was dropped
TODO: Use setTimestamp to set the logging attempt to when the revision
happened. Otherwise, we'll get a burst of logs when the script is run.
Fixes T89504
Bug: T89428
Bug: T89504
Change-Id: I6a39ff8aa8f58c3366cd253011a4b619c3a102a9
---
M container.php
M includes/Log/PostModerationLogger.php
A maintenance/FlowAddMissingModerationLogs.php
3 files changed, 117 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/43/191543/1
diff --git a/container.php b/container.php
index a3404c8..53a54b1 100644
--- a/container.php
+++ b/container.php
@@ -507,6 +507,11 @@
$c['storage.topic_list.indexes']
);
} );
+
+// TODO: Use the storage.rev-type.class values everywheree
+// (They are currently specified redundantly)
+$c['storage.header.class'] = 'Flow\Model\Header';
+
$c['storage.post.class'] = 'Flow\Model\PostRevision';
$c['storage.post.primary_key'] = array( 'rev_id' );
$c['storage.post.mapper'] = $c->share( function( $c ) {
@@ -613,6 +618,9 @@
$c['storage.post.listeners']
);
} );
+
+$c['storage.post-summary.class'] = 'Flow\Model\PostSummary';
+
$c['storage.topic_history.primary_key'] = array( 'rev_id' );
$c['storage.topic_history.backend'] = $c->share( function( $c ) {
global $wgFlowExternalStore;
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..6506b08
--- /dev/null
+++ b/maintenance/FlowAddMissingModerationLogs.php
@@ -0,0 +1,108 @@
+<?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', false, 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', false, 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' );
+ if ( $start !== null ) {
+ $startId = UUID::create( $start );
+ $rowIterator->addConditions( array(
+ 'rev_id > ' . $dbw->addQuotes(
$startId->getBinary() ),
+ ) );
+ }
+
+ $stop = $this->getOption( 'stop' );
+ if ( $stop !== null ) {
+ $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++;
+ $classKey = "storage.{$row->rev_type}.class";
+ $objectManager = $storage->getStorage(
$container[$classKey] );
+ $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: newchange
Gerrit-Change-Id: I6a39ff8aa8f58c3366cd253011a4b619c3a102a9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits