Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
AbstractIntRdbmsCrud | |
0.00% |
0 / 9 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
create | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
deserializeRowIdentity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
read | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
delete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\WikispeechSpeechDataCollector\Crud\Rdbms; |
4 | |
5 | /** |
6 | * @file |
7 | * @ingroup Extensions |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | |
11 | use ExternalStoreException; |
12 | use MediaWiki\WikispeechSpeechDataCollector\Domain\Persistent; |
13 | |
14 | /** |
15 | * @since 0.1.0 |
16 | * |
17 | * Expects that the integer identity is created during insert to table. |
18 | */ |
19 | abstract class AbstractIntRdbmsCrud extends AbstractRdbmsCrud { |
20 | |
21 | /** |
22 | * Given a persistent domain object instance with at least identity set, |
23 | * creates representation in database to correspond to the data set in the domain object. |
24 | * |
25 | * @param Persistent $instance |
26 | * @throws ExternalStoreException If instance identity is already set |
27 | * @since 0.1.0 |
28 | */ |
29 | public function create( |
30 | Persistent $instance |
31 | ): void { |
32 | if ( $instance->getIdentity() ) { |
33 | throw new ExternalStoreException( 'Identity already set' ); |
34 | } |
35 | $rows = $this->serializeFields( $instance ); |
36 | $dbw = $this->getContext()->getDbLoadBalancer()->getConnection( DB_PRIMARY ); |
37 | $dbw->insert( $this->getTable(), $rows, __METHOD__ ); |
38 | $instance->setIdentity( $dbw->insertId() ); |
39 | } |
40 | |
41 | /** |
42 | * @param Persistent $instance |
43 | * @param array $row |
44 | * @since 0.1.0 |
45 | */ |
46 | protected function deserializeRowIdentity( |
47 | Persistent $instance, |
48 | $row |
49 | ): void { |
50 | $instance->setIdentity( intval( $row[ $this->getIdentityColumn() ] ) ); |
51 | } |
52 | |
53 | /** |
54 | * @param int $identity |
55 | * @return Persistent|null |
56 | * @since 0.1.0 |
57 | */ |
58 | public function read( |
59 | $identity |
60 | ): ?Persistent { |
61 | return parent::read( $identity ); |
62 | } |
63 | |
64 | /** |
65 | * @param int $identity |
66 | * @since 0.1.0 |
67 | */ |
68 | public function delete( |
69 | $identity |
70 | ): void { |
71 | parent::delete( $identity ); |
72 | } |
73 | } |