Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 46 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
SetVersionData | |
0.00% |
0 / 40 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
initServices | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
fatalStatus | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CommunityConfiguration\Maintenance; |
4 | |
5 | use Maintenance; |
6 | use MediaWiki\Context\RequestContext; |
7 | use MediaWiki\Extension\CommunityConfiguration\CommunityConfigurationServices; |
8 | use MediaWiki\Extension\CommunityConfiguration\Provider\ConfigurationProviderFactory; |
9 | use MediaWiki\Permissions\UltimateAuthority; |
10 | use MediaWiki\Status\StatusFormatter; |
11 | use MediaWiki\User\User; |
12 | |
13 | $IP = getenv( 'MW_INSTALL_PATH' ); |
14 | if ( $IP === false ) { |
15 | $IP = __DIR__ . '/../../..'; |
16 | } |
17 | require_once "$IP/maintenance/Maintenance.php"; |
18 | |
19 | class SetVersionData extends Maintenance { |
20 | |
21 | private StatusFormatter $statusFormatter; |
22 | private ConfigurationProviderFactory $providerFactory; |
23 | |
24 | public function __construct() { |
25 | parent::__construct(); |
26 | $this->requireExtension( 'CommunityConfiguration' ); |
27 | |
28 | $this->addDescription( 'Add version data to configuration that previously did not have it ' . |
29 | '(useful when adding versioning to a schema that did not have it before)' ); |
30 | $this->addArg( |
31 | 'provider', |
32 | 'ID of the provider to change' |
33 | ); |
34 | $this->addArg( |
35 | 'version', |
36 | 'Version of schema the provider adheres to' |
37 | ); |
38 | } |
39 | |
40 | private function initServices(): void { |
41 | $ccServices = CommunityConfigurationServices::wrap( $this->getServiceContainer() ); |
42 | |
43 | $this->statusFormatter = $this->getServiceContainer()->getFormatterFactory()->getStatusFormatter( |
44 | RequestContext::getMain() |
45 | ); |
46 | $this->providerFactory = $ccServices->getConfigurationProviderFactory(); |
47 | } |
48 | |
49 | private function fatalStatus( \StatusValue $status, string $headline ) { |
50 | $this->fatalError( |
51 | "$headline.\n\n== Error details ==\n" |
52 | . $this->statusFormatter->getWikiText( $status ) |
53 | ); |
54 | } |
55 | |
56 | /** |
57 | * @inheritDoc |
58 | */ |
59 | public function execute() { |
60 | $this->initServices(); |
61 | |
62 | $provider = $this->providerFactory->newProvider( $this->getArg( 'provider' ) ); |
63 | $version = $this->getArg( 'version' ); |
64 | |
65 | if ( !$provider->getValidator()->areSchemasSupported() ) { |
66 | $this->fatalError( 'Provider ' . $provider->getId() . ' does not support schemas' ); |
67 | } |
68 | if ( $provider->getValidator()->getSchemaVersion() === null ) { |
69 | $this->fatalError( 'Provider ' . $provider->getId() . ' does not support versions' ); |
70 | } |
71 | |
72 | $currentConfig = $provider->loadValidConfiguration(); |
73 | if ( !$currentConfig->isOK() ) { |
74 | $this->fatalStatus( $currentConfig, 'Failed to load configuration' ); |
75 | } |
76 | |
77 | $status = $provider->getStore()->storeConfiguration( |
78 | $currentConfig->getValue(), |
79 | $version, |
80 | new UltimateAuthority( User::newSystemUser( User::MAINTENANCE_SCRIPT_USER ) ), |
81 | 'Adding version data' |
82 | ); |
83 | if ( !$status->isOK() ) { |
84 | $this->fatalStatus( $status, 'Failed to add version data' ); |
85 | } |
86 | |
87 | $this->output( 'All done!' . PHP_EOL ); |
88 | } |
89 | } |
90 | |
91 | $maintClass = SetVersionData::class; |
92 | require_once RUN_MAINTENANCE_IF_MAIN; |