Failed Conditions
Pull Request — user-welcomefix (#623)
by Simon
05:59 queued 03:22
created

MigrateToDomains::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 46
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 46
ccs 0
cts 38
cp 0
rs 9.376
cc 3
nc 3
nop 0
crap 12
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\ConsoleTasks;
10
11
use Waca\DataObjects\Domain;
12
use Waca\DataObjects\RequestQueue;
13
use Waca\Tasks\ConsoleTaskBase;
14
15
class MigrateToDomains extends ConsoleTaskBase
16
{
17
    public function execute()
18
    {
19
        $requestStates = $this->getSiteConfiguration()->getRequestStates();
0 ignored issues
show
Deprecated Code introduced by
The function Waca\SiteConfiguration::getRequestStates() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

19
        $requestStates = /** @scrutinizer ignore-deprecated */ $this->getSiteConfiguration()->getRequestStates();
Loading history...
20
        $database = $this->getDatabase();
21
22
        $domain = new Domain();
23
        $domain->setEnabled(true);
24
        $domain->setShortName('enwiki');
25
        $domain->setLongName('English Wikipedia');
26
        $domain->setWikiArticlePath($this->getSiteConfiguration()->getMediawikiScriptPath());
27
        $domain->setWikiApiPath($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint());
28
        $domain->setEnabled(true);
29
        $domain->setDefaultClose($this->getSiteConfiguration()->getDefaultCreatedTemplateId());
30
        $domain->setDefaultLanguage('en');
31
        $domain->setEmailSender('[email protected]');
32
        $domain->setNotificationTarget($this->getSiteConfiguration()->getIrcNotificationType());
33
34
        $domain->setDatabase($database);
35
        $domain->save();
36
37
        $first = true;
38
        foreach ($requestStates as $key => $data) {
39
            $state = new RequestQueue();
40
            $state->setDefault($first);
41
            $state->setDefaultAntispoof($first);
42
            $state->setDefaultTitleBlacklist($first);
43
            $state->setDomain($domain->getId());
44
            $state->setApiName($data['api']);
45
            $state->setDisplayName($data['deferto']);
46
            $state->setHeader($data['header']);
47
            $state->setLogName($data['defertolog']);
0 ignored issues
show
Deprecated Code introduced by
The function Waca\DataObjects\RequestQueue::setLogName() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

47
            /** @scrutinizer ignore-deprecated */ $state->setLogName($data['defertolog']);
Loading history...
48
            $state->setLegacyStatus($key);
0 ignored issues
show
Deprecated Code introduced by
The function Waca\DataObjects\RequestQueue::setLegacyStatus() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
            /** @scrutinizer ignore-deprecated */ $state->setLegacyStatus($key);
Loading history...
49
            $state->setEnabled(true);
50
51
            if (isset($data['help'])) {
52
                $state->setHelp($data['help']);
53
            }
54
55
            $state->setDatabase($database);
56
            $state->save();
57
58
            $first = false;
59
        }
60
61
        /** @noinspection SqlWithoutWhere */
62
        $database->exec("UPDATE schemaversion SET version = 37;");
63
    }
64
}
65