Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MediaModerationInsertFileOnUploadJob | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| run | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace MediaWiki\Extension\MediaModeration\Job; |
| 5 | |
| 6 | use MediaWiki\Extension\MediaModeration\Services\MediaModerationDatabaseManager; |
| 7 | use MediaWiki\JobQueue\Job; |
| 8 | |
| 9 | /** |
| 10 | * A job which handles inserting a file to the mediamoderation_scan table on upload. |
| 11 | * |
| 12 | * This job is run if the {@link InsertFileOnUploadUpdate} failed to execute, which can happen with temporary |
| 13 | * issues such as a short read only window, deadlock, or database overload. |
| 14 | */ |
| 15 | class MediaModerationInsertFileOnUploadJob extends Job { |
| 16 | public function __construct( |
| 17 | array $params, |
| 18 | private readonly MediaModerationDatabaseManager $mediaModerationDatabaseManager |
| 19 | ) { |
| 20 | parent::__construct( 'mediaModerationInsertFileOnUploadJob', $params ); |
| 21 | } |
| 22 | |
| 23 | /** @inheritDoc */ |
| 24 | public function run(): bool { |
| 25 | // Because we could not convert the File object to JSON, we need to re-produce what is in |
| 26 | // MediaModerationFileProcessor::insertFile but without having a File object. |
| 27 | // To do that, we have MediaModerationFileProcessor::canScanFile called for us by the code |
| 28 | // that created the job definition and then we can insert using the SHA-1. |
| 29 | if ( $this->params['canScanFile'] ) { |
| 30 | $this->mediaModerationDatabaseManager->insertSha1ToScanTable( $this->params['sha1'] ); |
| 31 | } |
| 32 | |
| 33 | return true; |
| 34 | } |
| 35 | } |