|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace Wikibase\Client\ChangeModification; |
|
6
|
|
|
|
|
7
|
|
|
use MediaWiki\MediaWikiServices; |
|
8
|
|
|
use Title; |
|
9
|
|
|
use Wikimedia\Assert\Assert; |
|
10
|
|
|
use Wikimedia\Rdbms\LBFactory; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Job for notifying a client wiki of a batch of revision visibility changes on the repository. |
|
14
|
|
|
* |
|
15
|
|
|
* @license GPL-2.0-or-later |
|
16
|
|
|
* @author Marius Hoch |
|
17
|
|
|
*/ |
|
18
|
|
|
class ChangeVisibilityNotificationJob extends ChangeModificationNotificationJob { |
|
19
|
|
|
|
|
20
|
|
|
private $batchSize; |
|
21
|
|
|
private $lbFactory; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Constructs a ChangeVisibilityNotificationJob for the repo revisions given. |
|
25
|
|
|
* |
|
26
|
|
|
* @param LBFactory $lbFactory |
|
27
|
|
|
* @param int $batchSize |
|
28
|
|
|
* @param array $params Contains the name of the repo, revisionIdentifiersJson to redact |
|
29
|
|
|
* and the visibilityBitFlag to set. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct( LBFactory $lbFactory, int $batchSize, array $params = [] ) { |
|
32
|
|
|
parent::__construct( 'ChangeVisibilityNotification', $lbFactory->getMainLB(), $params ); |
|
33
|
|
|
|
|
34
|
|
|
Assert::parameter( |
|
35
|
|
|
isset( $params['visibilityBitFlag'] ), |
|
36
|
|
|
'$params', |
|
37
|
|
|
'$params[\'visibilityBitFlag\'] not set.' |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
$this->lbFactory = $lbFactory; |
|
41
|
|
|
$this->batchSize = $batchSize; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public static function newFromGlobalState( Title $unused, array $params ) { |
|
45
|
|
|
$mwServices = MediaWikiServices::getInstance(); |
|
46
|
|
|
|
|
47
|
|
|
return new self( |
|
48
|
|
|
$mwServices->getDBLoadBalancerFactory(), |
|
49
|
|
|
$mwServices->getMainConfig()->get( 'UpdateRowsPerQuery' ), |
|
50
|
|
|
$params |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param int[] $relevantChanges |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function modifyChanges( array $relevantChanges ): void { |
|
58
|
|
|
$visibilityBitFlag = $this->params['visibilityBitFlag']; |
|
59
|
|
|
|
|
60
|
|
|
$dbw = $this->loadBalancer->getConnection( DB_MASTER ); |
|
61
|
|
|
|
|
62
|
|
|
foreach ( array_chunk( $relevantChanges, $this->batchSize ) as $rcIdBatch ) { |
|
63
|
|
|
$dbw->update( |
|
64
|
|
|
'recentchanges', |
|
65
|
|
|
[ 'rc_deleted' => $visibilityBitFlag ], |
|
66
|
|
|
[ 'rc_id' => $rcIdBatch ], |
|
67
|
|
|
__METHOD__ |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$this->lbFactory->waitForReplication(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|