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