Debian Codegraph @

extensions/Linter/includes/RecordLintJob.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Linter;
22
23 use Job;
24 use MediaWiki\Logger\LoggerFactory;
25 use MediaWiki\Page\PageReference;
26
27 class RecordLintJob extends Job {
28 private TotalsLookup $totalsLookup;
29 private Database $database;
30 private CategoryManager $categoryManager;
31
32 /**
33 * RecordLintJob constructor.
34 * @param PageReference $page
35 * @param array $params
36 * @param TotalsLookup $totalsLookup
37 * @param Database $database
38 * @param CategoryManager $categoryManager
39 */
40 public function __construct(
41 PageReference $page,
42 array $params,
43 TotalsLookup $totalsLookup,
44 Database $database,
45 CategoryManager $categoryManager
46 ) {
47 parent::__construct( 'RecordLintJob', $page, $params );
48 $this->totalsLookup = $totalsLookup;
49 $this->database = $database;
50 $this->categoryManager = $categoryManager;
51 }
52
53 public function run() {
54 if ( $this->title->getLatestRevID() != $this->params['revision'] ) {
55 // Outdated now, let a later job handle it
56 return true;
57 }
58
59 // [ 'id' => LintError ]
60 $errors = [];
61 foreach ( $this->params['errors'] as $errorInfo ) {
62 if ( !$this->categoryManager->isEnabled( $errorInfo['type'] ) ) {
63 // Drop lints of these types for now
64 continue;
65 }
66 $error = new LintError(
67 $errorInfo['type'],
68 $errorInfo['location'],
69 $errorInfo['params'],
70 $errorInfo['dbid']
71 );
72 // Use unique id as key to get rid of exact dupes
73 // (e.g. same category of error in same template)
74 $errors[$error->id()] = $error;
75 }
76
77 LoggerFactory::getInstance( 'Linter' )->debug(
78 '{method}: Recording {numErrors} errors for {page}',
79 [
80 'method' => __METHOD__,
81 'numErrors' => count( $errors ),
82 'page' => $this->title->getPrefixedDBkey()
83 ]
84 );
85
86 $this->totalsLookup->updateStats(
87 $this->database->setForPage(
88 $this->title->getArticleID(),
89 $this->title->getNamespace(),
90 $errors
91 )
92 );
93
94 return true;
95 }
96
97 }