Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LineReaderJob
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLog
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace MediaWiki\Extension\MathSearch\StackExchange;
4
5use MediaWiki\Logger\LoggerFactory;
6use SimpleXMLElement;
7
8class LineReaderJob extends \Job {
9
10    public function __construct( $title, $params ) {
11        parent::__construct( 'SeLineReader', $title, $params );
12    }
13
14    private static function getLog() {
15        return LoggerFactory::getInstance( 'MathSearch' );
16    }
17
18    /**
19     * Run the job
20     * @return bool Success
21     */
22    public function run() {
23        $filename = $this->params['fileName'];
24        foreach ( $this->params['rows'] as $row ) {
25            try {
26                $reader = new Row( $row, $filename );
27                $reader->processBody();
28            } catch ( \Throwable $e ) {
29                self::getLog()
30                    ->error( "While processing\n{row}\n the following exception appeared:\n{e} ", [
31                        'row' => $row,
32                        'e' => $e,
33                    ] );
34                $xml = new SimpleXMLElement( '<row/>' );
35                $rowTransposed = array_flip( $row );
36                array_walk( $rowTransposed, [ $xml, 'addAttribute' ] );
37                file_put_contents( $this->params['errFile'], "{$xml->asXML()}\n", FILE_APPEND );
38
39            }
40
41        }
42
43        return true;
44    }
45
46}