GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — integration (#2604)
by Brendan
05:28
created

migration_221::upgrade()   F

Complexity

Conditions 15
Paths 1540

Size

Total Lines 99
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 15
eloc 49
c 1
b 1
f 0
nc 1540
nop 0
dl 0
loc 99
rs 2

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
namespace SymphonyCms\Installer\Migrations;
3
4
use SymphonyCms\Installer\Lib\Migration;
5
use Symphony;
6
use Exception;
7
8
class migration_221 extends Migration
9
{
10
    public static function getVersion()
11
    {
12
        return '2.2.1';
13
    }
14
15
    public static function getReleaseNotes()
16
    {
17
        return 'http://getsymphony.com/download/releases/version/2.2.1/';
18
    }
19
20
    public static function upgrade()
21
    {
22
        // 2.2.1 Beta 1
23
        if (version_compare(self::$existing_version, '2.2.1 Beta 1', '<=')) {
24
            Symphony::Configuration()->set('version', '2.2.1 Beta 1', 'symphony');
25
            try {
26
                Symphony::Database()->query('CREATE INDEX `session_expires` ON `tbl_sessions` (`session_expires`)');
27
                Symphony::Database()->query('OPTIMIZE TABLE `tbl_sessions`');
28
            } catch (Exception $ex) {
29
            }
30
            Symphony::Configuration()->write();
31
        }
32
33
        // 2.2.1 Beta 2
34
        if (version_compare(self::$existing_version, '2.2.1 Beta 2', '<=')) {
35
            Symphony::Configuration()->set('version', '2.2.1 Beta 2', 'symphony');
36
37
            // Add Security Rules from 2.2 to .htaccess
38
            try {
39
                $htaccess = file_get_contents(DOCROOT . '/.htaccess');
40
41
                if ($htaccess !== false && !preg_match('/### SECURITY - Protect crucial files/', $htaccess)) {
42
                    $security = '
43
        ### SECURITY - Protect crucial files
44
        RewriteRule ^manifest/(.*)$ - [F]
45
        RewriteRule ^workspace/(pages|utilities)/(.*)\.xsl$ - [F]
46
        RewriteRule ^(.*)\.sql$ - [F]
47
        RewriteRule (^|/)\. - [F]
48
49
        ### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"';
50
51
                    $htaccess = str_replace(
52
                        '### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"',
53
                        $security,
54
                        $htaccess
55
                    );
56
                    file_put_contents(DOCROOT . '/.htaccess', $htaccess);
57
                }
58
            } catch (Exception $ex) {
59
            }
60
61
            // Add correct index to the `tbl_cache`
62
            try {
63
                Symphony::Database()->query('ALTER TABLE `tbl_cache` DROP INDEX `creation`');
64
                Symphony::Database()->query('CREATE INDEX `expiry` ON `tbl_cache` (`expiry`)');
65
                Symphony::Database()->query('OPTIMIZE TABLE `tbl_cache`');
66
            } catch (Exception $ex) {
67
            }
68
69
            // Remove Hide Association field from Select Data tables
70
            $select_tables = Symphony::Database()->fetchCol(
71
                "field_id",
72
                "SELECT `field_id` FROM `tbl_fields_select`"
73
            );
74
75
            if (is_array($select_tables) && !empty($select_tables)) {
76
                foreach ($select_tables as $field) {
77
                    if (Symphony::Database()->tableContainsField(
78
                        'tbl_entries_data_' . $field,
79
                        'show_association'
80
                    )
81
                    ) {
82
                        Symphony::Database()->query(sprintf(
83
                            "ALTER TABLE `tbl_entries_data_%d` DROP `show_association`",
84
                            $field
85
                        ));
86
                    }
87
                }
88
            }
89
90
            // Update Select table to include the sorting option
91
            if (!Symphony::Database()->tableContainsField('tbl_fields_select', 'sort_options')) {
92
                Symphony::Database()->query('ALTER TABLE `tbl_fields_select` ADD `sort_options` ENUM( "yes", "no" ) COLLATE utf8_unicode_ci NOT NULL DEFAULT "no"');
93
            }
94
95
            // Remove the 'driver' from the Config
96
            Symphony::Configuration()->remove('driver', 'database');
97
            Symphony::Configuration()->write();
98
99
            // Remove the NOT NULL from the Author tables
100
            try {
101
                $author = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_author`");
102
103
                foreach ($author as $id) {
104
                    $table = '`tbl_entries_data_' . $id . '`';
105
106
                    Symphony::Database()->query(
107
                        'ALTER TABLE ' . $table . ' CHANGE `author_id` `author_id` INT(11) UNSIGNED NULL'
108
                    );
109
                }
110
            } catch (Exception $ex) {
111
            }
112
113
            Symphony::Configuration()->write();
114
        }
115
116
        // Update the version information
117
        return parent::upgrade();
118
    }
119
120
    public static function postUpdateNotes()
121
    {
122
        return array(
123
            __(
124
                'Version %s introduces some improvements and fixes to Static XML Datasources. If you have any Static XML Datasources in your installation, please be sure to re-save them through the Data Source Editor to prevent unexpected results.',
125
                array('<code>2.2.1</code>')
126
            )
127
        );
128
    }
129
}
130