|
1
|
|
|
<?php declare(strict_types=1); |
|
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
|
|
|
/** |
|
13
|
|
|
* Wgfilemanager module for xoops |
|
14
|
|
|
* |
|
15
|
|
|
* @param mixed $module |
|
16
|
|
|
* @param null|mixed $prev_version |
|
17
|
|
|
* @author Wedega - Email:<[email protected]> - Website:<https://wedega.com> |
|
18
|
|
|
* @copyright module for xoops |
|
19
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
use XoopsModules\Wgfilemanager\Common\ { |
|
23
|
|
|
Configurator, |
|
24
|
|
|
Migrate, |
|
25
|
|
|
MigrateHelper |
|
26
|
|
|
}; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param $module |
|
30
|
|
|
* @param null $prev_version |
|
|
|
|
|
|
31
|
|
|
* |
|
32
|
|
|
* @return bool|null |
|
33
|
|
|
*/ |
|
34
|
|
|
function xoops_module_update_wgfilemanager($module, $prev_version = null) |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$ret = null; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$moduleDirName = $module->dirname(); |
|
39
|
|
|
|
|
40
|
|
|
$ret = wgfilemanager_check_db($module); |
|
41
|
|
|
|
|
42
|
|
|
//check upload directory |
|
43
|
|
|
require_once __DIR__ . '/install.php'; |
|
44
|
|
|
$ret = xoops_module_install_wgfilemanager($module); |
|
45
|
|
|
// update DB corresponding to sql/mysql.sql |
|
46
|
|
|
$configurator = new Configurator(); |
|
47
|
|
|
$migrate = new Migrate($configurator); |
|
48
|
|
|
|
|
49
|
|
|
$fileSql = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/mysql.sql'; |
|
50
|
|
|
// ToDo: add function setDefinitionFile to .\class\libraries\vendor\xoops\xmf\src\Database\Migrate.php |
|
51
|
|
|
// Todo: once we are using setDefinitionFile this part has to be adapted |
|
52
|
|
|
//$fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/update_' . $moduleDirName . '_migrate.yml'; |
|
53
|
|
|
//try { |
|
54
|
|
|
//$migrate->setDefinitionFile('update_' . $moduleDirName); |
|
55
|
|
|
//} catch (\Exception $e) { |
|
56
|
|
|
// as long as this is not done default file has to be created |
|
57
|
|
|
$moduleVersionOld = $module->getInfo('version'); |
|
58
|
|
|
$moduleVersionNew = \str_replace(['.', '-'], '_', $moduleVersionOld); |
|
59
|
|
|
$fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . "/sql/{$moduleDirName}_{$moduleVersionNew}_migrate.yml"; |
|
60
|
|
|
//} |
|
61
|
|
|
|
|
62
|
|
|
// create a schema file based on sql/mysql.sql |
|
63
|
|
|
$migratehelper = new MigrateHelper($fileSql, $fileYaml); |
|
64
|
|
|
if (!$migratehelper->createSchemaFromSqlfile()) { |
|
65
|
|
|
\xoops_error('Error: creation schema file failed!'); |
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// run standard procedure for db migration |
|
70
|
|
|
$migrate->getTargetDefinitions(); |
|
71
|
|
|
$migrate->synchronizeSchema(); |
|
72
|
|
|
|
|
73
|
|
|
$errors = $module->getErrors(); |
|
74
|
|
|
if (!empty($errors)) { |
|
75
|
|
|
\print_r($errors); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $ret; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param $module |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
function wgfilemanager_check_db($module) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
//insert here code for database check |
|
89
|
|
|
|
|
90
|
|
|
/* |
|
91
|
|
|
// Example: update table (add new field) |
|
92
|
|
|
$ret = true; |
|
93
|
|
|
$table = $GLOBALS['xoopsDB']->prefix('wgfilemanager_images'); |
|
94
|
|
|
$field = 'img_exif'; |
|
95
|
|
|
$check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
|
96
|
|
|
$numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
|
97
|
|
|
if (!$numRows) { |
|
98
|
|
|
$sql = "ALTER TABLE `$table` ADD `$field` TEXT NULL AFTER `img_state`;"; |
|
99
|
|
|
if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
|
100
|
|
|
xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
|
101
|
|
|
$module->setErrors("Error when adding '$field' to table '$table'."); |
|
102
|
|
|
$ret = false; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// Example: create new table |
|
107
|
|
|
$table = $GLOBALS['xoopsDB']->prefix('wgfilemanager_categories'); |
|
108
|
|
|
$check = $GLOBALS['xoopsDB']->queryF("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='$table'"); |
|
109
|
|
|
$numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
|
110
|
|
|
if (!$numRows) { |
|
111
|
|
|
// create new table 'wgfilemanager_categories' |
|
112
|
|
|
$sql = "CREATE TABLE `$table` ( |
|
113
|
|
|
`cat_id` INT(8) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
114
|
|
|
`cat_text` VARCHAR(100) NOT NULL DEFAULT '', |
|
115
|
|
|
`cat_date` INT(8) NOT NULL DEFAULT '0', |
|
116
|
|
|
`cat_submitter` INT(8) NOT NULL DEFAULT '0', |
|
117
|
|
|
PRIMARY KEY (`cat_id`) |
|
118
|
|
|
) ENGINE=InnoDB;"; |
|
119
|
|
|
if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
|
120
|
|
|
xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
|
121
|
|
|
$module->setErrors("Error when creating table '$table'."); |
|
122
|
|
|
$ret = false; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
return $ret; |
|
126
|
|
|
*/ |
|
127
|
|
|
return true; |
|
128
|
|
|
} |
|
129
|
|
|
|