Skip to content

Commit 4b7584c

Browse files
author
Marius Cramer
committed
Fixed issue with non-existing database user on slave server
1 parent c3d8a84 commit 4b7584c

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

interface/web/sites/database_edit.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,26 @@ function onBeforeUpdate() {
275275
}
276276
}
277277
}
278-
278+
279+
if ($app->tform->errorMessage == '') {
280+
// force update of the used database user
281+
if($this->dataRecord['database_user_id']) {
282+
$user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ' . $app->functions->intval($this->dataRecord['database_user_id']));
283+
if($user_old_rec) {
284+
$user_new_rec = $user_old_rec;
285+
$user_new_rec['server_id'] = $this->dataRecord['server_id'];
286+
$app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_user_id'], $user_old_rec, $user_new_rec);
287+
}
288+
}
289+
if($this->dataRecord['database_ro_user_id']) {
290+
$user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ' . $app->functions->intval($this->dataRecord['database_ro_user_id']));
291+
if($user_old_rec) {
292+
$user_new_rec = $user_old_rec;
293+
$user_new_rec['server_id'] = $this->dataRecord['server_id'];
294+
$app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_ro_user_id'], $user_old_rec, $user_new_rec);
295+
}
296+
}
297+
}
279298

280299
parent::onBeforeUpdate();
281300
}
@@ -344,6 +363,27 @@ function onBeforeInsert() {
344363
}
345364
}
346365

366+
if ($app->tform->errorMessage == '') {
367+
// force update of the used database user
368+
if($this->dataRecord['database_user_id']) {
369+
$user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ' . $app->functions->intval($this->dataRecord['database_user_id']));
370+
if($user_old_rec) {
371+
$user_new_rec = $user_old_rec;
372+
$user_new_rec['server_id'] = $this->dataRecord['server_id'];
373+
$app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_user_id'], $user_old_rec, $user_new_rec);
374+
}
375+
}
376+
if($this->dataRecord['database_ro_user_id']) {
377+
$user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ' . $app->functions->intval($this->dataRecord['database_ro_user_id']));
378+
if($user_old_rec) {
379+
$user_new_rec = $user_old_rec;
380+
$user_new_rec['server_id'] = $this->dataRecord['server_id'];
381+
$app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_ro_user_id'], $user_old_rec, $user_new_rec);
382+
}
383+
}
384+
}
385+
386+
347387
parent::onBeforeInsert();
348388
}
349389

0 commit comments

Comments
 (0)