Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
70.37% |
19 / 27 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
FlushUtterancesByExpirationDateOnFile | |
90.48% |
19 / 21 |
|
50.00% |
1 / 2 |
5.02 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
81.82% |
9 / 11 |
|
0.00% |
0 / 1 |
4.10 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Wikispeech; |
4 | |
5 | /** |
6 | * @file |
7 | * @ingroup Extensions |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | |
11 | use Maintenance; |
12 | use MediaWiki\Wikispeech\Utterance\FlushUtterancesByExpirationDateOnFileJobQueue; |
13 | use MediaWiki\Wikispeech\Utterance\UtteranceStore; |
14 | |
15 | /** @var string MediaWiki installation path */ |
16 | $IP = getenv( 'MW_INSTALL_PATH' ); |
17 | if ( $IP === false ) { |
18 | $IP = __DIR__ . '/../../..'; |
19 | } |
20 | require_once "$IP/maintenance/Maintenance.php"; |
21 | |
22 | /** |
23 | * Maintenance script to manually execute |
24 | * {@link UtteranceStore::flushUtterancesByExpirationDateOnFile()}. |
25 | * Used to clear out orphaned files (i.e. not tracked by utterance database). |
26 | * |
27 | * mwscript extensions/Wikispeech/maintenance/flushUtterancesByExpirationDateOnFile.php |
28 | * |
29 | * Be aware that you probably need to execute using mwscript, not php, |
30 | * in order to be executed as user www-data, who has access to deleting files. |
31 | * |
32 | * @since 0.1.7 |
33 | */ |
34 | class FlushUtterancesByExpirationDateOnFile extends Maintenance { |
35 | |
36 | /** @var UtteranceStore */ |
37 | private $utteranceStore; |
38 | |
39 | /** @var FlushUtterancesByExpirationDateOnFileJobQueue */ |
40 | private $jobQueue; |
41 | |
42 | public function __construct() { |
43 | parent::__construct(); |
44 | $this->requireExtension( 'Wikispeech' ); |
45 | $this->addDescription( 'Flush orphaned utterances from file backend.' ); |
46 | $this->addOption( |
47 | 'force', |
48 | 'Forces flushing in current thread rather than queuing as job.', |
49 | false, |
50 | false, |
51 | 'f' |
52 | ); |
53 | } |
54 | |
55 | /** |
56 | * @return bool success |
57 | */ |
58 | public function execute() { |
59 | // Non PHP core classes aren't available prior to this point, |
60 | // i.e. we can't initialize the fields in the constructor, |
61 | // and we have to be lenient for mocked instances set by tests. |
62 | |
63 | if ( $this->hasOption( 'force' ) ) { |
64 | if ( !$this->utteranceStore ) { |
65 | $this->utteranceStore = new UtteranceStore(); |
66 | } |
67 | |
68 | $flushedCount = $this->utteranceStore->flushUtterancesByExpirationDateOnFile(); |
69 | $this->output( "Flushed $flushedCount utterances.\n" ); |
70 | } else { |
71 | if ( !$this->jobQueue ) { |
72 | $this->jobQueue = new FlushUtterancesByExpirationDateOnFileJobQueue(); |
73 | } |
74 | |
75 | $this->jobQueue->queueJob(); |
76 | $this->output( 'Flush job has been queued and will be executed ' . |
77 | "in accordance with your MediaWiki configuration.\n" ); |
78 | } |
79 | |
80 | return true; |
81 | } |
82 | |
83 | } |
84 | |
85 | /** @var string This class, required to start via Maintenance. */ |
86 | $maintClass = FlushUtterancesByExpirationDateOnFile::class; |
87 | require_once RUN_MAINTENANCE_IF_MAIN; |