Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
AbstractUuidRdbmsCrud | |
0.00% |
0 / 10 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
create | |
0.00% |
0 / 7 |
|
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 | use MediaWiki\WikispeechSpeechDataCollector\Uuid; |
14 | |
15 | /** |
16 | * @since 0.1.0 |
17 | * |
18 | * Assigns a UUID as identity in local scope before insert to table. |
19 | */ |
20 | abstract class AbstractUuidRdbmsCrud extends AbstractRdbmsCrud { |
21 | |
22 | /** |
23 | * Given a persistent domain object instance with at least identity set, |
24 | * creates representation in database to correspond to the data set in the domain object. |
25 | * |
26 | * @param Persistent $instance |
27 | * @throws ExternalStoreException If instance identity is already set |
28 | * @since 0.1.0 |
29 | */ |
30 | public function create( |
31 | Persistent $instance |
32 | ): void { |
33 | if ( $instance->getIdentity() ) { |
34 | throw new ExternalStoreException( 'Identity already set' ); |
35 | } |
36 | $instance->setIdentity( Uuid::v4BytesFactory() ); |
37 | $rows = $this->serializeFields( $instance ); |
38 | $rows[ $this->getIdentityColumn() ] = $instance->getIdentity(); |
39 | $dbw = $this->getContext()->getDbLoadBalancer()->getConnection( DB_PRIMARY ); |
40 | $dbw->insert( $this->getTable(), $rows, __METHOD__ ); |
41 | } |
42 | |
43 | /** |
44 | * @param Persistent $instance |
45 | * @param array $row |
46 | * @since 0.1.0 |
47 | */ |
48 | protected function deserializeRowIdentity( |
49 | Persistent $instance, |
50 | $row |
51 | ): void { |
52 | $instance->setIdentity( strval( $row[ $this->getIdentityColumn() ] ) ); |
53 | } |
54 | |
55 | /** |
56 | * @param string $identity |
57 | * @return Persistent|null |
58 | * @since 0.1.0 |
59 | */ |
60 | public function read( |
61 | $identity |
62 | ): ?Persistent { |
63 | return parent::read( $identity ); |
64 | } |
65 | |
66 | /** |
67 | * @param string $identity |
68 | * @since 0.1.0 |
69 | */ |
70 | public function delete( |
71 | $identity |
72 | ): void { |
73 | parent::delete( $identity ); |
74 | } |
75 | |
76 | } |