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_231   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 83
Duplicated Lines 40.96 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 34
loc 83
rs 10
wmc 14
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getVersion() 0 4 1
A getReleaseNotes() 0 4 1
F upgrade() 34 70 12

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace SymphonyCms\Installer\Migrations;
3
4
use SymphonyCms\Installer\Lib\Migration;
5
use Symphony;
6
use Exception;
7
8
class migration_231 extends Migration
9
{
10
    public static function getVersion()
11
    {
12
        return '2.3.1';
13
    }
14
15
    public static function getReleaseNotes()
16
    {
17
        return 'http://getsymphony.com/download/releases/version/2.3.1/';
18
    }
19
20
    public static function upgrade()
21
    {
22
        // 2.3.1dev
23
        if (version_compare(self::$existing_version, '2.3.1dev', '<=')) {
24
            // Remove unused setting from the Author field
25
            $author_table = 'tbl_fields_author';
26
            if (Symphony::Database()->tableContainsField($author_table, 'allow_author_change')) {
27
                Symphony::Database()->query("ALTER TABLE `$author_table` DROP `allow_author_change`;");
28
            }
29
30
            // Author Types [#1219]
31
            if (!Symphony::Database()->tableContainsField($author_table, 'author_types')) {
32
                Symphony::Database()->query("ALTER TABLE `$author_table` ADD `author_types` VARCHAR(255) DEFAULT NULL;");
33
            }
34
35
            // Entries Modification Date [#983]
36 View Code Duplication
            if (!Symphony::Database()->tableContainsField('tbl_entries', 'modification_date')) {
37
                Symphony::Database()->query("ALTER TABLE `tbl_entries` ADD `modification_date` DATETIME NOT NULL;");
38
                Symphony::Database()->query("ALTER TABLE `tbl_entries` ADD KEY `modification_date` (`modification_date`)");
39
                Symphony::Database()->query("UPDATE `tbl_entries` SET modification_date = creation_date;");
40
            }
41
42 View Code Duplication
            if (!Symphony::Database()->tableContainsField('tbl_entries', 'modification_date_gmt')) {
43
                Symphony::Database()->query("ALTER TABLE `tbl_entries` ADD `modification_date_gmt` DATETIME NOT NULL;");
44
                Symphony::Database()->query("ALTER TABLE `tbl_entries` ADD KEY `modification_date_gmt` (`modification_date_gmt`)");
45
                Symphony::Database()->query("UPDATE `tbl_entries` SET modification_date_gmt = creation_date_gmt;");
46
            }
47
48
            // Cleanup #977, remove `entry_order` & `entry_order_direction` from `tbl_sections`
49
            if (Symphony::Database()->tableContainsField('tbl_sections', 'entry_order')) {
50
                Symphony::Database()->query("ALTER TABLE `tbl_sections` DROP `entry_order`;");
51
            }
52
53
            if (Symphony::Database()->tableContainsField('tbl_sections', 'entry_order_direction')) {
54
                Symphony::Database()->query("ALTER TABLE `tbl_sections` DROP `entry_order_direction`;");
55
            }
56
        }
57
58 View Code Duplication
        if (version_compare(self::$existing_version, '2.3.1RC1', '<=')) {
59
            // Add Security Rules from 2.2 to .htaccess
60
            try {
61
                $htaccess = file_get_contents(DOCROOT . '/.htaccess');
62
63
                if ($htaccess !== false && preg_match('/### SECURITY - Protect crucial files/', $htaccess)) {
64
                    $security = '
65
        ### SECURITY - Protect crucial files
66
        RewriteRule ^manifest/(.*)$ - [F]
67
        RewriteRule ^workspace/(pages|utilities)/(.*)\.xsl$ - [F]
68
        RewriteRule ^(.*)\.sql$ - [F]
69
        RewriteRule (^|/)\. - [F]
70
71
        ### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"';
72
73
                    $htaccess = str_replace(
74
                        '### SECURITY - Protect crucial files.*### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"',
75
                        $security,
76
                        $htaccess
77
                    );
78
                    file_put_contents(DOCROOT . '/.htaccess', $htaccess);
79
                }
80
            } catch (Exception $ex) {
81
            }
82
83
            // Increase length of password field to accomodate longer hashes
84
            Symphony::Database()->query("ALTER TABLE `tbl_authors` CHANGE `password` `password` VARCHAR( 150 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL");
85
        }
86
87
        // Update the version information
88
        return parent::upgrade();
89
    }
90
}
91