Conditions | 6 |
Paths | 18 |
Total Lines | 67 |
Code Lines | 31 |
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 |
||
39 | function xoops_module_update_wgevents($module, $prev_version = null) |
||
40 | { |
||
41 | $moduleDirName = $module->dirname(); |
||
42 | |||
43 | //check preload folder and remove replace index.php by index.html if exist |
||
44 | if (\is_file(\XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/preloads/index.php')) { |
||
45 | //delete olf file |
||
46 | \unlink(\XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/preloads/index.php'); |
||
47 | //create html file |
||
48 | $myfile = \fopen(\XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/preloads/index.html', 'wb'); |
||
49 | \fwrite($myfile, '<script>history.go(-1);</script>'); |
||
50 | \fclose($myfile); |
||
51 | } |
||
52 | |||
53 | //wgevents_check_db($module); |
||
54 | |||
55 | // update DB corresponding to sql/mysql.sql |
||
56 | $configurator = new Configurator(); |
||
57 | $migrate = new Migrate($configurator); |
||
58 | //$migrate->saveCurrentSchema(); |
||
59 | |||
60 | $fileSql = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/mysql.sql'; |
||
61 | // ToDo: add function setDefinitionFile to .\class\libraries\vendor\xoops\xmf\src\Database\Migrate.php |
||
62 | // Todo: once we are using setDefinitionFile this part has to be adapted |
||
63 | //$fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/update_' . $moduleDirName . '_migrate.yml'; |
||
64 | //try { |
||
65 | //$migrate->setDefinitionFile('update_' . $moduleDirName); |
||
66 | //} catch (\Exception $e) { |
||
67 | // as long as this is not done default file has to be created |
||
68 | $moduleVersionOld = $module->getInfo('version'); |
||
69 | $moduleVersionNew = \str_replace(['.', '-'], '_', $moduleVersionOld); |
||
70 | $fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . "/sql/{$moduleDirName}_{$moduleVersionNew}_migrate.yml"; |
||
71 | //} |
||
72 | |||
73 | // create a schema file based on sql/mysql.sql |
||
74 | $migratehelper = new MigrateHelper($fileSql, $fileYaml); |
||
75 | if (!$migratehelper->createSchemaFromSqlfile()) { |
||
76 | \xoops_error('Error: creation schema file failed!'); |
||
77 | return false; |
||
78 | } |
||
79 | |||
80 | //create copy for XOOPS 2.5.11 Beta 1 and older versions |
||
81 | $fileYaml2 = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . "/sql/{$moduleDirName}_{$moduleVersionOld}_migrate.yml"; |
||
82 | \copy($fileYaml, $fileYaml2); |
||
83 | |||
84 | // run standard procedure for db migration |
||
85 | $migrate->getTargetDefinitions(); |
||
86 | $migrate->synchronizeSchema(); |
||
87 | |||
88 | //check upload directory |
||
89 | require_once __DIR__ . '/install.php'; |
||
90 | xoops_module_install_wgevents($module); |
||
91 | |||
92 | $moduleVersion = (int)\str_replace(['.', '-'], '', $module->getInfo('version')); |
||
93 | if ($moduleVersion < 104) { |
||
94 | wgevents_update_fee($module); |
||
95 | } |
||
96 | if ($moduleVersion < 105) { |
||
97 | wgevents_update_subcats($module); |
||
98 | } |
||
99 | |||
100 | $errors = $module->getErrors(); |
||
101 | if (!empty($errors)) { |
||
102 | \print_r($errors); |
||
103 | } |
||
104 | |||
105 | return true; |
||
106 | |||
204 |