Conditions | 15 |
Paths | 1540 |
Total Lines | 92 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
15 | public static function upgrade() |
||
16 | { |
||
17 | // 2.2.1 Beta 1 |
||
18 | if (version_compare(self::$existing_version, '2.2.1 Beta 1', '<=')) { |
||
19 | Symphony::Configuration()->set('version', '2.2.1 Beta 1', 'symphony'); |
||
20 | try { |
||
21 | Symphony::Database()->query('CREATE INDEX `session_expires` ON `tbl_sessions` (`session_expires`)'); |
||
22 | Symphony::Database()->query('OPTIMIZE TABLE `tbl_sessions`'); |
||
23 | } catch (Exception $ex) { |
||
24 | } |
||
25 | Symphony::Configuration()->write(); |
||
26 | } |
||
27 | |||
28 | // 2.2.1 Beta 2 |
||
29 | if (version_compare(self::$existing_version, '2.2.1 Beta 2', '<=')) { |
||
30 | Symphony::Configuration()->set('version', '2.2.1 Beta 2', 'symphony'); |
||
31 | |||
32 | // Add Security Rules from 2.2 to .htaccess |
||
33 | try { |
||
34 | $htaccess = file_get_contents(DOCROOT . '/.htaccess'); |
||
35 | |||
36 | if ($htaccess !== false && !preg_match('/### SECURITY - Protect crucial files/', $htaccess)) { |
||
37 | $security = ' |
||
38 | ### SECURITY - Protect crucial files |
||
39 | RewriteRule ^manifest/(.*)$ - [F] |
||
40 | RewriteRule ^workspace/(pages|utilities)/(.*)\.xsl$ - [F] |
||
41 | RewriteRule ^(.*)\.sql$ - [F] |
||
42 | RewriteRule (^|/)\. - [F] |
||
43 | |||
44 | ### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"'; |
||
45 | |||
46 | $htaccess = str_replace('### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"', $security, |
||
47 | $htaccess); |
||
48 | file_put_contents(DOCROOT . '/.htaccess', $htaccess); |
||
49 | } |
||
50 | } catch (Exception $ex) { |
||
51 | } |
||
52 | |||
53 | // Add correct index to the `tbl_cache` |
||
54 | try { |
||
55 | Symphony::Database()->query('ALTER TABLE `tbl_cache` DROP INDEX `creation`'); |
||
56 | Symphony::Database()->query('CREATE INDEX `expiry` ON `tbl_cache` (`expiry`)'); |
||
57 | Symphony::Database()->query('OPTIMIZE TABLE `tbl_cache`'); |
||
58 | } catch (Exception $ex) { |
||
59 | } |
||
60 | |||
61 | // Remove Hide Association field from Select Data tables |
||
62 | $select_tables = Symphony::Database()->fetchCol("field_id", |
||
63 | "SELECT `field_id` FROM `tbl_fields_select`"); |
||
64 | |||
65 | if (is_array($select_tables) && !empty($select_tables)) { |
||
66 | foreach ($select_tables as $field) { |
||
67 | if (Symphony::Database()->tableContainsField('tbl_entries_data_' . $field, |
||
68 | 'show_association') |
||
69 | ) { |
||
70 | Symphony::Database()->query(sprintf( |
||
71 | "ALTER TABLE `tbl_entries_data_%d` DROP `show_association`", |
||
72 | $field |
||
73 | )); |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | |||
78 | // Update Select table to include the sorting option |
||
79 | if (!Symphony::Database()->tableContainsField('tbl_fields_select', 'sort_options')) { |
||
80 | Symphony::Database()->query('ALTER TABLE `tbl_fields_select` ADD `sort_options` ENUM( "yes", "no" ) COLLATE utf8_unicode_ci NOT NULL DEFAULT "no"'); |
||
81 | } |
||
82 | |||
83 | // Remove the 'driver' from the Config |
||
84 | Symphony::Configuration()->remove('driver', 'database'); |
||
85 | Symphony::Configuration()->write(); |
||
86 | |||
87 | // Remove the NOT NULL from the Author tables |
||
88 | try { |
||
89 | $author = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_author`"); |
||
90 | |||
91 | foreach ($author as $id) { |
||
92 | $table = '`tbl_entries_data_' . $id . '`'; |
||
93 | |||
94 | Symphony::Database()->query( |
||
95 | 'ALTER TABLE ' . $table . ' CHANGE `author_id` `author_id` INT(11) UNSIGNED NULL' |
||
96 | ); |
||
97 | } |
||
98 | } catch (Exception $ex) { |
||
99 | } |
||
100 | |||
101 | Symphony::Configuration()->write(); |
||
102 | } |
||
103 | |||
104 | // Update the version information |
||
105 | return parent::upgrade(); |
||
106 | } |
||
107 | |||
116 |