Skip to content

Commit

Permalink
Fixed Multiple Issues with DB Administrator
Browse files Browse the repository at this point in the history
For issue #1111

- Added JavaScript Check for DB Admin Config page
- Removed unused Vars table settings
- Fixed a number of DB Admin Config page bugs
- Added success message for non JavaScript  browsers for features of DB Admin
  • Loading branch information
eSilverStrike committed Jan 28, 2022
1 parent a3ef5d9 commit 2fbb322
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 51 deletions.
7 changes: 5 additions & 2 deletions language/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
'terms_of_service' => 'Terms of Service',
'privacy_policy' => 'Privacy Policy',
'about_cookies' => 'About Cookies',
'parse_php_error' => 'There was an error parsing your PHP code: %s'
'parse_php_error' => 'There was an error parsing your PHP code: %s',
'error_title' => 'An Error Occurred'
);

###############################################################################
Expand Down Expand Up @@ -1786,7 +1787,8 @@
'site_db_backup' => "{$_CONF['site_name']} Database Backup",
'create_backup' => 'Backup Database',
'do_backup' => 'Do Backup',
'backup_successful' => 'Database back up was successful.',
'backup_successful' => 'Database backup was successful.',
'backup_error' => 'Error performing database backup.',
'db_explanation' => 'To create a new backup of your site\'s database, select the "Backup Database" option above. To download a backup, click on the filename from the list below.',
'backup_instructions' => 'To create a new backup of your site database, select the "Do Backup" button below. This will backup all current Geeklog tables. You can download a copy of the backup from the main Database Administration Screen.',
'zero_size' => 'Backup Failed: Filesize was 0 bytes',
Expand Down Expand Up @@ -1838,6 +1840,7 @@
'use_gzip' => 'Use GZip if available',
'configure' => 'Configure',
'config_instructions' => 'Select any tables you wish to exclude from the backup. Other options can be found in the Geeklog Configuration under the Database tab.',
'config_successful' => 'Tables to Backup list was saved successfully.'
);

###############################################################################
Expand Down
7 changes: 5 additions & 2 deletions language/english_utf-8.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
'terms_of_service' => 'Terms of Service',
'privacy_policy' => 'Privacy Policy',
'about_cookies' => 'About Cookies',
'parse_php_error' => 'There was an error parsing your PHP code: %s'
'parse_php_error' => 'There was an error parsing your PHP code: %s',
'error_title' => 'An Error Occurred'
);

###############################################################################
Expand Down Expand Up @@ -1786,7 +1787,8 @@
'site_db_backup' => "{$_CONF['site_name']} Database Backup",
'create_backup' => 'Backup Database',
'do_backup' => 'Do Backup',
'backup_successful' => 'Database back up was successful.',
'backup_successful' => 'Database backup was successful.',
'backup_error' => 'Error performing database backup.',
'db_explanation' => 'To create a new backup of your site\'s database, select the "Backup Database" option above. To download a backup, click on the filename from the list below.',
'backup_instructions' => 'To create a new backup of your site database, select the "Do Backup" button below. This will backup all current Geeklog tables. You can download a copy of the backup from the main Database Administration Screen.',
'zero_size' => 'Backup Failed: Filesize was 0 bytes',
Expand Down Expand Up @@ -1838,6 +1840,7 @@
'use_gzip' => 'Use GZip if available',
'configure' => 'Configure',
'config_instructions' => 'Select any tables you wish to exclude from the backup. Other options can be found in the Geeklog Configuration under the Database tab.',
'config_successful' => 'Tables to Backup list was saved successfully.'
);

###############################################################################
Expand Down
7 changes: 5 additions & 2 deletions language/japanese_utf-8.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@
'terms_of_service' => '利用規約',
'privacy_policy' => 'プライバシーポリシー',
'about_cookies' => 'クッキーについて',
'parse_php_error' => 'PHPをパース中にエラーが発生しました: %s'
'parse_php_error' => 'PHPをパース中にエラーが発生しました: %s',
'error_title' => 'An Error Occurred'
);

