1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
/** |
12
|
|
|
* wgSitenotice module for xoops |
13
|
|
|
* |
14
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
15
|
|
|
* @license GPL 2.0 or later |
16
|
|
|
* @package wgsitenotice |
17
|
|
|
* @since 1.0 |
18
|
|
|
* @min_xoops 2.5.11 |
19
|
|
|
* @author Goffy (xoops.wedega.com) - Email:<[email protected]> - Website:<https://xoops.wedega.com> |
20
|
|
|
*/ |
21
|
|
|
/** |
22
|
|
|
* @param $module |
23
|
|
|
* @param null $prev_version |
24
|
|
|
* |
25
|
|
|
* @return bool|null |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
use XoopsModules\Wgsitenotice\Common\ { |
29
|
|
|
Configurator, |
30
|
|
|
Migrate, |
31
|
|
|
MigrateHelper |
32
|
|
|
}; |
33
|
|
|
|
34
|
|
|
function xoops_module_update_wgsitenotice($module, $prev_version = null) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
$moduleDirName = $module->dirname(); |
38
|
|
|
|
39
|
|
|
$configurator = new Configurator(); |
40
|
|
|
$migrate = new Migrate($configurator); |
41
|
|
|
|
42
|
|
|
$fileSql = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/mysql.sql'; |
|
|
|
|
43
|
|
|
// ToDo: add function setDefinitionFile to .\class\libraries\vendor\xoops\xmf\src\Database\Migrate.php |
44
|
|
|
// Todo: once we are using setDefinitionFile this part has to be adapted |
45
|
|
|
//$fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/update_' . $moduleDirName . '_migrate.yml'; |
46
|
|
|
//try { |
47
|
|
|
//$migrate->setDefinitionFile('update_' . $moduleDirName); |
48
|
|
|
//} catch (\Exception $e) { |
49
|
|
|
// as long as this is not done default file has to be created |
50
|
|
|
$moduleVersionOld = $module->getInfo('version'); |
51
|
|
|
$moduleVersionNew = \str_replace(['.', '-'], '_', $moduleVersionOld); |
52
|
|
|
$fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . "/sql/{$moduleDirName}_{$moduleVersionNew}_migrate.yml"; |
53
|
|
|
//} |
54
|
|
|
|
55
|
|
|
// create a schema file based on sql/mysql.sql |
56
|
|
|
$migratehelper = new MigrateHelper($fileSql, $fileYaml); |
57
|
|
|
if (!$migratehelper->createSchemaFromSqlfile()) { |
58
|
|
|
\xoops_error('Error: creation schema file failed!'); |
|
|
|
|
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
//create copy for XOOPS 2.5.11 Beta 1 and older versions |
63
|
|
|
$fileYaml2 = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . "/sql/{$moduleDirName}_{$moduleVersionOld}_migrate.yml"; |
64
|
|
|
\copy($fileYaml, $fileYaml2); |
65
|
|
|
|
66
|
|
|
// run standard procedure for db migration |
67
|
|
|
$migrate->getTargetDefinitions(); |
68
|
|
|
$migrate->synchronizeSchema(); |
69
|
|
|
|
70
|
|
|
//check upload directory |
71
|
|
|
require_once __DIR__ . '/install.php'; |
72
|
|
|
$ret = xoops_module_install_wgsitenotice($module); |
73
|
|
|
$errors = $module->getErrors(); |
74
|
|
|
foreach ($errors as $error) { |
75
|
|
|
xoops_error($error); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $ret; |
79
|
|
|
} |
80
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.