Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PopulateCognateSites | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
getSiteDetailsFromSiteList | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Cognate; |
4 | |
5 | use MediaWiki\Maintenance\Maintenance; |
6 | use MediaWiki\Site\Site; |
7 | use MediaWiki\Site\SiteList; |
8 | |
9 | if ( getenv( 'MW_INSTALL_PATH' ) !== false ) { |
10 | require_once getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'; |
11 | } else { |
12 | require_once __DIR__ . '/../../../maintenance/Maintenance.php'; |
13 | } |
14 | |
15 | /** |
16 | * Maintenance script for populating the Cognate sites table. |
17 | * |
18 | * @license GPL-2.0-or-later |
19 | * @author Addshore |
20 | */ |
21 | class PopulateCognateSites extends Maintenance { |
22 | |
23 | public function __construct() { |
24 | parent::__construct(); |
25 | |
26 | $this->addDescription( 'Populate the Cognate sites table' ); |
27 | $this->addOption( 'site-group', 'Site group that this wiki is a member of. ' |
28 | . 'For example, "wiktionary".', true, true ); |
29 | $this->requireExtension( 'Cognate' ); |
30 | } |
31 | |
32 | public function execute() { |
33 | $siteGroup = $this->getOption( 'site-group' ); |
34 | $services = $this->getServiceContainer(); |
35 | |
36 | $this->output( "Getting sites.\n" ); |
37 | $siteList = $services->getSiteLookup()->getSites(); |
38 | $siteList = $siteList->getGroup( $siteGroup ); |
39 | |
40 | $this->output( 'Got ' . $siteList->count() . " sites.\n" ); |
41 | $sites = $this->getSiteDetailsFromSiteList( $siteList ); |
42 | |
43 | $this->output( "Inserting sites.\n" ); |
44 | /** @var CognateStore $store */ |
45 | $store = $services->getService( 'CognateStore' ); |
46 | $store->insertSites( $sites ); |
47 | |
48 | $this->output( "Done.\n" ); |
49 | return true; |
50 | } |
51 | |
52 | /** |
53 | * @param SiteList $siteList |
54 | * @return string[] |
55 | */ |
56 | private function getSiteDetailsFromSiteList( SiteList $siteList ) { |
57 | $sites = []; |
58 | foreach ( $siteList as $site ) { |
59 | /** @var Site $site */ |
60 | $sites[$site->getGlobalId()] = $site->getLanguageCode(); |
61 | } |
62 | return $sites; |
63 | } |
64 | |
65 | } |
66 | |
67 | $maintClass = PopulateCognateSites::class; |
68 | require_once RUN_MAINTENANCE_IF_MAIN; |