Skip to content

Commit 6c00d0d

Browse files
committed
Fix issues with upgrading when not using Cacti DB
1 parent e04f0f0 commit 6c00d0d

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

database.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,13 @@ function syslog_db_table_exists($table, $log = true) {
149149
return false;
150150
}
151151

152+
function syslog_db_column_exists($table, $column, $log = true) {
153+
global $syslog_cnn;
154+
return db_column_exists($table, $column, $log, $syslog_cnn);
155+
}
156+
157+
function syslog_db_add_column($table, $column, $log = true) {
158+
global $syslog_cnn;
159+
return db_add_column($table, $column, $log, $syslog_cnn);
160+
}
161+

setup.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function syslog_connect() {
204204
}
205205

206206
function syslog_check_upgrade() {
207-
global $config, $cnn_id, $syslog_levels, $database_default, $syslog_upgrade;
207+
global $config, $syslog_cnn, $cnn_id, $syslog_levels, $database_default, $syslog_upgrade;
208208

209209
include(dirname(__FILE__) . '/config.php');
210210

@@ -237,7 +237,7 @@ function syslog_check_upgrade() {
237237
print __('Syslog 2.0 Requires an Entire Reinstall. Please uninstall Syslog and Remove all Data before Installing. Migration is possible, but you must plan this in advance. No automatic migration is supported.', 'syslog') . "\n";
238238
exit;
239239
} elseif ($old == 2) {
240-
db_execute('ALTER TABLE syslog_statistics
240+
syslog_db_execute('ALTER TABLE syslog_statistics
241241
ADD COLUMN id BIGINT UNSIGNED auto_increment FIRST,
242242
DROP PRIMARY KEY,
243243
ADD PRIMARY KEY(id),
@@ -252,24 +252,24 @@ function syslog_check_upgrade() {
252252
webpage='" . $version['homepage'] . "'
253253
WHERE directory='" . $version['name'] . "' ");
254254

255-
if (!db_column_exists('syslog_alert', 'hash')) {
256-
db_add_column('syslog_alert', array(
255+
if (!syslog_db_column_exists('syslog_alert', 'hash')) {
256+
syslog_db_add_column('syslog_alert', array(
257257
'name' => 'hash',
258258
'type' => 'varchar(32)',
259259
'NULL' => false,
260260
'default' => '',
261261
'after' => 'id')
262262
);
263263

264-
db_add_column('syslog_remove', array(
264+
syslog_db_add_column('syslog_remove', array(
265265
'name' => 'hash',
266266
'type' => 'varchar(32)',
267267
'NULL' => false,
268268
'default' => '',
269269
'after' => 'id')
270270
);
271271

272-
db_add_column('syslog_reports', array(
272+
syslog_db_add_column('syslog_reports', array(
273273
'name' => 'hash',
274274
'type' => 'varchar(32)',
275275
'NULL' => false,
@@ -278,8 +278,8 @@ function syslog_check_upgrade() {
278278
);
279279
}
280280

281-
if (db_column_exists('syslog_incoming', 'date')) {
282-
db_execute("ALTER TABLE syslog_incoming
281+
if (syslog_db_column_exists('syslog_incoming', 'date')) {
282+
syslog_db_execute("ALTER TABLE syslog_incoming
283283
DROP COLUMN date,
284284
CHANGE COLUMN `time` logtime timestamp default '0000-00-00';");
285285
}
@@ -291,7 +291,7 @@ function syslog_check_upgrade() {
291291
if (cacti_sizeof($alerts)) {
292292
foreach($alerts as $a) {
293293
$hash = get_hash_syslog($a['id'], 'syslog_alert');
294-
db_execute_prepared('UPDATE syslog_alert
294+
syslog_db_execute_prepared('UPDATE syslog_alert
295295
SET hash = ?
296296
WHERE id = ?',
297297
array($hash, $a['id']));
@@ -305,7 +305,7 @@ function syslog_check_upgrade() {
305305
if (cacti_sizeof($removes)) {
306306
foreach($removes as $r) {
307307
$hash = get_hash_syslog($r['id'], 'syslog_remove');
308-
db_execute_prepared('UPDATE syslog_remove
308+
syslog_db_execute_prepared('UPDATE syslog_remove
309309
SET hash = ?
310310
WHERE id = ?',
311311
array($hash, $r['id']));
@@ -319,14 +319,13 @@ function syslog_check_upgrade() {
319319
if (cacti_sizeof($reports)) {
320320
foreach($reports as $r) {
321321
$hash = get_hash_syslog($r['id'], 'syslog_reports');
322-
db_execute_prepared('UPDATE syslog_reports
322+
syslog_db_execute_prepared('UPDATE syslog_reports
323323
SET hash = ?
324324
WHERE id = ?',
325325
array($hash, $r['id']));
326326
}
327327
}
328328
}
329-
330329
}
331330

332331
function syslog_get_mysql_version($db = 'cacti') {

0 commit comments

Comments
 (0)