[geeklog-cvs] geeklog: Merged with "dbadmin" feature branch

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sat Oct 31 16:49:55 EDT 2009


changeset 7418:1ef30531a38e
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/1ef30531a38e
user: Dirk Haun <dirk at haun-online.de>
date: Sat Oct 31 18:03:53 2009 +0100
description:
Merged with "dbadmin" feature branch

diffstat:

 language/english.php                   |   22 +-
 language/english_utf-8.php             |   26 +-
 public_html/admin/database.php         |  524 +++++++++++++++++++++++++++++++++++--
 public_html/admin/install/toinnodb.php |  116 --------
 public_html/docs/history               |    3 +
 5 files changed, 538 insertions(+), 153 deletions(-)

diffs (truncated from 812 to 300 lines):

diff -r 6043bfcaf4c9 -r 1ef30531a38e language/english.php
--- a/language/english.php	Sat Oct 31 17:00:51 2009 +0100
+++ b/language/english.php	Sat Oct 31 18:03:53 2009 +0100
@@ -1336,7 +1336,27 @@
     'size' => 'Size',
     'bytes' => 'Bytes',
     'total_number' => 'Total number of backups: %d',
-    'download' => 'Click to download this file'
+    'download' => 'Click to download this file',
+    'new_backup' => 'New Backup',
+    'delete_failure' => 'One or more backup files could not be deleted.',
+    'delete_success' => 'Backup file(s) successfully deleted.',
+    'convert_menu' => 'Convert to InnoDB',
+    'convert_title' => 'Convert to InnoDB tables',
+    'convert_button' => 'Convert',
+    'sorry_no_innodb' => 'Sorry, your version of MySQL does not support InnoDB tables.',
+    'innodb_explain' => 'InnoDB tables provide better performance on <em>really</em> large databases but make the backup process more complicated. Please <a href="http://dev.mysql.com/doc/mysql/en/innodb.html">read up</a> on the pros and cons of InnoDB tables before you perform this operation.',
+    'already_converted' => 'Note: It appears that all of the tables have already been converted to InnoDB.',
+    'conversion_patience' => 'Note: Conversion may take some time - please be patient.',
+    'innodb_success' => 'Successfully converted tables to InnoDB.',
+    'table_issues' => 'There may have been problems with some tables, though. Please check error.log for details.',
+
+    'optimize_menu' => 'Optimize Tables',
+    'optimize_title' => 'Optimize Tables',
+    'optimize_button' => 'Optimize',
+    'optimize_explain' => 'Optimizing tables may help to improve the performance of your site. The actual impact depends on the table usage and some tables may benefit from it more than others. Do no expect to see a huge difference in performance. The <a href="http://dev.mysql.com/doc/mysql/en/optimize-table.html">MySQL manual</a> states: <q>it is not likely that you need to do this more than once a week or month</q>.',
+    'last_optimization' => 'Last optimization',
+    'optimization_patience' => 'Note: Optimization may take some time - please be patient.',
+    'optimize_success' => 'Successfully optimized database tables.'
 );
 
 ###############################################################################
diff -r 6043bfcaf4c9 -r 1ef30531a38e language/english_utf-8.php
--- a/language/english_utf-8.php	Sat Oct 31 17:00:51 2009 +0100
+++ b/language/english_utf-8.php	Sat Oct 31 18:03:53 2009 +0100
@@ -1034,7 +1034,7 @@
     6 => 'Warning: Plugin Already Installed!',
     7 => 'The plugin you are trying to install already exists.  Please delete the plugin before re-installing it',
     8 => 'Plugin Compatibility Check Failed',
-    9 => 'This plugin requires a newer version of Geeklog. Please upgrade your copy of <a href="http://www.geeklog.net/">Geeklog</a>.',
+    9 => 'This plugin requires a newer version of Geeklog. Please upgrade your copy of <a href="http://www.geeklog.net">Geeklog</a>.',
     10 => '<br' . XHTML . '><b>There are no plugins currently installed.</b><br' . XHTML . '><br' . XHTML . '>',
     11 => 'To modify or delete a plugin, click on that plugin\'s edit icon below. This will show the plugin details including the authors\'s website. Both the installed version and the version returned from the plugin\'s code are shown. This will aid you to know if the plugin needs to be upgraded. To install or upgrade a plugin please consult its documentation.',
     12 => 'no plugin name provided to plugineditor()',
@@ -1336,7 +1336,27 @@
     'size' => 'Size',
     'bytes' => 'Bytes',
     'total_number' => 'Total number of backups: %d',
