-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathPopulateCentralWikiTask.php
More file actions
60 lines (48 loc) · 1.58 KB
/
Copy pathPopulateCentralWikiTask.php
File metadata and controls
60 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare( strict_types = 1 );
namespace Miraheze\CreateWiki\Installer;
use MediaWiki\Installer\Task\Task;
use MediaWiki\MainConfigNames;
use MediaWiki\Status\Status;
/** @codeCoverageIgnore Tested by installing MediaWiki. */
class PopulateCentralWikiTask extends Task {
public function getName(): string {
return 'createwiki-populate-central-wiki';
}
public function getDescription(): string {
return '[CreateWiki] Populating central wiki';
}
public function getDependencies(): array {
return [ 'extension-tables', 'services' ];
}
public function execute(): Status {
$connectionProvider = $this->getServices()->getConnectionProvider();
$dbw = $connectionProvider->getPrimaryDatabase( 'virtual-createwiki' );
$dbr = $connectionProvider->getReplicaDatabase( 'virtual-createwiki-central' );
$centralWiki = $dbr->getDomainID();
$exists = $dbw->newSelectQueryBuilder()
->select( 'wiki_dbname' )
->from( 'cw_wikis' )
->where( [ 'wiki_dbname' => $centralWiki ] )
->caller( __METHOD__ )
->fetchRow();
if ( $exists ) {
// The central wiki is already populated.
return Status::newGood();
}
$dbw->newInsertQueryBuilder()
->insertInto( 'cw_wikis' )
->row( [
'wiki_dbname' => $centralWiki,
'wiki_dbcluster' => null,
'wiki_sitename' => $this->getConfigVar( MainConfigNames::Sitename ),
'wiki_language' => $this->getConfigVar( MainConfigNames::LanguageCode ),
'wiki_private' => 0,
'wiki_creation' => $dbw->timestamp(),
'wiki_category' => 'uncategorised',
] )
->caller( __METHOD__ )
->execute();
return Status::newGood();
}
}