Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 102 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UpdateFRAutoPromote | |
0.00% |
0 / 96 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 92 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | /** |
3 | * @ingroup Maintenance |
4 | */ |
5 | |
6 | use MediaWiki\User\ActorMigration; |
7 | use MediaWiki\User\User; |
8 | use Wikimedia\Rdbms\IExpression; |
9 | use Wikimedia\Rdbms\LikeValue; |
10 | |
11 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
12 | $IP = getenv( 'MW_INSTALL_PATH' ); |
13 | } else { |
14 | $IP = __DIR__ . '/../../..'; |
15 | } |
16 | |
17 | require_once "$IP/maintenance/Maintenance.php"; |
18 | |
19 | class UpdateFRAutoPromote extends Maintenance { |
20 | |
21 | public function __construct() { |
22 | parent::__construct(); |
23 | $this->addDescription( "Update autopromote table" ); |
24 | $this->setBatchSize( 50 ); |
25 | $this->requireExtension( 'FlaggedRevs' ); |
26 | } |
27 | |
28 | /** |
29 | * @inheritDoc |
30 | */ |
31 | public function execute() { |
32 | $this->output( "Populating and updating flaggedrevs_promote table\n" ); |
33 | |
34 | $services = $this->getServiceContainer(); |
35 | $commentQuery = $services->getCommentStore()->getJoin( 'rev_comment' ); |
36 | $revisionStore = $services->getRevisionStore(); |
37 | $revQuery = $revisionStore->getQueryInfo(); |
38 | $revPageQuery = $revisionStore->getQueryInfo( [ 'page' ] ); |
39 | $dbr = $this->getReplicaDB(); |
40 | $dbw = $this->getPrimaryDB(); |
41 | $start = $dbr->newSelectQueryBuilder() |
42 | ->select( 'MIN(user_id)' ) |
43 | ->from( 'user' ) |
44 | ->caller( __METHOD__ ) |
45 | ->fetchField(); |
46 | $end = $dbr->newSelectQueryBuilder() |
47 | ->select( 'MAX(user_id)' ) |
48 | ->from( 'user' ) |
49 | ->caller( __METHOD__ ) |
50 | ->fetchField(); |
51 | if ( $start === null || $end === null ) { |
52 | $this->output( "...user table seems to be empty.\n" ); |
53 | return; |
54 | } |
55 | $count = 0; |
56 | $changed = 0; |
57 | |
58 | $contentNamespaces = $services->getNamespaceInfo()->getContentNamespaces(); |
59 | $autopromote = $this->getConfig()->get( 'FlaggedRevsAutopromote' ); |
60 | |
61 | for ( $blockStart = (int)$start; $blockStart <= $end; $blockStart += (int)$this->mBatchSize ) { |
62 | $blockEnd = (int)min( $end, $blockStart + $this->mBatchSize - 1 ); |
63 | $this->output( "...doing user_id from $blockStart to $blockEnd\n" ); |
64 | $res = $dbr->newSelectQueryBuilder() |
65 | ->select( '*' ) |
66 | ->from( 'user' ) |
67 | ->where( $dbr->expr( 'user_id', '>=', $blockStart )->and( 'user_id', '<=', $blockEnd ) ) |
68 | ->caller( __METHOD__ ) |
69 | ->fetchResultSet(); |
70 | # Go through and clean up missing items |
71 | foreach ( $res as $row ) { |
72 | $this->beginTransaction( $dbw, __METHOD__ ); |
73 | $user = User::newFromRow( $row ); |
74 | $p = FRUserCounters::getUserParams( $user->getId(), IDBAccessObject::READ_EXCLUSIVE ); |
75 | $oldp = $p; |
76 | # Get edit comments used |
77 | $revWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user ); |
78 | $sres = $dbr->newSelectQueryBuilder() |
79 | ->select( '1' ) |
80 | ->tables( $revQuery['tables'] ) |
81 | ->tables( $commentQuery['tables'] ) |
82 | ->where( [ |
83 | $revWhere['conds'], |
84 | // @todo Should there be a "rev_comment != ''" here too? |
85 | $dbw->expr( |
86 | $commentQuery['fields']['rev_comment_text'], |
87 | IExpression::NOT_LIKE, |
88 | new LikeValue( '/*', $dbw->anyString(), '*/' ) // manual comments only |
89 | ), |
90 | ] ) |
91 | ->limit( max( $autopromote['editComments'], 500 ) ) |
92 | ->joinConds( $commentQuery['joins'] ) |
93 | ->caller( __METHOD__ ) |
94 | ->fetchResultSet(); |
95 | $p['editComments'] = $sres->numRows(); |
96 | # Get content page edits |
97 | $sres = $dbr->newSelectQueryBuilder() |
98 | ->select( '1' ) |
99 | ->tables( $revPageQuery['tables'] ) |
100 | ->where( [ |
101 | $revWhere['conds'], |
102 | 'page_namespace' => $contentNamespaces, |
103 | ] ) |
104 | ->limit( max( $autopromote['totalContentEdits'], 500 ) ) |
105 | ->joinConds( $revPageQuery['joins'] ) |
106 | ->caller( __METHOD__ ) |
107 | ->fetchResultSet(); |
108 | $p['totalContentEdits'] = $sres->numRows(); |
109 | # Get unique content pages edited |
110 | $sres = $dbr->newSelectQueryBuilder() |
111 | ->select( 'rev_page' ) |
112 | ->distinct() |
113 | ->tables( $revPageQuery['tables'] ) |
114 | ->where( [ |
115 | $revWhere['conds'], |
116 | 'page_namespace' => $contentNamespaces, |
117 | ] ) |
118 | ->limit( max( $autopromote['uniqueContentPages'], 50 ) ) |
119 | ->joinConds( $revPageQuery['joins'] ) |
120 | ->caller( __METHOD__ ) |
121 | ->fetchResultSet(); |
122 | $p['uniqueContentPages'] = []; |
123 | foreach ( $sres as $innerRow ) { |
124 | $p['uniqueContentPages'][] = (int)$innerRow->rev_page; |
125 | } |
126 | # Save the new params... |
127 | if ( $oldp != $p ) { |
128 | FRUserCounters::saveUserParams( $user->getId(), $p ); |
129 | $changed++; |
130 | } |
131 | |
132 | $count++; |
133 | $this->commitTransaction( $dbw, __METHOD__ ); |
134 | } |
135 | $this->waitForReplication(); |
136 | } |
137 | $this->output( "flaggedrevs_promote table update complete ..." . |
138 | " {$count} rows [{$changed} changed or added]\n" ); |
139 | } |
140 | } |
141 | |
142 | $maintClass = UpdateFRAutoPromote::class; |
143 | require_once RUN_MAINTENANCE_IF_MAIN; |