-    'download' => 'Click to download this file'
+    'download' => 'Click to download this file',
+    'new_backup' => 'New Backup',
+    'delete_failure' => 'One or more backup files could not be deleted.',
+    'delete_success' => 'Backup file(s) successfully deleted.',
+    'convert_menu' => 'Convert to InnoDB',
+    'convert_title' => 'Convert to InnoDB tables',
+    'convert_button' => 'Convert',
+    'sorry_no_innodb' => 'Sorry, your version of MySQL does not support InnoDB tables.',
+    'innodb_explain' => 'InnoDB tables provide better performance on <em>really</em> large databases but make the backup process more complicated. Please <a href="http://dev.mysql.com/doc/mysql/en/innodb.html">read up</a> on the pros and cons of InnoDB tables before you perform this operation.',
+    'already_converted' => 'Note: It appears that all of the tables have already been converted to InnoDB.',
+    'conversion_patience' => 'Note: Conversion may take some time - please be patient.',
+    'innodb_success' => 'Successfully converted tables to InnoDB.',
+    'table_issues' => 'There may have been problems with some tables, though. Please check error.log for details.',
+
+    'optimize_menu' => 'Optimize Tables',
+    'optimize_title' => 'Optimize Tables',
+    'optimize_button' => 'Optimize',
+    'optimize_explain' => 'Optimizing tables may help to improve the performance of your site. The actual impact depends on the table usage and some tables may benefit from it more than others. Do no expect to see a huge difference in performance. The <a href="http://dev.mysql.com/doc/mysql/en/optimize-table.html">MySQL manual</a> states: <q>it is not likely that you need to do this more than once a week or month</q>.',
+    'last_optimization' => 'Last optimization',
+    'optimization_patience' => 'Note: Optimization may take some time - please be patient.',
+    'optimize_success' => 'Successfully optimized database tables.'
 );
 
 ###############################################################################
@@ -1855,7 +1875,7 @@
     'url_rewrite' => "Enable URL Rewrite",
     'meta_tags' => "Meta Tags",
     'meta_description' => "Default Meta Description",
-    'meta_keywords' => "Default Meta Keywords",
+    'meta_keywords' => "Default Meta Keywords",    
     'default_permissions_block' => "Block Default Permissions",
     'default_permissions_story' => "Story Default Permissions",
     'default_permissions_topic' => "Topic Default Permissions",
diff -r 6043bfcaf4c9 -r 1ef30531a38e public_html/admin/database.php
--- a/public_html/admin/database.php	Sat Oct 31 17:00:51 2009 +0100
+++ b/public_html/admin/database.php	Sat Oct 31 18:03:53 2009 +0100
@@ -6,7 +6,7 @@
 // +---------------------------------------------------------------------------+
 // | database.php                                                              |
 // |                                                                           |
-// | Geeklog database backup administration page.                              |
+// | Geeklog database backup and maintenance page.                             |
 // +---------------------------------------------------------------------------+
 // | Copyright (C) 2000-2009 by the following authors:                         |
 // |                                                                           |
@@ -32,7 +32,22 @@
 // |                                                                           |
 // +---------------------------------------------------------------------------+
 
+/**
+* This admin panel provides some simple database backup and administration
+* abilities. You can create and download database backups, optimize tables,
+* or convert tables to InnoDB.
+* All of these functions are currently only available for MySQL. The link to
+* this admin panel is actually hidden when not using MySQL.
+*/
+
+/**
+* Geeklog common function library
+*/
 require_once '../lib-common.php';
+
+/**
+* Security check to ensure user even belongs on this page
+*/
 require_once 'auth.inc.php';
 
 $display = '';
@@ -48,12 +63,6 @@
 }
 
 /**
-* This page allows all Root admins to create a database backup.  It's pretty
-* simple actually.  The admin clicks a button, we do a mysqldump to a file in
-* the following format: geeklog_db_backup_YYYY_MM_DD_hh_mm_ss.sql  That's it.
-*/
-
-/**
 * Sort backup files with newest first, oldest last.
 * For use with usort() function.
 * This is needed because the sort order of the backup files, coming from the
@@ -80,7 +89,8 @@
 */
 function listbackups()
 {
-    global $_CONF, $_TABLES, $_IMAGE_TYPE, $LANG08, $LANG_ADMIN, $LANG_DB_BACKUP;
+    global $_CONF, $_TABLES, $_IMAGE_TYPE, $LANG08, $LANG_ADMIN,
+           $LANG_DB_BACKUP, $_DB_dbms;
 
     require_once $_CONF['path_system'] . 'lib-admin.php';
 
@@ -122,11 +132,23 @@
         $token = SEC_createToken();
         $menu_arr = array(
             array('url' => $_CONF['site_admin_url']
-                           . '/database.php?mode=backup&'.CSRF_TOKEN.'='.$token,
+                                . '/database.php?mode=backup&'
+                                . CSRF_TOKEN . '=' . $token,
                   'text' => $LANG_ADMIN['create_new']),
+        );
+        if ($_DB_dbms == 'mysql') {
+            $menu_arr[] =
+                array('url' => $thisUrl . '?mode=optimize',
+                      'text' => $LANG_DB_BACKUP['optimize_menu']);
+            if (innodb_supported()) {
+                $menu_arr[] =
+                    array('url' => $thisUrl . '?mode=innodb',
+                          'text' => $LANG_DB_BACKUP['convert_menu']);
+            }
+        }
+        $menu_arr[] =
             array('url' => $_CONF['site_admin_url'],
-                  'text' => $LANG_ADMIN['admin_home'])
-        );
+                  'text' => $LANG_ADMIN['admin_home']);
         $retval .= COM_startBlock($LANG_DB_BACKUP['last_ten_backups'], '',
                             COM_getBlockTemplate('_admin_block', 'header'));
         $retval .= ADMIN_createMenu(
@@ -263,21 +285,393 @@
     $dl->downloadFile($file);
 }
 