###############################################################################
Expand Down Expand Up @@ -1792,6 +1793,7 @@
'create_backup' => 'データベースのバックアップ',
'do_backup' => 'バックアップの実行',
'backup_successful' => 'データベースのバックアップを完了しました。',
'backup_error' => 'Error performing database backup.',
'db_explanation' => 'サイトのデータベースのバックアップを新しく作成するには「バックアップの実行」をクリックしてください。バックアップファイルをダウンロードするには、下記の一覧でファイル名をクリックしてください。',
'backup_instructions' => 'サイトのデータベースのバックアップを新しく作成するには下の「バックアップの実行」を選択してください。現在のGeeklogテーブルをバックアップします。データベース管理画面からバックアップしたファイルをダウンロードすることができます。',
'zero_size' => 'バックアップ失敗: ファイルの大きさが0バイトです。',
Expand Down Expand Up @@ -1842,7 +1844,8 @@
'disable_purge' => '(無制限に保持するには"0"を指定)',
'use_gzip' => '可能なら圧縮する(GZip)',
'configure' => 'コンフィギュレーション',
'config_instructions' => 'バックアップしたくないテーブルを選択してください。その他のオプションはコンフィギュレーションのGeeklog - データベースタブにあります。'
'config_instructions' => 'バックアップしたくないテーブルを選択してください。その他のオプションはコンフィギュレーションのGeeklog - データベースタブにあります。',
'config_successful' => 'Tables to Backup list was saved successfully.'
);

###############################################################################
Expand Down
96 changes: 53 additions & 43 deletions public_html/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// | |
// +---------------------------------------------------------------------------+

global $_DB_dbms, $_TABLES, $_USER;
global $_DB_dbms, $_TABLES, $_USER, $LANG01;

require_once '../lib-common.php';
require_once 'auth.inc.php';
Expand Down Expand Up @@ -279,16 +279,16 @@ function DBADMIN_backupCompleteAjax()
*/
function DBADMIN_backupTableAjax()
{
global $_VARS;
global $_CONF;

if (!COM_isAjax()) {
die();
}

$retval = [];

if (!isset($_VARS['_dbback_allstructs'])) {
$_VARS['_dbback_allstructs'] = 0;
if (!isset($_CONF['dbdump_tables_only'])) {
$_CONF['dbdump_tables_only'] = 0;
}

$filename = Geeklog\Input::post('backup_filename', '');
Expand All @@ -301,7 +301,7 @@ function DBADMIN_backupTableAjax()

$backup = new dbBackup();
$backup->setBackupFilename($filename);
list ($rc, $sessionCounter, $recordCounter) = $backup->backupTable($table, $_VARS['_dbback_allstructs'], $start);
list ($rc, $sessionCounter, $recordCounter) = $backup->backupTable($table, $_CONF['dbdump_tables_only'], $start);

switch ($rc) {
case 1:
Expand Down Expand Up @@ -398,9 +398,9 @@ function DBADMIN_backupPrompt()
]);
}

if (isset($_VARS['_dbback_allstructs']) && $_VARS['_dbback_allstructs']) {
$T->set_var('struct_warning', $LANG_DB_BACKUP['backup_warning']);
}
if (isset($_CONF['dbdump_tables_only']) && $_CONF['dbdump_tables_only']) {
$T->set_var('struct_warning', $LANG_DB_BACKUP['backup_warning']);
}

