Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractCompositeOwnerMcrCrud
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 create
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace MediaWiki\WikispeechSpeechDataCollector\Crud\Mcr;
4
5/**
6 * @file
7 * @ingroup Extensions
8 * @license GPL-2.0-or-later
9 */
10
11use ExternalStoreException;
12use MediaWiki\WikispeechSpeechDataCollector\Domain\Persistent;
13
14/**
15 * CRUD for composite association owner objects.
16 *
17 * These are objects that create their own unique identity. Compare to composite part objects
18 * that inherit the identity of the composite owner object they are related to.
19 *
20 * A composite part object can not exist without the composite owner.
21 *
22 * E.g, {@link Recording} would be a composite owner object,
23 * while {@link RecordingAnnotations} is a composite part object
24 * that depends on an existing Recording in order to be created.
25 *
26 * @see AbstractCompositePartMcrCrud
27 * @since 0.1.0
28 */
29abstract class AbstractCompositeOwnerMcrCrud extends AbstractMcrCrud {
30
31    /**
32     * Asserts that identity is not set and that the page does not exist.
33     *
34     * @param Persistent $instance
35     * @throws ExternalStoreException
36     */
37    public function create( Persistent $instance ): void {
38        if ( $instance->getIdentity() ) {
39            throw new ExternalStoreException( 'Identity already set' );
40        }
41        $this->getIdentityStrategy()->identityFactory( $instance );
42        $page = $this->getIdentityStrategy()->getWikiPage(
43            $instance->getIdentity(),
44            $this->getContext()
45        );
46        if ( $page->exists() ) {
47            // todo consider,
48            // this probably means that we came up with an identity that was not unique.
49            // should we rather just try again with a new identity?
50            throw new ExternalStoreException( 'Page already exists' );
51        }
52        parent::create( $instance );
53    }
54
55}