+/**
+* Delete selected backup files
+*
+* @return   string  empty string (nothing to do), or HTML error or success msg
+*
+*/
+function deletebackups()
+{
+    global $_CONF, $LANG_DB_BACKUP;
+
+    $retval = '';
+    $files = 0;
+    $failed = 0;
+
+    foreach ($_POST['delitem'] as $delfile) {
+        $file = COM_sanitizeFilename($delfile, true);
+        if (! empty($file)) {
+            $files++;
+            if (! @unlink($_CONF['backup_path'] . $file)) {
+                COM_errorLog('Unable to remove backup file "' . $file . '"');
+                $failed++;
+            }
+        }
+    }
+
+    if ($files > 0) {
+        if ($failed > 0) {
+            $retval .= COM_showMessageText($LANG_DB_BACKUP['delete_failure']);
+        } else {
+            $retval .= COM_showMessageText($LANG_DB_BACKUP['delete_success']);
+        }
+    }
+
+    return $retval;
+}
+
+/**
+* Create a simple form with two buttons
+*
+* Creates a simple form that has a Cancel and an "action" button, where
+* the latter invokes a POST request with $_POST['mode'] set to the given value.
+*
+* @param    string  $buttontext     text string for the "action" button
+* @param    string  $mode           mode value
+* @param    string  $token          CSRF token, will be created if empty
+* @return   string                  HTML form
+*
+*/
+function miniform_DoOrCancel($buttontext, $mode, $token = '')
+{
+    global $_CONF, $LANG_ADMIN;
+
+    $retval = '';
+
+    if (empty($token)) {
+        $token = SEC_createToken();
+    }
+
+    $retval .= '<div id="miniform"><form action="' . $_CONF['site_admin_url']
+            . '/database.php" method="post" style="display:inline;">' . LB;
+    $retval .= '<input type="submit" value="' . $buttontext . '"'
+            . XHTML . '>' . LB;
+    $retval .= '<input type="hidden" name="mode" value="' . $mode . '"'
+            . XHTML . '>' . LB;
+    $retval .= '<input type="hidden" name="' . CSRF_TOKEN . '" value="'
+            . $token . '"' . XHTML . '>' . LB;
+    $retval .= '</form>' . LB;
+    $retval .= '<form action="' . $_CONF['site_admin_url']
+            . '/database.php" method="post" style="display:inline;">' . LB;
+    $retval .= '<input type="submit" value="' . $LANG_ADMIN['cancel'] . '"'
+            . XHTML . '>' . LB;
+    $retval .= '</form></div>' . LB;
+
+    return $retval;
+}
+
+/**
+* Check for InnoDB table support (usually as of MySQL 4.0, but may be
+* available in earlier versions, e.g. "Max" or custom builds).
+*
+* @return   true = InnoDB tables supported, false = not supported
+*
+*/
+function innodb_supported()
+{
+    global $_DB_dbms;
+
+    $retval = false;
+
+    if ($_DB_dbms == 'mysql') {
+        $result = DB_query("SHOW TABLE TYPES");
+        $numEngines = DB_numRows($result);
+        for ($i = 0; $i < $numEngines; $i++) {
+            $A = DB_fetchArray($result);
+
+            if (strcasecmp($A['Engine'], 'InnoDB') == 0) {
+                if (strcasecmp($A['Support'], 'yes') == 0) {
+                    $retval = true;
+                }
+                break;
+            }
+        }
+    }
+
+    return $retval;
+}
+
+/**
+* Check if all the tables have already been converted to InnoDB
+*
+* @return   bool    true: all tables are InnoDB, otherwise false
+*
+*/
+function already_converted()
+{
+    global $_CONF, $_TABLES, $_DB_name;
+
+    $retval = false;
+
+    $engine = DB_getItem($_TABLES['vars'], 'value', "name = 'database_engine'");
+    if (!empty($engine) && ($engine == 'InnoDB')) {
+        // need to look at all the tables
+        $result = DB_query("SHOW TABLES");
+        $numTables = DB_numRows($result);
+        for ($i = 0; $i < $numTables; $i++) {
+            $A = DB_fetchArray($result, true);
+            $table = $A[0];
+            if (in_array($table, $_TABLES)) {
+                $result2 = DB_query("SHOW TABLE STATUS FROM $_DB_name LIKE '$table'");



More information about the geeklog-cvs mailing list