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:23
created

migration_221   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 113
rs 10
wmc 18
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getVersion() 0 4 1
A getReleaseNotes() 0 4 1
F upgrade() 0 92 15
A postUpdateNotes() 0 7 1
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('### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"', $security,
52
                            $htaccess);
53
                        file_put_contents(DOCROOT . '/.htaccess', $htaccess);
54
                    }
55
                } catch (Exception $ex) {
56
                }
57
58
                // Add correct index to the `tbl_cache`
59
                try {
60
                    Symphony::Database()->query('ALTER TABLE `tbl_cache` DROP INDEX `creation`');
61
                    Symphony::Database()->query('CREATE INDEX `expiry` ON `tbl_cache` (`expiry`)');
62
                    Symphony::Database()->query('OPTIMIZE TABLE `tbl_cache`');
63
                } catch (Exception $ex) {
64
                }
65
66
                // Remove Hide Association field from Select Data tables
67
                $select_tables = Symphony::Database()->fetchCol("field_id",
68
                    "SELECT `field_id` FROM `tbl_fields_select`");
69
70
                if (is_array($select_tables) && !empty($select_tables)) {
71
                    foreach ($select_tables as $field) {
72
                        if (Symphony::Database()->tableContainsField('tbl_entries_data_' . $field,
73
                            'show_association')
74
                        ) {
75
                            Symphony::Database()->query(sprintf(
76
                                "ALTER TABLE `tbl_entries_data_%d` DROP `show_association`",
77
                                $field
78
                            ));
79
                        }
80
                    }
81
                }
82
83
                // Update Select table to include the sorting option
84
                if (!Symphony::Database()->tableContainsField('tbl_fields_select', 'sort_options')) {
85
                    Symphony::Database()->query('ALTER TABLE `tbl_fields_select` ADD `sort_options` ENUM( "yes", "no" ) COLLATE utf8_unicode_ci NOT NULL DEFAULT "no"');
86
                }
87
88
                // Remove the 'driver' from the Config
89
                Symphony::Configuration()->remove('driver', 'database');
90
                Symphony::Configuration()->write();
91
92
                // Remove the NOT NULL from the Author tables
93
                try {
94
                    $author = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_author`");
95
96
                    foreach ($author as $id) {
97
                        $table = '`tbl_entries_data_' . $id . '`';
98
99
                        Symphony::Database()->query(
100
                            'ALTER TABLE ' . $table . ' CHANGE `author_id` `author_id` INT(11) UNSIGNED NULL'
101
                        );
102
                    }
103
                } catch (Exception $ex) {
104
                }
105
106
                Symphony::Configuration()->write();
107
            }
108
109
            // Update the version information
110
            return parent::upgrade();
111
        }
112
113
        public static function postUpdateNotes()
114
        {
115
            return array(
116
                __('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.',
117
                    array('<code>2.2.1</code>'))
118
            );
119
        }
120
    }
121