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 |
||
| 3 | |||
| 4 | use SymphonyCms\Installer\Lib\Migration; |
||
| 5 | use Symphony; |
||
| 6 | use Exception; |
||
| 7 | |||
| 8 | class migration_234 extends Migration |
||
| 9 | { |
||
| 10 | public static function getVersion() |
||
| 14 | |||
| 15 | public static function getReleaseNotes() |
||
| 19 | |||
| 20 | public static function upgrade() |
||
| 21 | { |
||
| 22 | View Code Duplication | if (version_compare(self::$existing_version, '2.3.4beta1', '<=')) { |
|
| 23 | // Detect mod_rewrite #1808 |
||
| 24 | try { |
||
| 25 | $htaccess = file_get_contents(DOCROOT . '/.htaccess'); |
||
| 26 | |||
| 27 | if ($htaccess !== false && !preg_match('/SetEnv HTTP_MOD_REWRITE No/', $htaccess)) { |
||
| 28 | $rewrite = ' |
||
| 29 | <IfModule !mod_rewrite.c> |
||
| 30 | SetEnv HTTP_MOD_REWRITE No |
||
| 31 | </IfModule> |
||
| 32 | |||
| 33 | <IfModule mod_rewrite.c>'; |
||
| 34 | |||
| 35 | $htaccess = str_replace('<IfModule mod_rewrite.c>', $rewrite, $htaccess); |
||
| 36 | file_put_contents(DOCROOT . '/.htaccess', $htaccess); |
||
| 37 | } |
||
| 38 | } catch (Exception $ex) { |
||
| 39 | } |
||
| 40 | |||
| 41 | // Extend token field to enable more secure tokens |
||
| 42 | try { |
||
| 43 | Symphony::Database()->query('ALTER TABLE `tbl_forgotpass` CHANGE `token` `token` VARCHAR(16);'); |
||
| 44 | } catch (Exception $ex) { |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | if (version_compare(self::$existing_version, '2.3.4beta2', '<=')) { |
||
| 49 | // Extend session_id field for default Suhosin installs |
||
| 50 | try { |
||
| 51 | Symphony::Database()->query('ALTER TABLE `tbl_sessions` CHANGE `session` `session` VARCHAR(128);'); |
||
| 52 | } catch (Exception $ex) { |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 60 |