| Conditions | 8 |
| Paths | 10 |
| Total Lines | 59 |
| Code Lines | 32 |
| Lines | 14 |
| Ratio | 23.73 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 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 |