| Conditions | 15 |
| Paths | 1540 |
| Total Lines | 92 |
| Code Lines | 45 |
| 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 |
||
| 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 | |||
| 121 |