Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
ChangeOpGlossList | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
apply | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
validate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getActions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getChangeOps | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\DataAccess\ChangeOp; |
4 | |
5 | use ValueValidators\Result; |
6 | use Wikibase\DataModel\Entity\EntityDocument; |
7 | use Wikibase\Lexeme\Domain\Model\Sense; |
8 | use Wikibase\Lexeme\MediaWiki\Api\Summary\SummaryAggregator; |
9 | use Wikibase\Lib\Summary; |
10 | use Wikibase\Repo\ChangeOp\ChangeOp; |
11 | use Wikibase\Repo\ChangeOp\DummyChangeOpResult; |
12 | use Wikibase\Repo\Store\EntityPermissionChecker; |
13 | use Wikimedia\Assert\Assert; |
14 | |
15 | /** |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | class ChangeOpGlossList implements ChangeOp { |
19 | |
20 | private const SUMMARY_ACTION_AGGREGATE = 'update-sense-glosses'; |
21 | |
22 | /** |
23 | * @var ChangeOp[] |
24 | */ |
25 | private $changeOps; |
26 | |
27 | /** |
28 | * @var SummaryAggregator |
29 | */ |
30 | private $summaryAggregator; |
31 | |
32 | /** |
33 | * @param ChangeOp[] $changeOps |
34 | */ |
35 | public function __construct( array $changeOps ) { |
36 | $this->changeOps = $changeOps; |
37 | $this->summaryAggregator = new SummaryAggregator( self::SUMMARY_ACTION_AGGREGATE ); |
38 | } |
39 | |
40 | public function apply( EntityDocument $entity, ?Summary $summary = null ) { |
41 | Assert::parameterType( Sense::class, $entity, '$entity' ); |
42 | |
43 | foreach ( $this->changeOps as $changeOp ) { |
44 | $subSummary = new Summary(); |
45 | $changeOp->apply( $entity, $subSummary ); |
46 | |
47 | if ( $summary !== null ) { |
48 | $this->summaryAggregator->overrideSummary( $summary, $subSummary ); |
49 | } |
50 | } |
51 | |
52 | return new DummyChangeOpResult(); |
53 | } |
54 | |
55 | public function validate( EntityDocument $entity ) { |
56 | // TODO: should rather combine the validation results from individual change ops |
57 | // OR: return error on first validation error occurred |
58 | Assert::parameterType( Sense::class, $entity, '$entity' ); |
59 | |
60 | return Result::newSuccess(); |
61 | } |
62 | |
63 | public function getActions() { |
64 | // TODO: should rather combine the actions of individual change ops |
65 | return [ EntityPermissionChecker::ACTION_EDIT ]; |
66 | } |
67 | |
68 | /** |
69 | * Get the array of change operations. |
70 | * |
71 | * @return ChangeOp[] |
72 | */ |
73 | public function getChangeOps() { |
74 | return $this->changeOps; |
75 | } |
76 | |
77 | } |