|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @param \XoopsModule $module |
|
5
|
|
|
* @return bool |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
use XoopsModules\Smartfaq; |
|
9
|
|
|
use XoopsModules\Smartfaq\Helper; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @param $module |
|
13
|
|
|
* @return bool |
|
14
|
|
|
*/ |
|
15
|
|
|
function xoops_module_update_smartfaq($module) |
|
16
|
|
|
{ |
|
17
|
|
|
/* |
|
18
|
|
|
// Load SmartDbUpdater from the SmartObject Framework if present |
|
19
|
|
|
$smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartobject/class/smartdbupdater.php'; |
|
20
|
|
|
if (!file_exists($smartdbupdater)) { |
|
21
|
|
|
$smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartfaq/class/SmartobjectDbupdater.php'; |
|
22
|
|
|
} |
|
23
|
|
|
require_once $smartdbupdater; |
|
24
|
|
|
*/ |
|
25
|
|
|
$dbupdater = new Smartfaq\SmartobjectDbupdater(); |
|
26
|
|
|
/** @var Smartfaq\Helper $helper */ |
|
27
|
|
|
$helper = Helper::getInstance(); |
|
28
|
|
|
$helper->loadLanguage('smartdbupdater'); |
|
29
|
|
|
|
|
30
|
|
|
ob_start(); |
|
31
|
|
|
|
|
32
|
|
|
echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
33
|
|
|
|
|
34
|
|
|
// Adding partialview field |
|
35
|
|
|
$table = new Smartfaq\SmartDbTable('smartfaq_faq'); |
|
36
|
|
|
if (!$table->fieldExists('partialview')) { |
|
37
|
|
|
$table->addNewField('partialview', "tinyint(1) NOT NULL default '0'"); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Changing categoryid type to int(11) |
|
41
|
|
|
$table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false); |
|
42
|
|
|
|
|
43
|
|
|
if (!$dbupdater->updateTable($table)) { |
|
44
|
|
|
/** |
|
45
|
|
|
* @todo trap the errors |
|
46
|
|
|
*/ |
|
47
|
|
|
} |
|
48
|
|
|
unset($table); |
|
49
|
|
|
|
|
50
|
|
|
// Editing smartfaq_categories table |
|
51
|
|
|
$table = new Smartfaq\SmartDbTable('smartfaq_categories'); |
|
52
|
|
|
// Changing categoryid type to int(11) |
|
53
|
|
|
$table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false); |
|
54
|
|
|
|
|
55
|
|
|
// Changing parentid type to int(11) |
|
56
|
|
|
$table->addAlteredField('parentid', "int(11) NOT NULL default '0'", false); |
|
57
|
|
|
|
|
58
|
|
|
if (!$dbupdater->updateTable($table)) { |
|
59
|
|
|
/** |
|
60
|
|
|
* @todo trap the errors |
|
61
|
|
|
*/ |
|
62
|
|
|
} |
|
63
|
|
|
unset($table); |
|
64
|
|
|
|
|
65
|
|
|
// Editing smartfaq_answers table |
|
66
|
|
|
$table = new Smartfaq\SmartDbTable('smartfaq_answers'); |
|
67
|
|
|
// Changing categoryid type to int(11) |
|
68
|
|
|
$table->addAlteredField('answerid', "int(11) NOT NULL default '0'", false); |
|
69
|
|
|
|
|
70
|
|
|
// Changing parentid type to int(11) |
|
71
|
|
|
$table->addAlteredField('faqid', "int(11) NOT NULL default '0'", false); |
|
72
|
|
|
|
|
73
|
|
|
if (!$dbupdater->updateTable($table)) { |
|
74
|
|
|
/** |
|
75
|
|
|
* @todo trap the errors |
|
76
|
|
|
*/ |
|
77
|
|
|
} |
|
78
|
|
|
unset($table); |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Check for items with categoryid=0 |
|
82
|
|
|
*/ // require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'; |
|
83
|
|
|
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
|
84
|
|
|
$smartfaq_faqHandler = $answerHandler = Helper::getInstance()->getHandler('Faq'); |
|
|
|
|
|
|
85
|
|
|
/** @var \XoopsModules\Smartfaq\CategoryHandler $smartfaq_categoryHandler */ |
|
86
|
|
|
$smartfaq_categoryHandler = $answerHandler = Helper::getInstance()->getHandler('Category'); |
|
87
|
|
|
|
|
88
|
|
|
//find a valid categoryid |
|
89
|
|
|
$categoriesObj = $smartfaq_categoryHandler->getCategories(1, 0, 0, 'weight', 'ASC', false); |
|
90
|
|
|
if (count($categoriesObj) > 0) { |
|
91
|
|
|
$categoryid = $categoriesObj[0]->getVar('categoryid'); |
|
92
|
|
|
$criteria = new \CriteriaCompo(); |
|
93
|
|
|
$criteria->add(new \Criteria('categoryid', 0)); |
|
94
|
|
|
$smartfaq_faqHandler->updateAll('categoryid', $categoryid, $criteria); |
|
95
|
|
|
echo ' Cleaning up questions with categoryid=0<br>'; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
echo '</code>'; |
|
99
|
|
|
|
|
100
|
|
|
$feedback = ob_get_clean(); |
|
101
|
|
|
if (method_exists($module, 'setMessage')) { |
|
102
|
|
|
$module->setMessage($feedback); |
|
103
|
|
|
} else { |
|
104
|
|
|
echo $feedback; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return true; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param \XoopsModule $module |
|
112
|
|
|
* @return bool |
|
113
|
|
|
*/ |
|
114
|
|
|
function xoops_module_install_smartfaq($module) |
|
115
|
|
|
{ |
|
116
|
|
|
ob_start(); |
|
117
|
|
|
|
|
118
|
|
|
// require_once XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/include/functions.php'; |
|
119
|
|
|
|
|
120
|
|
|
$feedback = ob_get_clean(); |
|
121
|
|
|
if (method_exists($module, 'setMessage')) { |
|
122
|
|
|
$module->setMessage($feedback); |
|
123
|
|
|
} else { |
|
124
|
|
|
echo $feedback; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return true; |
|
128
|
|
|
} |
|
129
|
|
|
|