$T->set_var([
'action' => 'backup',
Expand Down Expand Up @@ -434,11 +434,21 @@ function DBADMIN_backupPrompt()
*/
function DBADMIN_backup()
{
$backup = new dbBackup();
$backup->performBackUp();
$backup->purge();

return DBADMIN_list();
global $LANG_DB_BACKUP, $LANG01;

$page = '';

$backup = new dbBackup();
if ($backup->performBackUp()) {
$page .= COM_showMessageText($LANG_DB_BACKUP['backup_successful']);
} else {
$page .= COM_showMessageText($LANG_DB_BACKUP['backup_error'], $LANG01['error_title']);
}
$backup->purge();

$page .= DBADMIN_list();

return $page;
}

/**
Expand Down Expand Up @@ -1121,7 +1131,6 @@ function DBADMIN_configBackup()

$T = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'admin/dbadmin'));
$T->set_file('page', 'dbbackupcfg.thtml');
$_SCRIPTS->setJavaScriptFile('move_users', '/javascript/moveusers.js');
$T->set_var(
'start_block',
COM_startBlock($LANG_DB_BACKUP['database_admin'], '',
Expand All @@ -1136,25 +1145,34 @@ function DBADMIN_configBackup()
)
);

$include_tables = array_diff($_TABLES, $exclude_tables);

foreach ($include_tables as $key => $name) {
$included .= "<option value=\"$name\">$name</option>\n";
foreach ($_TABLES as $key => $name) {
if (!in_array($name, $exclude_tables)) { // Only include actual tables that are not excluded
$included .= "<option value=\"$name\">$name</option>\n";
}
}
foreach ($exclude_tables as $key => $name) {
$excluded .= "<option value=\"$name\">$name</option>\n";
if (in_array($name, $_TABLES)) { // Only include actual tables that exist now in exclude
$excluded .= "<option value=\"$name\">$name</option>\n";
}
}

$T->set_var([
'lang_tables_to_backup' => $LANG_DB_BACKUP['tables_to_backup'],
'lang_include' => $LANG_DB_BACKUP['include'],
'lang_exclude' => $LANG_DB_BACKUP['exclude'],
'lang_save' => $LANG_ADMIN['save'],
'included_tables' => $included,
'excluded_tables' => $excluded,
'noscript' => COM_getNoScript(false), // JavaScript is required
]);
$T->set_var('end_block', COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer')));

// Add JavaScript
// Hide the Advanced Editor as Javascript is required. If JS is enabled then the JS below will un-hide it
$js = 'document.getElementById("admin-dbconfig").style.display="";';
$_SCRIPTS->setJavaScript($js, true);
$_SCRIPTS->setJavaScriptFile('admin-dbconfig', '/javascript/moveusers.js');

$T->parse('output', 'page');
$retval .= $T->finish($T->get_var('output'));

Expand Down Expand Up @@ -1234,7 +1252,7 @@ function DBADMIN_configBackup()
if (DBADMIN_supported_engine('MyISAM')) {
$page .= DBADMIN_myisam();
} else {
$page .= COM_showMessageText($LANG_DB_BACKUP['no_myisam'], 'error');
$page .= COM_showMessageText($LANG_DB_BACKUP['no_myisam'], $LANG01['error_title']);
}
break;

Expand All @@ -1243,7 +1261,7 @@ function DBADMIN_configBackup()
if (DBADMIN_supported_engine('InnoDB')) {
$page .= DBADMIN_innodb();
} else {
$page .= COM_showMessageText($LANG_DB_BACKUP['no_innodb'], 'error');
$page .= COM_showMessageText($LANG_DB_BACKUP['no_innodb'], $LANG01['error_title']);
}
break;

Expand All @@ -1258,12 +1276,12 @@ function DBADMIN_configBackup()
if ($num_errors == 0) {
$page .= COM_showMessageText($LANG_DB_BACKUP['innodb_success']);
} else {
$page .= COM_showMessageText($LANG_DB_BACKUP['innodb_success'] . ' ' . $LANG_DB_BACKUP['table_issues'], 'error');
$page .= COM_showMessageText($LANG_DB_BACKUP['innodb_success'] . ' ' . $LANG_DB_BACKUP['table_issues'], $LANG01['error_title']);
}
$page .= DBADMIN_list();
}
} else {
$page .= COM_showMessageText($LANG_DB_BACKUP['no_innodb'], 'error');
$page .= COM_showMessageText($LANG_DB_BACKUP['no_innodb'], $LANG01['error_title']);
}
break;

Expand All @@ -1278,12 +1296,12 @@ function DBADMIN_configBackup()
if ($num_errors == 0) {
$page .= COM_showMessageText($LANG_DB_BACKUP['myisam_success']);
} else {
$page .= COM_showMessageText($LANG_DB_BACKUP['myisam_success'] . ' ' . $LANG_DB_BACKUP['table_issues'], 'error');
$page .= COM_showMessageText($LANG_DB_BACKUP['myisam_success'] . ' ' . $LANG_DB_BACKUP['table_issues'], $LANG01['error_title']);
}
$page .= DBADMIN_list();
}
} else {
$page .= COM_showMessageText($LANG_DB_BACKUP['no_innodb'], 'error');
$page .= COM_showMessageText($LANG_DB_BACKUP['no_innodb'], $LANG01['error_title']);
}
break;

Expand All @@ -1303,7 +1321,7 @@ function DBADMIN_configBackup()
} else {
$page .= COM_showMessageText(
$LANG_DB_BACKUP['optimize_success'] . ' ' . $LANG_DB_BACKUP['table_issues'],
'error'
$LANG01['error_title']
);
}
$page .= DBADMIN_list();
Expand All @@ -1313,22 +1331,12 @@ function DBADMIN_configBackup()
case 'saveconfig':
$items = [];

// Code taken from Geeklog Group Members. Uses same javascript so that is why it has these variable names
$exclude_tables = explode('|', Geeklog\Input::post('groupmembers'));
// Make sure tables exist that can be excluded
$exclude_tables = array_intersect($exclude_tables, $_TABLES);
// Get the excluded tables into a serialized string
$tables = explode('|', Geeklog\Input::post('groupmembers'));
$items['_dbback_exclude'] = DB_escapeString(@serialize($tables));
$items['_dbback_files'] = (int) Geeklog\Input::post('db_backup_maxfiles', 0);

/* ---
if (isset($_POST['disable_cron'])) {
$str = '-1';
} else {
$str = (int)$_POST['db_backup_interval'];
}
$items['_dbback_cron'] = $str;
--- */

$items['_dbback_gzip'] = isset($_POST['use_gzip']) ? 1 : 0;
$items['_dbback_allstructs'] = isset($_POST['allstructs']) ? 1 : 0;
$items['_dbback_exclude'] = DB_escapeString(@serialize($exclude_tables));

foreach ($items as $name => $value) {
$sql = "INSERT INTO {$_TABLES['vars']} (name, value)
Expand All @@ -1337,7 +1345,9 @@ function DBADMIN_configBackup()
DB_query($sql);
}

$page = DBADMIN_list();
$page .= COM_showMessageText($LANG_DB_BACKUP['config_successful']);

$page .= DBADMIN_list();
break;

case 'mode':
Expand Down
10 changes: 9 additions & 1 deletion public_html/admin/install/devel-db-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ function update_DatabaseFor222()
update_CombineUserTables222();
}
*/
}
}

