Migration::schemaUpdates()   F
last analyzed

Complexity

Conditions 13
Paths 4096

Size

Total Lines 112
Code Lines 92

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 92
nc 4096
nop 0
dl 0
loc 112
rs 2.1345
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Copyright (c) by the ACP3 Developers.
5
 * See the LICENSE file at the top-level module directory for licensing details.
6
 */
7
8
namespace ACP3\Modules\ACP3\Users\Installer;
9
10
use ACP3\Core\Date;
11
use ACP3\Core\Modules;
12
13
class Migration extends Modules\Installer\AbstractMigration
14
{
15
    /**
16
     * {@inheritdoc}
17
     *
18
     * @return array
19
     */
20
    public function schemaUpdates()
21
    {
22
        return [
23
            31 => [
24
                "INSERT INTO `{pre}settings` (`id`, `module_id`, `name`, `value`) VALUES ('', '{moduleId}', 'mail', '');",
25
            ],
26
            32 => [
27
                'ALTER TABLE `{pre}users` DROP `msn`;',
28
                "UPDATE `{pre}users` SET `mail` = REVERSE(SUBSTRING(REVERSE(`mail`), 1 + LOCATE(':', REVERSE(`mail`))));",
29
                "UPDATE `{pre}users` SET `realname` = REVERSE(SUBSTRING(REVERSE(`realname`), 1 + LOCATE(':', REVERSE(`realname`))));",
30
                "UPDATE `{pre}users` SET `gender` = REVERSE(SUBSTRING(REVERSE(`gender`), 1 + LOCATE(':', REVERSE(`gender`))));",
31
                "UPDATE `{pre}users` SET `birthday` = REVERSE(SUBSTRING(REVERSE(`birthday`), 1 + LOCATE(':', REVERSE(`birthday`))));",
32
                "UPDATE `{pre}users` SET `website` = REVERSE(SUBSTRING(REVERSE(`website`), 1 + LOCATE(':', REVERSE(`website`))));",
33
                "UPDATE `{pre}users` SET `icq` = REVERSE(SUBSTRING(REVERSE(`icq`), 1 + LOCATE(':', REVERSE(`icq`))));",
34
                "UPDATE `{pre}users` SET `skype` = REVERSE(SUBSTRING(REVERSE(`skype`), 1 + LOCATE(':', REVERSE(`skype`))));",
35
                'ALTER TABLE `{pre}users` CHANGE `gender` `gender` TINYINT(1) UNSIGNED NOT NULL;',
36
                'ALTER TABLE `{pre}users` CHANGE `birthday` `birthday` VARCHAR(10) NOT NULL;',
37
                'ALTER TABLE `{pre}users` CHANGE `birthday_format` `birthday_display` TINYINT(1) UNSIGNED NOT NULL;',
38
                'ALTER TABLE `{pre}users` ADD `street` VARCHAR(120) NOT NULL AFTER `skype`;',
39
                'ALTER TABLE `{pre}users` ADD `house_number` VARCHAR(5) NOT NULL AFTER `street`;',
40
                'ALTER TABLE `{pre}users` ADD `zip` VARCHAR(5) NOT NULL AFTER `house_number`;',
41
                'ALTER TABLE `{pre}users` ADD `city` VARCHAR(120) NOT NULL AFTER `zip`;',
42
                'ALTER TABLE `{pre}users` ADD `country` CHAR(2) NOT NULL AFTER `city`;',
43
                'ALTER TABLE `{pre}users` ADD `address_display` TINYINT(1) UNSIGNED NOT NULL AFTER `city`;',
44
                'ALTER TABLE `{pre}users` ADD `country_display` TINYINT(1) UNSIGNED NOT NULL AFTER `country`;',
45
                'ALTER TABLE `{pre}users` ADD `mail_display` TINYINT(1) UNSIGNED NOT NULL AFTER `mail`;',
46
            ],
47
            33 => [
48
                "DELETE FROM `{pre}acl_resources` WHERE `module_id` = '{moduleId}' AND `page` = \"functions\";",
49
            ],
50
            34 => [
51
                'ALTER TABLE `{pre}users` ADD `registration_date` DATETIME NOT NULL AFTER `draft`;',
52
                "UPDATE `{pre}users` SET `registration_date` = '" . \gmdate(Date::DEFAULT_DATE_FORMAT_FULL) . "';",
53
            ],
54
            35 => [
55
                "DELETE FROM `{pre}acl_resources` WHERE `module_id` = '{moduleId}' AND `page` = 'sidebar';",
56
                "INSERT INTO `{pre}acl_resources` (`id`, `module_id`, `page`, `params`, `privilege_id`) VALUES('', '{moduleId}', 'sidebar_login', '', 1);",
57
                "INSERT INTO `{pre}acl_resources` (`id`, `module_id`, `page`, `params`, `privilege_id`) VALUES('', '{moduleId}', 'sidebar_user_menu', '', 1);",
58
            ],
59
            36 => [
60
                'UPDATE `{pre}seo` SET `uri`=REPLACE(`uri`, "users/", "users/index/") WHERE `uri` LIKE "users/%";',
61
            ],
62
            37 => [
63
                "UPDATE `{pre}acl_resources` SET `controller` = 'account', `page` = 'edit' WHERE `module_id` = '{moduleId}' AND `area` = 'frontend' AND `page` = 'edit_profile';",
64
                "UPDATE `{pre}acl_resources` SET `controller` = 'account', `page` = 'settings' WHERE `module_id` = '{moduleId}' AND `area` = 'frontend' AND `page` = 'edit_settings';",
65
                "UPDATE `{pre}acl_resources` SET `controller` = 'account', `page` = 'index' WHERE `module_id` = '{moduleId}' AND `area` = 'frontend' AND `page` = 'home';",
66
            ],
67
            38 => [
68
                'UPDATE `{pre}users` SET `language` = "de_DE" WHERE `language` = "de";',
69
                'UPDATE `{pre}users` SET `language` = "en_US" WHERE `language` = "en";',
70
            ],
71
            39 => [
72
                $this->schemaHelper->moduleIsInstalled('menus') || $this->schemaHelper->moduleIsInstalled('menu_items') ? 'UPDATE `{pre}menu_items` SET `uri`=REPLACE(`uri`, "users/forgot_pwd/", "users/index/forgot_pwd/") WHERE `uri` LIKE "users/forgot_pwd/%";' : '',
73
                $this->schemaHelper->moduleIsInstalled('menus') || $this->schemaHelper->moduleIsInstalled('menu_items') ? 'UPDATE `{pre}menu_items` SET `uri`=REPLACE(`uri`, "users/list/", "users/index/index/") WHERE `uri` LIKE "users/list/%";' : '',
74
                $this->schemaHelper->moduleIsInstalled('menus') || $this->schemaHelper->moduleIsInstalled('menu_items') ? 'UPDATE `{pre}menu_items` SET `uri`=REPLACE(`uri`, "users/login/", "users/index/login/") WHERE `uri` LIKE "users/login/%";' : '',
75
                $this->schemaHelper->moduleIsInstalled('menus') || $this->schemaHelper->moduleIsInstalled('menu_items') ? 'UPDATE `{pre}menu_items` SET `uri`=REPLACE(`uri`, "users/logout/", "users/index/logout/") WHERE `uri` LIKE "users/logout/%";' : '',
76
                $this->schemaHelper->moduleIsInstalled('menus') || $this->schemaHelper->moduleIsInstalled('menu_items') ? 'UPDATE `{pre}menu_items` SET `uri`=REPLACE(`uri`, "users/register/", "users/index/register/") WHERE `uri` LIKE "users/register/%";' : '',
77
                $this->schemaHelper->moduleIsInstalled('menus') || $this->schemaHelper->moduleIsInstalled('menu_items') ? 'UPDATE `{pre}menu_items` SET `uri`=REPLACE(`uri`, "users/view_profile/", "users/index/view_profile/") WHERE `uri` LIKE "users/view_profile/%";' : '',
78
            ],
79
            40 => [
80
                'ALTER TABLE `{pre}users` ADD `pwd_salt` VARCHAR(16) NOT NULL AFTER `pwd`;',
81
                'UPDATE `{pre}users` SET `pwd_salt` = SUBSTRING(`pwd`, 42), `pwd` = SUBSTRING(`pwd`, 1, 40);',
82
                'ALTER TABLE `{pre}users` ADD `remember_me_token` VARCHAR(128) NOT NULL AFTER `pwd_salt`;',
83
                'ALTER TABLE `{pre}users` CHANGE `pwd` `pwd` VARCHAR(128) NOT NULL;',
84
            ],
85
            41 => [
86
                'ALTER TABLE `{pre}users` ENGINE = InnoDB',
87
            ],
88
            42 => [
89
                'ALTER TABLE `{pre}users` CHANGE `id` `id` INT(10) UNSIGNED AUTO_INCREMENT',
90
            ],
91
            43 => [
92
                "UPDATE `{pre}acl_resources` SET `area` = 'widget' WHERE `module_id` = '{moduleId}' AND `area` = 'sidebar';",
93
            ],
94
            44 => [
95
                "INSERT INTO `{pre}acl_resources` (`id`, `module_id`, `area`, `controller`, `page`, `params`, `privilege_id`) VALUES('', '{moduleId}', 'widget', 'index', 'hash', '', 1);",
96
            ],
97
            45 => [
98
                'ALTER TABLE `{pre}users` DROP COLUMN `draft`;',
99
            ],
100
            46 => [
101
                'ALTER TABLE `{pre}users` DROP COLUMN `entries`;',
102
                "DELETE FROM `{pre}settings` WHERE `module_id` = {moduleId} AND `name` = 'entries_override';",
103
            ],
104
            47 => [
105
                'ALTER TABLE `{pre}users` DROP COLUMN `date_format_long`;',
106
                'ALTER TABLE `{pre}users` DROP COLUMN `date_format_short`;',
107
                'ALTER TABLE `{pre}users` DROP COLUMN `time_zone`;',
108
                'ALTER TABLE `{pre}users` DROP COLUMN `language`;',
109
                "DELETE FROM `{pre}settings` WHERE `module_id` = {moduleId} AND `name` = 'language_override';",
110
            ],
111
            48 => [
112
                'ALTER TABLE `{pre}users` ADD UNIQUE KEY `nickname` (`nickname`);',
113
                'ALTER TABLE `{pre}users` ADD UNIQUE KEY `mail` (`mail`);',
114
            ],
115
            49 => [
116
                'ALTER TABLE `{pre}users` MODIFY COLUMN `nickname` VARCHAR(30) {charset} NOT NULL;',
117
                'ALTER TABLE `{pre}users` MODIFY COLUMN `pwd` VARCHAR(128) {charset} NOT NULL;',
118
                'ALTER TABLE `{pre}users` MODIFY COLUMN `pwd_salt` VARCHAR(16) {charset} NOT NULL;',
119
                'ALTER TABLE `{pre}users` MODIFY COLUMN `remember_me_token` VARCHAR(128) {charset} NOT NULL;',
120
                'ALTER TABLE `{pre}users` MODIFY COLUMN `realname` VARCHAR(80) {charset} NOT NULL;',
121
                'ALTER TABLE `{pre}users` MODIFY COLUMN `birthday` VARCHAR(10) {charset} NOT NULL;',
122
                'ALTER TABLE `{pre}users` MODIFY COLUMN `mail` VARCHAR(120) {charset} NOT NULL;',
123
                'ALTER TABLE `{pre}users` MODIFY COLUMN `website` VARCHAR(120) {charset} NOT NULL;',
124
                'ALTER TABLE `{pre}users` MODIFY COLUMN `icq` VARCHAR(11) {charset} NOT NULL;',
125
                'ALTER TABLE `{pre}users` MODIFY COLUMN `skype` VARCHAR(30) {charset} NOT NULL;',
126
                'ALTER TABLE `{pre}users` MODIFY COLUMN `street` VARCHAR(120) {charset} NOT NULL;',
127
                'ALTER TABLE `{pre}users` MODIFY COLUMN `house_number` VARCHAR(5) {charset} NOT NULL;',
128
                'ALTER TABLE `{pre}users` MODIFY COLUMN `zip` VARCHAR(6) {charset} NOT NULL;',
129
                'ALTER TABLE `{pre}users` MODIFY COLUMN `city` VARCHAR(120) {charset} NOT NULL;',
130
                'ALTER TABLE `{pre}users` MODIFY COLUMN `country` CHAR(2) {charset} NOT NULL;',
131
                'ALTER TABLE `{pre}users` CONVERT TO {charset};',
132
            ],
133
        ];
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     *
139
     * @return array
140
     */
141
    public function renameModule()
142
    {
143
        return [];
144
    }
145
}
146