1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* **************************************************************************** |
4
|
|
|
* - A Project by Developers TEAM For Xoops - ( https://xoops.org ) |
5
|
|
|
* **************************************************************************** |
6
|
|
|
* XNEWSLETTER - MODULE FOR XOOPS |
7
|
|
|
* Copyright (c) 2007 - 2012 |
8
|
|
|
* Goffy ( wedega.com ) |
9
|
|
|
* |
10
|
|
|
* You may not change or alter any portion of this comment or credits |
11
|
|
|
* of supporting developers from this source code or any supporting |
12
|
|
|
* source code which is considered copyrighted (c) material of the |
13
|
|
|
* original comment or credit authors. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU General Public License for more details. |
19
|
|
|
* --------------------------------------------------------------------------- |
20
|
|
|
* @copyright Goffy ( wedega.com ) |
21
|
|
|
* @license GPL 2.0 |
22
|
|
|
* @package xnewsletter |
23
|
|
|
* @author Goffy ( [email protected] ) |
24
|
|
|
* |
25
|
|
|
* Version : 1 Mon 2012/11/05 14:31:32 : Exp $ |
26
|
|
|
* **************************************************************************** |
27
|
|
|
* |
28
|
|
|
* @param $xoopsModule |
29
|
|
|
* @param null $oldversion |
30
|
|
|
* |
31
|
|
|
* @return bool |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
xoops_loadLanguage('admin', 'xnewsletter'); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param \XoopsObject $xoopsModule |
38
|
|
|
* @param null $oldversion |
39
|
|
|
* @return bool |
40
|
|
|
*/ |
41
|
|
|
function xoops_module_update_xnewsletter(\XoopsObject $xoopsModule, $oldversion = null) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
if (100 == $oldversion) { |
44
|
|
|
xoops_module_update_xnewsletter_101(); |
45
|
|
|
} |
46
|
|
|
if ($oldversion < 103) { |
47
|
|
|
xoops_module_update_xnewsletter_103(); |
48
|
|
|
} |
49
|
|
|
if ($oldversion < 104) { |
50
|
|
|
xoops_module_update_xnewsletter_104(); |
51
|
|
|
} |
52
|
|
|
if ($oldversion < 130) { |
53
|
|
|
xoops_module_update_xnewsletter_130(); |
54
|
|
|
} |
55
|
|
|
if ($oldversion < 141) { |
56
|
|
|
xoops_module_update_xnewsletter_141(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
xoops_module_update_xnewsletter_subscr_actkey(); |
60
|
|
|
|
61
|
|
|
return true; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
|
|
function xoops_module_update_xnewsletter_subscr_actkey() |
68
|
|
|
{ |
69
|
|
|
global $xoopsDB; |
70
|
|
|
|
71
|
|
|
$helper = \XoopsModules\Xnewsletter\Helper::getInstance(); |
72
|
|
|
$subscrAll = $helper->getHandler('Subscr')->getAll(); |
73
|
|
View Code Duplication |
foreach ($subscrAll as $subscr_id => $subscrObj) { |
|
|
|
|
74
|
|
|
if ($subscrObj->getVar('subscr_actkey') == '') { |
75
|
|
|
$subscrObj->setVar('subscr_actkey', xoops_makepass()); |
76
|
|
|
$helper->getHandler('Subscr')->insert($subscrObj, true); |
77
|
|
|
} |
78
|
|
|
unset($subscrObj); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return true; |
82
|
|
|
} |
83
|
|
|
/** |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
|
|
function xoops_module_update_xnewsletter_141() |
87
|
|
|
{ |
88
|
|
|
global $xoopsDB; |
89
|
|
|
|
90
|
|
|
$helper = \XoopsModules\Xnewsletter\Helper::getInstance(); |
91
|
|
|
$subscrAll = $helper->getHandler('Subscr')->getAll(); |
92
|
|
View Code Duplication |
foreach ($subscrAll as $subscr_id => $subscrObj) { |
|
|
|
|
93
|
|
|
if ($subscrObj->getVar('subscr_actkey') == '') { |
94
|
|
|
$subscrObj->setVar('subscr_actkey', xoops_makepass()); |
95
|
|
|
$helper->getHandler('Subscr')->insert($subscrObj, true); |
96
|
|
|
} |
97
|
|
|
unset($subscrObj); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_letter') . '`'; |
101
|
|
|
$sql .= " ADD COLUMN `letter_templateid` int(8) NOT NULL default '1' AFTER `letter_content`;"; |
102
|
|
|
$result = $xoopsDB->queryF($sql); |
103
|
|
|
if (!$result) { |
104
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_letter' ADD 'letter_templateid'"; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_template') . '`'; |
108
|
|
|
$sql .= ' ADD UNIQUE `template_title` (`template_title`);'; |
109
|
|
|
$result = $xoopsDB->queryF($sql); |
110
|
|
|
if (!$result) { |
111
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_template' ADD 'template_type'"; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_template') . '`'; |
115
|
|
|
$sql .= " ADD COLUMN `template_type` tinyint(1) NOT NULL default '1';"; |
116
|
|
|
$result = $xoopsDB->queryF($sql); |
117
|
|
|
if (!$result) { |
118
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_template' ADD 'template_type'"; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_template') . '`'; |
122
|
|
|
$sql .= " ADD COLUMN `template_online` tinyint(1) NOT NULL default '1';"; |
123
|
|
|
$result = $xoopsDB->queryF($sql); |
124
|
|
|
if (!$result) { |
125
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_template' ADD 'template_online'"; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_protocol') . "` CHANGE `protocol_status_str_id` `protocol_status_str_id` TEXT NULL DEFAULT '';"; |
129
|
|
|
$result = $xoopsDB->queryF($sql); |
130
|
|
|
if (!$result) { |
131
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_protocol' CHANGE `protocol_status_str_id`"; |
132
|
|
|
} |
133
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_protocol') . "` CHANGE `protocol_status_vars` `protocol_status_vars` TEXT NULL DEFAULT '';"; |
134
|
|
|
$result = $xoopsDB->queryF($sql); |
135
|
|
|
if (!$result) { |
136
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_protocol' CHANGE `protocol_status_str_vars`"; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_mailinglist') . '`'; |
140
|
|
|
$sql .= " ADD COLUMN `mailinglist_system` VARCHAR(100) NOT NULL DEFAULT '',"; |
141
|
|
|
$sql .= " ADD COLUMN `mailinglist_target` VARCHAR(200) NOT NULL DEFAULT '',"; |
142
|
|
|
$sql .= " ADD COLUMN `mailinglist_pwd` VARCHAR(100) NOT NULL DEFAULT '',"; |
143
|
|
|
$sql .= " ADD COLUMN `mailinglist_notifyowner` tinyint(1) NOT NULL default '0';"; |
144
|
|
|
$result = $xoopsDB->queryF($sql); |
145
|
|
|
if (!$result) { |
146
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_mailinglist' ADD"; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return true; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return bool |
154
|
|
|
*/ |
155
|
|
|
function xoops_module_update_xnewsletter_130() |
156
|
|
|
{ |
157
|
|
|
// change module dirname to lowercase |
158
|
|
|
$path = dirname(__DIR__); |
159
|
|
|
$dirname = basename(dirname(__DIR__)); |
160
|
|
|
rename($path, mb_strtolower($dirname)); |
161
|
|
|
// update module dirname field in database to lowercase |
162
|
|
|
global $xoopsDB; |
163
|
|
|
$sql = "UPDATE `{$xoopsDB->prefix('modules')}` SET `dirname` = '" . mb_strtolower($dirname) . "'"; |
164
|
|
|
$sql .= " WHERE LOWER(`dirname`) = '" . mb_strtolower($dirname) . "';"; |
165
|
|
|
$result = $xoopsDB->queryF($sql); |
166
|
|
|
if (!$result) { |
167
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": UPDATE 'modules' SET `dirname` = '" . mb_strtolower($dirname) . "'"; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
// reverse 'mod_' prefix on tables |
171
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_accounts'); |
172
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_attachment'); |
173
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_bmh'); |
174
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_cat'); |
175
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_catsubscr'); |
176
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_import'); |
177
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_letter'); |
178
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_mailinglist'); |
179
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_protocol'); |
180
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_subscr'); |
181
|
|
|
xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_task'); |
182
|
|
|
$sql = sprintf('DROP TABLE IF EXISTS `' . $xoopsDB->prefix('xnewsletter_template') . '`'); |
|
|
|
|
183
|
|
|
|
184
|
|
|
// create 'xnewsletter_template' table |
185
|
|
|
global $xoopsDB; |
186
|
|
|
$sql = sprintf('DROP TABLE IF EXISTS `' . $xoopsDB->prefix('xnewsletter_template') . '`'); |
187
|
|
|
$result = $xoopsDB->queryF($sql); |
188
|
|
|
if (!$result) { |
189
|
|
|
echo '<br>' . _AM_XNEWSLETTER_UPGRADEFAILED . ": 'DROP TABLE 'xnewsletter_template'"; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
$sql = ' |
193
|
|
|
CREATE TABLE `' . $xoopsDB->prefix('xnewsletter_template') . "` ( |
194
|
|
|
`template_id` INT (8) NOT NULL AUTO_INCREMENT, |
195
|
|
|
`template_title` VARCHAR (100) NOT NULL DEFAULT '', |
196
|
|
|
`template_description` TEXT NOT NULL DEFAULT '', |
197
|
|
|
`template_content` TEXT NOT NULL DEFAULT '', |
198
|
|
|
`template_submitter` INT (8) NOT NULL DEFAULT '0', |
199
|
|
|
`template_created` INT (8) NOT NULL DEFAULT '0', |
200
|
|
|
PRIMARY KEY (`template_id`) |
201
|
|
|
) ENGINE=MyISAM;"; |
202
|
|
|
$result = $xoopsDB->queryF($sql); |
203
|
|
|
if (!$result) { |
204
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": CREATE TABLE 'xnewsletter_template'"; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
// add fields to 'xnewsletter_cat' table |
208
|
|
|
global $xoopsDB; |
209
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_cat') . '`'; |
210
|
|
|
$sql .= " ADD COLUMN `dohtml` tinyint(1) NOT NULL default '0',"; |
211
|
|
|
$sql .= " ADD COLUMN `dosmiley` tinyint(1) NOT NULL default '1',"; |
212
|
|
|
$sql .= " ADD COLUMN `doxcode` tinyint(1) NOT NULL default '1',"; |
213
|
|
|
$sql .= " ADD COLUMN `doimage` tinyint(1) NOT NULL default '1',"; |
214
|
|
|
$sql .= " ADD COLUMN `dobr` tinyint(1) NOT NULL default '1';"; |
215
|
|
|
$result = $xoopsDB->queryF($sql); |
216
|
|
|
if (!$result) { |
217
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_cat' ADD"; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
// add fields to 'xnewsletter_letter' table |
221
|
|
|
global $xoopsDB; |
222
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_letter') . '`'; |
223
|
|
|
$sql .= " ADD COLUMN `letter_sender` int(8) NOT NULL default '0',"; |
224
|
|
|
$sql .= " ADD COLUMN `letter_sent` int(10) NOT NULL default '0';"; |
225
|
|
|
$result = $xoopsDB->queryF($sql); |
226
|
|
|
if (!$result) { |
227
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_letter' ADD"; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
// add fields to 'xnewsletter_attachment' table |
231
|
|
|
global $xoopsDB; |
232
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_attachment') . '`'; |
233
|
|
|
$sql .= " ADD COLUMN `attachment_size` int(8) NOT NULL default '0',"; |
234
|
|
|
$sql .= " ADD COLUMN `attachment_mode` int(8) NOT NULL default '0';"; |
235
|
|
|
$result = $xoopsDB->queryF($sql); |
236
|
|
|
if (!$result) { |
237
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_attachment' ADD"; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
// update fields 'xnewsletter_attachment' table |
241
|
|
|
global $xoopsDB; |
242
|
|
|
$sql = 'UPDATE `' . $xoopsDB->prefix('xnewsletter_letter') . '`'; |
243
|
|
|
$sql .= " SET `letter_sent` = '1';"; |
244
|
|
|
$result = $xoopsDB->queryF($sql); |
245
|
|
|
if (!$result) { |
246
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_attachment' ADD"; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
// delete old html template files |
250
|
|
|
$templateDirectory = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/'; |
251
|
|
|
$template_list = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
252
|
|
|
foreach ($template_list as $k => $v) { |
253
|
|
|
$fileinfo = new \SplFileInfo($templateDirectory . $v); |
254
|
|
|
if ('html' === $fileinfo->getExtension() && 'index.html' !== $fileinfo->getFilename()) { |
255
|
|
|
if (!@unlink($templateDirectory . $v)) { |
256
|
|
|
$e = error_get_last(); |
257
|
|
|
trigger_error($e['message']); |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
// Load class XoopsFile |
262
|
|
|
xoops_load('xoopsfile'); |
263
|
|
|
|
264
|
|
|
//delete /images directory |
265
|
|
|
$imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/images/'; |
266
|
|
|
/** @var \XoopsFolderHandler $folderHandler */ |
267
|
|
|
$folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
268
|
|
|
$folderHandler->delete($imagesDirectory); |
269
|
|
|
|
270
|
|
|
//delete /templates/style.css file |
271
|
|
|
$cssFile = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/style.css'; |
272
|
|
|
/** @var \XoopsFileHandler $fileHandler */ |
273
|
|
|
$fileHandler = XoopsFile::getHandler('file', $cssFile); |
274
|
|
|
$fileHandler->delete($cssFile); |
275
|
|
|
|
276
|
|
|
//delete .html entries from the tpl table |
277
|
|
|
$sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE LOWER(`tpl_module`) = '" . mb_strtolower($dirname) . "' AND `tpl_file` LIKE '%.html%'"; |
278
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
279
|
|
|
|
280
|
|
|
return true; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @return bool |
285
|
|
|
*/ |
286
|
|
|
function xoops_module_update_xnewsletter_104() |
287
|
|
|
{ |
288
|
|
|
global $xoopsDB; |
289
|
|
|
|
290
|
|
|
$sql = sprintf('DROP TABLE IF EXISTS `' . $xoopsDB->prefix('mod_xnewsletter_task') . '`'); |
291
|
|
|
$result = $xoopsDB->queryF($sql); |
292
|
|
|
if (!$result) { |
293
|
|
|
echo '<br>' . _AM_XNEWSLETTER_UPGRADEFAILED . ": 'DROP TABLE 'mod_xnewsletter_task'"; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
$sql = sprintf('CREATE TABLE `' . $xoopsDB->prefix('mod_xnewsletter_task') . "` ( |
297
|
|
|
`task_id` INT(8) NOT NULL AUTO_INCREMENT, |
298
|
|
|
`task_letter_id` INT(8) NOT NULL DEFAULT '0', |
299
|
|
|
`task_subscr_id` INT(8) NOT NULL DEFAULT '0', |
300
|
|
|
`task_starttime` INT(8) NOT NULL DEFAULT '0', |
301
|
|
|
`task_submitter` INT(8) NOT NULL DEFAULT '0', |
302
|
|
|
`task_created` INT(8) NOT NULL DEFAULT '0', |
303
|
|
|
PRIMARY KEY (`task_id`), |
304
|
|
|
KEY `idx_task_starttime` (`task_starttime`) |
305
|
|
|
) ENGINE=MyISAM;"); |
306
|
|
|
$result = $xoopsDB->queryF($sql); |
307
|
|
|
if (!$result) { |
308
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": CREATE TABLE 'mod_xnewsletter_task'"; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
if (!@unlink(XOOPS_ROOT_PATH . '/modules/xnewsletter/include/sendletter.php')) { |
312
|
|
|
$e = error_get_last(); |
313
|
|
|
trigger_error($e['message']); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
return true; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* @return bool |
321
|
|
|
*/ |
322
|
|
|
function xoops_module_update_xnewsletter_103() |
323
|
|
|
{ |
324
|
|
|
global $xoopsDB; |
325
|
|
|
|
326
|
|
|
$sql = sprintf('DROP TABLE IF EXISTS `' . $xoopsDB->prefix('mod_xnewsletter_import') . '`'); |
327
|
|
|
$result = $xoopsDB->queryF($sql); |
328
|
|
|
if (!$result) { |
329
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": 'DROP TABLE 'mod_xnewsletter_import'"; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
$sql = sprintf('CREATE TABLE `' . $xoopsDB->prefix('mod_xnewsletter_import') . "` ( |
333
|
|
|
`import_id` INT (8) NOT NULL AUTO_INCREMENT, |
334
|
|
|
`import_email` VARCHAR (100) NOT NULL DEFAULT ' ', |
335
|
|
|
`import_firstname` VARCHAR (100) NULL DEFAULT ' ', |
336
|
|
|
`import_lastname` VARCHAR (100) NULL DEFAULT ' ', |
337
|
|
|
`import_sex` VARCHAR (100) NULL DEFAULT ' ', |
338
|
|
|
`import_cat_id` INT (8) NOT NULL DEFAULT '0', |
339
|
|
|
`import_subscr_id` INT (8) NOT NULL DEFAULT '0', |
340
|
|
|
`import_catsubscr_id` INT (8) NOT NULL DEFAULT '0', |
341
|
|
|
`import_status` TINYINT (1) NOT NULL DEFAULT '0', |
342
|
|
|
PRIMARY KEY (`import_id`), |
343
|
|
|
KEY `idx_email` (`import_email`), |
344
|
|
|
KEY `idx_subscr_id` (`import_subscr_id`), |
345
|
|
|
KEY `idx_import_status` (`import_status`) |
346
|
|
|
) ENGINE=MyISAM;"); |
347
|
|
|
$result = $xoopsDB->queryF($sql); |
348
|
|
|
if (!$result) { |
349
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": CREATE TABLE 'mod_xnewsletter_import'"; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
$sql = sprintf('ALTER TABLE `' . $xoopsDB->prefix('mod_xnewsletter_subscr') . '` ADD INDEX `idx_subscr_email` ( `subscr_email` )'); |
353
|
|
|
$result = $xoopsDB->queryF($sql); |
354
|
|
|
if (!$result) { |
355
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ': ADD INDEX `idx_subscr_email`'; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
$sql = sprintf('ALTER TABLE `' . $xoopsDB->prefix('mod_xnewsletter_catsubscr') . '` ADD UNIQUE `idx_subscription` ( `catsubscr_catid` , `catsubscr_subscrid` )'); |
359
|
|
|
$result = $xoopsDB->queryF($sql); |
360
|
|
|
if (!$result) { |
361
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ': ADD INDEX `idx_subscription`'; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
return true; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @return bool |
369
|
|
|
*/ |
370
|
|
|
function xoops_module_update_xnewsletter_101() |
371
|
|
|
{ |
372
|
|
|
global $xoopsDB; |
373
|
|
|
|
374
|
|
|
//rename tables to new xoops naming scheme |
375
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_accounts'); |
376
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_cat'); |
377
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_subscr'); |
378
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_catsubscr'); |
379
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_letter'); |
380
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_protocol'); |
381
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_attachment'); |
382
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_mailinglist'); |
383
|
|
|
xoops_module_update_xnewsletter_rename_table('xnewsletter_bmh'); |
384
|
|
|
|
385
|
|
|
return true; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* @param string $tablename |
390
|
|
|
* |
391
|
|
|
* @return bool |
392
|
|
|
*/ |
393
|
|
View Code Duplication |
function xoops_module_update_xnewsletter_rename_table($tablename) |
|
|
|
|
394
|
|
|
{ |
395
|
|
|
global $xoopsDB; |
396
|
|
|
|
397
|
|
|
if (tableExists($xoopsDB->prefix($tablename))) { |
398
|
|
|
$sql = sprintf('ALTER TABLE ' . $xoopsDB->prefix($tablename) . ' RENAME ' . $xoopsDB->prefix('mod_' . $tablename)); |
399
|
|
|
$result = $xoopsDB->queryF($sql); |
400
|
|
|
if (!$result) { |
401
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": RENAME table '" . $tablename . "'"; |
402
|
|
|
// ++$errors; |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
return true; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @param string $tablename |
411
|
|
|
* |
412
|
|
|
* @return bool |
413
|
|
|
*/ |
414
|
|
View Code Duplication |
function xoops_module_update_xnewsletter_rename_mod_table($tablename) |
|
|
|
|
415
|
|
|
{ |
416
|
|
|
global $xoopsDB; |
417
|
|
|
|
418
|
|
|
if (tableExists($xoopsDB->prefix('mod_' . $tablename))) { |
419
|
|
|
$sql = sprintf('ALTER TABLE ' . $xoopsDB->prefix('mod_' . $tablename) . ' RENAME ' . $xoopsDB->prefix($tablename)); |
420
|
|
|
$result = $xoopsDB->queryF($sql); |
421
|
|
|
if (!$result) { |
422
|
|
|
echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": RENAME table '" . $tablename . "'"; |
423
|
|
|
// ++$errors; |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
return true; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @param $tablename |
432
|
|
|
* |
433
|
|
|
* @return bool |
434
|
|
|
*/ |
435
|
|
|
function tableExists($tablename) |
436
|
|
|
{ |
437
|
|
|
global $xoopsDB; |
438
|
|
|
$result = $xoopsDB->queryF("SHOW TABLES LIKE '{$tablename}'"); |
439
|
|
|
|
440
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
441
|
|
|
} |
442
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.