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

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 19.44 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 14
loc 72
rs 10
wmc 10
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getVersion() 0 4 1
A getReleaseNotes() 0 4 1
B upgrade() 14 59 8

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
3
namespace SymphonyCms\Installer\Migrations;
4
5
use SymphonyCms\Installer\Lib\Migration;
6
use Symphony;
7
use Exception;
8
9
class migration_220 extends Migration
10
{
11
    public static function getVersion()
12
    {
13
        return '2.2';
14
    }
15
16
    public static function getReleaseNotes()
17
    {
18
        return 'http://getsymphony.com/download/releases/version/2.2/';
19
    }
20
21
    public static function upgrade()
22
    {
23
        // 2.2.0dev
24
        if (version_compare(self::$existing_version, '2.2.0dev', '<=')) {
25
            Symphony::Configuration()->set('version', '2.2dev', 'symphony');
26
            if (Symphony::Database()->tableContainsField('tbl_sections_association', 'cascading_deletion')) {
27
                Symphony::Database()->query(
28
                    'ALTER TABLE `tbl_sections_association` CHANGE  `cascading_deletion` `hide_association` ENUM("yes","no") COLLATE utf8_unicode_ci NOT NULL DEFAULT "no";'
29
                );
30
            }
31
32
            // Update Select table to include the new association field
33
            Symphony::Database()->query('ALTER TABLE `tbl_fields_select` ADD `show_association` ENUM( "yes", "no" ) COLLATE utf8_unicode_ci NOT NULL DEFAULT "yes"');
34
35
            if (Symphony::Database()->tableContainsField('tbl_authors', 'default_section')) {
36
                // Allow Authors to be set to any area in the backend.
37
                Symphony::Database()->query(
38
                    'ALTER TABLE `tbl_authors` CHANGE `default_section` `default_area` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL;'
39
                );
40
            }
41
            Symphony::Configuration()->write();
42
        }
43
44
        // 2.2.0
45
        if (version_compare(self::$existing_version, '2.2', '<=')) {
46
            Symphony::Configuration()->set('version', '2.2', 'symphony');
47
            Symphony::Configuration()->set('datetime_separator', ' ', 'region');
48
            Symphony::Configuration()->set('strict_error_handling', 'yes', 'symphony');
49
50
            // We've added UNIQUE KEY indexes to the Author, Checkbox, Date, Input, Textarea and Upload Fields
51
            // Time to go through the entry tables and make this change as well.
52
            $author = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_author`");
53
            $checkbox = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_checkbox`");
54
            $date = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_date`");
55
            $input = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_input`");
56
            $textarea = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_textarea`");
57
            $upload = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_upload`");
58
59
            $field_ids = array_merge($author, $checkbox, $date, $input, $textarea, $upload);
60
61 View Code Duplication
            foreach ($field_ids as $id) {
62
                $table = '`tbl_entries_data_' . $id . '`';
63
64
                try {
65
                    Symphony::Database()->query("ALTER TABLE " . $table . " DROP INDEX `entry_id`");
66
                } catch (Exception $ex) {
67
                }
68
69
                try {
70
                    Symphony::Database()->query("CREATE UNIQUE INDEX `entry_id` ON " . $table . " (`entry_id`)");
71
                    Symphony::Database()->query("OPTIMIZE TABLE " . $table);
72
                } catch (Exception $ex) {
73
                }
74
            }
75
        }
76
77
        // Update the version information
78
        return parent::upgrade();
79
    }
80
}
81