Conditions | 15 |
Paths | 1540 |
Total Lines | 88 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 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, $htaccess); |
||
47 | file_put_contents(DOCROOT . '/.htaccess', $htaccess); |
||
48 | } |
||
49 | } catch (Exception $ex) { |
||
50 | } |
||
51 | |||
52 | // Add correct index to the `tbl_cache` |
||
53 | try { |
||
54 | Symphony::Database()->query('ALTER TABLE `tbl_cache` DROP INDEX `creation`'); |
||
55 | Symphony::Database()->query('CREATE INDEX `expiry` ON `tbl_cache` (`expiry`)'); |
||
56 | Symphony::Database()->query('OPTIMIZE TABLE `tbl_cache`'); |
||
57 | } catch (Exception $ex) { |
||
58 | } |
||
59 | |||
60 | // Remove Hide Association field from Select Data tables |
||
61 | $select_tables = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_select`"); |
||
62 | |||
63 | if (is_array($select_tables) && !empty($select_tables)) { |
||
64 | foreach ($select_tables as $field) { |
||
65 | if (Symphony::Database()->tableContainsField('tbl_entries_data_' . $field, 'show_association')) { |
||
66 | Symphony::Database()->query(sprintf( |
||
67 | "ALTER TABLE `tbl_entries_data_%d` DROP `show_association`", |
||
68 | $field |
||
69 | )); |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | |||
74 | // Update Select table to include the sorting option |
||
75 | if (!Symphony::Database()->tableContainsField('tbl_fields_select', 'sort_options')) { |
||
76 | Symphony::Database()->query('ALTER TABLE `tbl_fields_select` ADD `sort_options` ENUM( "yes", "no" ) COLLATE utf8_unicode_ci NOT NULL DEFAULT "no"'); |
||
77 | } |
||
78 | |||
79 | // Remove the 'driver' from the Config |
||
80 | Symphony::Configuration()->remove('driver', 'database'); |
||
81 | Symphony::Configuration()->write(); |
||
82 | |||
83 | // Remove the NOT NULL from the Author tables |
||
84 | try { |
||
85 | $author = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_author`"); |
||
86 | |||
87 | foreach ($author as $id) { |
||
88 | $table = '`tbl_entries_data_' . $id . '`'; |
||
89 | |||
90 | Symphony::Database()->query( |
||
91 | 'ALTER TABLE ' . $table . ' CHANGE `author_id` `author_id` int(11) unsigned NULL' |
||
92 | ); |
||
93 | } |
||
94 | } catch (Exception $ex) { |
||
95 | } |
||
96 | |||
97 | Symphony::Configuration()->write(); |
||
98 | } |
||
99 | |||
100 | // Update the version information |
||
101 | return parent::upgrade(); |
||
102 | } |
||
103 | |||
111 |