// Old VARS table variables for Database Backup that are not used anymore (but could still get created in some cases)
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_files'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_gzip'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_allstructs'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = 'db_backup_interval'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_cron'";



// ***************************************
Expand Down
3 changes: 2 additions & 1 deletion public_html/layout/denim/admin/dbadmin/dbbackupcfg.thtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

{admin_menu}

<div class="uk-panel uk-panel-box uk-container-center">
{noscript}
<div class="uk-panel uk-panel-box uk-container-center" id="admin-dbconfig" style="display:none;">
<form class="uk-form uk-form-horizontal" action="{site_admin_url}/database.php" method="post">
<input type="hidden" name="saveconfig" value="x">
<input type="hidden" name="groupmembers">
Expand Down
7 changes: 7 additions & 0 deletions sql/updates/mysql_2.2.1_to_2.2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
$_SQL[] = "DROP TABLE {$_TABLES['dateformats']}";
$_SQL[] = "DROP TABLE {$_TABLES['maillist']}";

// Old VARS table variables for Database Backup that are not used anymore (but could still get created in some cases)
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_files'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_gzip'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_allstructs'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = 'db_backup_interval'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_cron'";

/**
* Add/Edit/Delete config options for new version
*/
Expand Down
7 changes: 7 additions & 0 deletions sql/updates/pgsql_2.2.1_to_2.2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
$_SQL[] = "DROP TABLE {$_TABLES['dateformats']}";
$_SQL[] = "DROP TABLE {$_TABLES['maillist']}";

// Old VARS table variables for Database Backup that are not used anymore (but could still get created in some cases)
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_files'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_gzip'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_allstructs'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = 'db_backup_interval'";
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = '_dbback_cron'";

/**
* Add/Edit/Delete config options for new version
*/
Expand Down

0 comments on commit 2fbb322

Please sign in to comment.