Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1429794
migrateConfigToCommunity.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
migrateConfigToCommunity.php
View Options
<?php
namespace
MediaWiki\Babel\Maintenance
;
use
LoggedUpdateMaintenance
;
use
MediaWiki\Context\RequestContext
;
use
MediaWiki\Extension\CommunityConfiguration\CommunityConfigurationServices
;
use
MediaWiki\Extension\CommunityConfiguration\Provider\IConfigurationProvider
;
use
MediaWiki\Json\FormatJson
;
use
MediaWiki\Permissions\UltimateAuthority
;
use
MediaWiki\Status\StatusFormatter
;
use
MediaWiki\User\User
;
$IP
=
getenv
(
'MW_INSTALL_PATH'
);
if
(
$IP
===
false
)
{
$IP
=
__DIR__
.
'/../../..'
;
}
require_once
"$IP/maintenance/Maintenance.php"
;
class
MigrateConfigToCommunity
extends
LoggedUpdateMaintenance
{
private
StatusFormatter
$statusFormatter
;
private
IConfigurationProvider
$provider
;
public
function
__construct
()
{
parent
::
__construct
();
$this
->
requireExtension
(
'Babel'
);
$this
->
requireExtension
(
'CommunityConfiguration'
);
$this
->
addOption
(
'dry-run'
,
'Print the migration summary.'
);
}
private
function
initServices
():
void
{
$services
=
$this
->
getServiceContainer
();
$this
->
statusFormatter
=
$services
->
getFormatterFactory
()
->
getStatusFormatter
(
RequestContext
::
getMain
()
);
$ccServices
=
CommunityConfigurationServices
::
wrap
(
$this
->
getServiceContainer
()
);
$this
->
provider
=
$ccServices
->
getConfigurationProviderFactory
()->
newProvider
(
'Babel'
);
}
protected
function
doDBUpdates
()
{
$this
->
initServices
();
$dryRun
=
$this
->
hasOption
(
'dry-run'
);
$config
=
$this
->
getConfig
();
$newConfig
=
(
object
)[
'BabelCategoryNames'
=>
(
object
)
$config
->
get
(
'BabelCategoryNames'
),
'BabelMainCategory'
=>
$config
->
get
(
'BabelMainCategory'
),
'BabelUseUserLanguage'
=>
$config
->
get
(
'BabelUseUserLanguage'
),
'BabelAutoCreate'
=>
$config
->
get
(
'BabelAutoCreate'
),
'BabelCategorizeNamespaces'
=>
$config
->
get
(
'BabelCategorizeNamespaces'
),
];
if
(
$dryRun
)
{
$this
->
output
(
FormatJson
::
encode
(
$newConfig
,
true
)
.
PHP_EOL
);
}
else
{
$status
=
$this
->
provider
->
storeValidConfiguration
(
$newConfig
,
new
UltimateAuthority
(
User
::
newSystemUser
(
User
::
MAINTENANCE_SCRIPT_USER
)
)
);
if
(
$status
->
isOK
()
)
{
$this
->
output
(
'Done!'
.
PHP_EOL
);
}
else
{
$this
->
error
(
'Error when saving the new configuration'
);
$this
->
error
(
'== Error details'
);
$this
->
error
(
$this
->
statusFormatter
->
getWikiText
(
$status
)
);
return
false
;
}
}
return
!
$dryRun
;
}
/**
* @inheritDoc
*/
protected
function
getUpdateKey
()
{
return
'BabelMigrateConfigToCommunity'
;
}
}
$maintClass
=
MigrateConfigToCommunity
::
class
;
require_once
RUN_MAINTENANCE_IF_MAIN
;
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 18:01 (9 h, 17 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
67/d2/d66c310a039fa55a6daa7d065040
Default Alt Text
migrateConfigToCommunity.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment