Vergleich admin/dbtools.php - 1.2.2 - 1.2.13

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 3Zeile 3
 * MyBB 1.2
* Copyright © 2006 MyBB Group, All Rights Reserved
*

 * MyBB 1.2
* Copyright © 2006 MyBB Group, All Rights Reserved
*

 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html

 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/eula.html

 *

 *

 * $Id$

 * $Id: dbtools.php 3530 2007-12-01 19:29:47Z Tikitiki $

 */

define("IN_MYBB", 1);

 */

define("IN_MYBB", 1);

Zeile 32Zeile 32
	case 'optimize':
addacpnav($lang->optimize_tables);
break;

	case 'optimize':
addacpnav($lang->optimize_tables);
break;

 
	case 'utf8_conversion':
addacpnav($lang->convert_to_utf8);
break;
}

if($mybb->input['action'] == "utf8_conversion")
{
cpheader();

// The last step where we do the actual conversion process.
if($mybb->request_method == "post" || ($mybb->input['table'] == "all" && isset($mybb->input['table2'])))
{
@set_time_limit(0);

if($mybb->input['table'] == "all")
{
$all = true;
$mybb->input['table'] = $mybb->input['table2'];
}

if(!$db->table_exists($db->escape_string($mybb->input['table'])))
{
cperror($lang->error_invalid_table);
}

starttable();

$table1 = $db->show_create_table($db->escape_string($mybb->input['table']));
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table1, $matches);
$charset = $matches[1];

tableheader($converting_table." {$mybb->input['table']}", 'tablename', 1);

echo "<tr>\n";
echo "<td class=\"subheader\"><strong>".sprintf($lang->converting_to_utf8, $mybb->input['table'], $charset)."</strong></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"altbg1\" align=\"center\">{$lang->please_wait}</td>\n";
echo "</tr>\n";

flush();

$types = array(
'text' => 'blob',
'mediumtext' => 'mediumblob',
'longtext' => 'longblob',
'char' => 'varbinary',
'varchar' => 'varbinary',
'tinytext' => 'tinyblob'
);

// Get next table in list
$convert_to_binary = '';
$convert_to_utf8 = '';
$comma = '';

// Set table default charset
$db->query("ALTER TABLE {$mybb->input['table']} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");

// Fetch any fulltext keys
if($db->supports_fulltext($mybb->input['table']))
{
$table_structure = $db->show_create_table($mybb->input['table']);
preg_match_all("#FULLTEXT KEY `?([a-zA-Z0-9_]+)`? \(([a-zA-Z0-9_`,']+)\)#i", $table_structure, $matches);
if(is_array($matches))
{
foreach($matches[0] as $key => $matched)
{
$db->query("ALTER TABLE {$mybb->input['table']} DROP INDEX {$matches[1][$key]}");
$fulltext_to_create[$matches[1][$key]] = $matches[2][$key];
}
}
}

// Find out which columns need converting and build SQL statements
$query = $db->query("SHOW FULL COLUMNS FROM {$mybb->input['table']}");
while($column = $db->fetch_array($query))
{
list($type) = explode('(', $column['Type']);
if(array_key_exists($type, $types))
{
// Build the actual strings for converting the columns
$names = "CHANGE `{$column['Field']}` `{$column['Field']}` ";

$attributes = " DEFAULT ";
if($column['Default'] == 'NULL')
{
$attributes .= "NULL ";
}
else
{
$attributes .= "'".$db->escape_string($column['Default'])."' ";

if($column['Null'] == 'YES')
{
$attributes .= 'NULL';
}
else
{
$attributes .= 'NOT NULL';
}
}

$convert_to_binary .= $comma.$names.preg_replace('/'.$type.'/i', $types[$type], $column['Type']).$attributes;
$convert_to_utf8 .= "{$comma}{$names}{$column['Type']} CHARACTER SET utf8 COLLATE utf8_general_ci{$attributes}";

$comma = ', ';
}
}

if(!empty($convert_to_binary))
{
// This converts the columns to UTF-8 while also doing the same for data
$db->query("ALTER TABLE {$mybb->input['table']} {$convert_to_binary}");
$db->query("ALTER TABLE {$mybb->input['table']} {$convert_to_utf8}");
}

// Any fulltext indexes to recreate?
if(is_array($fulltext_to_create))
{
foreach($fulltext_to_create as $name => $fields)
{
$db->create_fulltext_index($mybb->input['table'], $fields, $name);
}
}

if($all == true)
{
$tables = $db->list_tables($config['database']);
foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
if(fetch_iconv_encoding($matches[1]) == 'utf-8' && $mybb->input['table'] != $tablename)
{
continue;
}

$mybb_tables[$key] = $tablename;
}
}

asort($mybb_tables);
reset($mybb_tables);

$is_next = false;
$nexttable = "";

foreach($mybb_tables as $key => $tablename)
{
if($is_next == true)
{
$nexttable = $tablename;
break;
}
else if($mybb->input['table'] == $tablename)
{
$is_next = true;
}
}

if($nexttable)
{
$nexttable = $db->escape_string($nexttable);
echo "<tr>\n";
echo "<td class=\"altbg2\" align=\"center\">".sprintf($lang->success_table_converted, $mybb->input['table'])."</td>\n";
echo "</tr>\n";
endtable();
echo "<meta http-equiv=\"Refresh\" content=\"5; url=dbtools.php?".SID."&amp;action=utf8_conversion&amp;table=all&amp;table2={$nexttable}\" />";
}
else
{
echo "<tr>\n";
echo "<td class=\"altbg2\" align=\"center\">".sprintf($lang->success_table_converted, $mybb->input['table'])."</td>\n";
echo "</tr>\n";
endtable();
echo "<meta http-equiv=\"Refresh\" content=\"5; url=dbtools.php?".SID."&amp;action=utf8_conversion\" />";
}
}
else
{
echo "<tr>\n";
echo "<td class=\"altbg2\" align=\"center\">".sprintf($lang->success_table_converted, $mybb->input['table'])."</td>\n";
echo "</tr>\n";
endtable();
echo "<meta http-equiv=\"Refresh\" content=\"5; url=dbtools.php?".SID."&amp;action=utf8_conversion\" />";
}

cpfooter();

exit;
}

// This is the second step where we confirm the table we're about to convert.
if($mybb->input['table'])
{
if($mybb->input['table'] != "all" && !$db->table_exists($db->escape_string($mybb->input['table'])))
{
cperror($lang->error_invalid_table);
}

if($mybb->input['table'] == "all")
{
$tables = $db->list_tables($config['database']);
foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
if(fetch_iconv_encoding($matches[1]) == 'utf-8')
{
continue;
}
$mybb_tables[$key] = $tablename;
}
}

if(is_array($mybb_tables))
{
asort($mybb_tables);
reset($mybb_tables);
$nexttable = current($mybb_tables);
$table = $db->show_create_table($db->escape_string($nexttable));
}
else
{
cperror($lang->error_all_tables_already_converted);
}
}
else
{
$table = $db->show_create_table($db->escape_string($mybb->input['table']));
}

preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
$charset = $matches[1];

startform('dbtools.php', '', "utf8_conversion");
makehiddencode('table', $mybb->input['table']);


if($mybb->input['table'] == "all")
{
makehiddencode('table2', $nexttable);
starttable();
tableheader($lang->convert_tables, 'converttable', 1);
echo "<tr>\n";
echo "<td class=\"subheader\"><strong>".sprintf($lang->convert_all_to_utf, $charset)."</strong></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"altbg1\" align=\"center\">{$lang->notice_proccess_long_time}</td>\n";
echo "</tr>\n";

$submit_button = makebuttoncode('submit', $lang->convert_database_tables);
}
else
{
starttable();
tableheader($lang->convert_table." {$mybb->input['table']}", 'converttable', 1);
echo "<tr>\n";
echo "<td class=\"subheader\"><strong>".sprintf($lang->convert_to_utf, $mybb->input['table'], $charset)."</strong></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class=\"altbg1\" align=\"center\">{$lang->notice_proccess_long_time}</td>\n";
echo "</tr>\n";

$submit_button = makebuttoncode('submit', $lang->convert_database_table);
}

makelabelcode('<div align="center">'.$submit_button.'</div>');

endtable();
endform();
cpfooter();

exit;
}

$tables = $db->list_tables($config['database']);

$not_okey_count = 0;
$not_okey = array();
$okay_count = 0;

foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
if(fetch_iconv_encoding($matches[1]) != 'utf-8')
{
$not_okey[$key] = $tablename;
++$not_okey_count;
}
else
{
++$okay_count;
}

$mybb_tables[$key] = $tablename;
}
}

asort($mybb_tables);

if($okay_count == count($mybb_tables))
{
cperror($lang->error_all_tables_already_converted);
}

// From here we display a list of tables to convert. This is the first step
if(!$config['db_encoding'])
{
cperror($lang->error_db_encoding_not_set);
}


$hopto[] = "<input type=\"button\" value=\"{$lang->convert_all}\" onclick=\"hopto('dbtools.php?".SID."&amp;action=utf8_conversion&amp;table=all');\" class=\"hoptobutton\" />";
makehoptolinks($hopto);

starttable();
tableheader($lang->utf8_conversion, 'utf8_conversion', 2);
echo "<tr>\n";
echo "<td class=\"subheader\">".$lang->table."</td>\n";
echo "<td class=\"subheader\" align=\"center\">".$lang->status."</td>\n";
echo "</tr>\n";

foreach($mybb_tables as $key => $tablename)
{
if(array_key_exists($key, $not_okey))
{
$status = "<a href=\"dbtools.php?".SID."&amp;action=utf8_conversion&amp;table={$tablename}\">{$lang->convert_now}</a>";
}
else
{
$status = "OK";
}
$bgcolor = getaltbg();
echo "<tr>\n";
echo "<td class=\"$bgcolor\"><strong>{$tablename}</strong></td>\n";
echo "<td class=\"$bgcolor\" align=\"center\" width=\"15%\">{$status}</td>\n";
echo "</tr>\n";
}

endtable();
cpfooter();

}

if($mybb->input['action'] == 'do_delete')

}

if($mybb->input['action'] == 'do_delete')

Zeile 45Zeile 395
			$delete = @unlink(MYBB_ADMIN_DIR.'backups/'.$file);

if($delete)

			$delete = @unlink(MYBB_ADMIN_DIR.'backups/'.$file);

if($delete)

			{

			{

				cpredirect('dbtools.php?'.SID.'&action=existing', $lang->backup_deleted);
}
else

				cpredirect('dbtools.php?'.SID.'&action=existing', $lang->backup_deleted);
}
else

Zeile 81Zeile 431
			}

$fp = gzopen($file.'.gz', 'w9');

			}

$fp = gzopen($file.'.gz', 'w9');

		}
else
{
$fp = fopen($file.'.sql', 'w');
}

		}
else
{
$fp = fopen($file.'.sql', 'w');
}

	}
else
{

	}
else
{

Zeile 106Zeile 456
	}

$time = date('dS F Y \a\t H:i', time());

	}

$time = date('dS F Y \a\t H:i', time());

	$header = "-- MyBB Database Backup\n-- Generated: ".$time."\n---------------------------------------\n\n";

	$header = "-- MyBB Database Backup\n-- Generated: ".$time."\n-- -------------------------------------\n\n";

	$contents = $header;
foreach($mybb->input['tables'] as $table)
{
$field_list = array();
$query = $db->query("SHOW FIELDS FROM ".$table);
while($row = $db->fetch_array($query))

	$contents = $header;
foreach($mybb->input['tables'] as $table)
{
$field_list = array();
$query = $db->query("SHOW FIELDS FROM ".$table);
while($row = $db->fetch_array($query))

		{

		{

			$field_list[] = $row['Field'];
}
$fields = implode(",", $field_list);

			$field_list[] = $row['Field'];
}
$fields = implode(",", $field_list);

Zeile 121Zeile 471
		{
$structure = $db->show_create_table($table).";\n";
$contents .= $structure;

		{
$structure = $db->show_create_table($table).";\n";
$contents .= $structure;

 
			seq_backup($fp, $contents);

		}
if($mybb->input['contents'] != 'structure')
{

		}
if($mybb->input['contents'] != 'structure')
{

Zeile 134Zeile 485
					if(!isset($row[$field]) || trim($row[$field]) == "")
{
$insert .= $comma."''";

					if(!isset($row[$field]) || trim($row[$field]) == "")
{
$insert .= $comma."''";

					}

					}

					else
{
$insert .= $comma."'".$db->escape_string($row[$field])."'";
}
$comma = ',';

					else
{
$insert .= $comma."'".$db->escape_string($row[$field])."'";
}
$comma = ',';

				}

				}

				$insert .= ");\n";
$contents .= $insert;

				$insert .= ");\n";
$contents .= $insert;

 
				seq_backup($fp, $contents);

			}
}
}

			}
}
}

Zeile 153Zeile 505
		{
gzwrite($fp, $contents);
gzclose($fp);

		{
gzwrite($fp, $contents);
gzclose($fp);

		}

		}

		else
{
fwrite($fp, $contents);

		else
{
fwrite($fp, $contents);

Zeile 172Zeile 524
		$file_from_admindir = 'dbtools.php?'.SID.'&amp;action=dlbackup&amp;file='.basename($file).$ext;
$lang->backup_complete = sprintf($lang->backup_complete, $file.$ext, $file_from_admindir);
cpmessage($lang->backup_complete);

		$file_from_admindir = 'dbtools.php?'.SID.'&amp;action=dlbackup&amp;file='.basename($file).$ext;
$lang->backup_complete = sprintf($lang->backup_complete, $file.$ext, $file_from_admindir);
cpmessage($lang->backup_complete);

	}

	}

	else
{
if($mybb->input['type'] == "gzip")

	else
{
if($mybb->input['type'] == "gzip")

Zeile 192Zeile 544
	{
cperror($lang->error_download_no_file);
}

	{
cperror($lang->error_download_no_file);
}

 
	
@set_time_limit(0);

	
$file = basename($mybb->input['file']);
$ext = get_extension($file);

	
$file = basename($mybb->input['file']);
$ext = get_extension($file);

Zeile 217Zeile 571
	{
cperror($lang->error_no_tables_selected);
}

	{
cperror($lang->error_no_tables_selected);
}

 
	
@set_time_limit(0);

	
foreach($mybb->input['tables'] as $table)
{

	
foreach($mybb->input['tables'] as $table)
{

Zeile 248Zeile 604
					"time" => @filemtime(MYBB_ADMIN_DIR.'backups/'.$file),
"type" => $ext
);

					"time" => @filemtime(MYBB_ADMIN_DIR.'backups/'.$file),
"type" => $ext
);

			}

			}

		}
}

		}
}

	

	

	$count = count($backups);

if($count != 0)

	$count = count($backups);

if($count != 0)

	{

	{

		makelabelcode($lang->restore_database_desc, '', 5);
echo "<tr>\n";
echo "<td class=\"subheader\">".$lang->file_name."</td>\n";

		makelabelcode($lang->restore_database_desc, '', 5);
echo "<tr>\n";
echo "<td class=\"subheader\">".$lang->file_name."</td>\n";

Zeile 289Zeile 645
			echo "<td class=\"$bgcolor\" align=\"center\">".$delete_link."</td>\n";
echo "</tr>\n";
}

			echo "<td class=\"$bgcolor\" align=\"center\">".$delete_link."</td>\n";
echo "</tr>\n";
}

	}

	}

	else
{
makelabelcode($lang->no_existing_backups);

	else
{
makelabelcode($lang->no_existing_backups);

Zeile 302Zeile 658
if($mybb->input['action'] == 'delete')
{
if(!$mybb->input['backup'])

if($mybb->input['action'] == 'delete')
{
if(!$mybb->input['backup'])

	{

	{

		$lang->error_no_backup_specified = sprintf($lang->error_no_backup_specified, $lang->deletion);
cperror($lang->error_no_backup_specified);
}

		$lang->error_no_backup_specified = sprintf($lang->error_no_backup_specified, $lang->deletion);
cperror($lang->error_no_backup_specified);
}

Zeile 355Zeile 711
	startform("dbtools.php", "table_selection" , "do_optimize");
starttable();
tableheader($lang->optimize_tables);

	startform("dbtools.php", "table_selection" , "do_optimize");
starttable();
tableheader($lang->optimize_tables);

	tablesubheader($lang->table_selection);
$bgcolor = getaltbg();

	tablesubheader($lang->table_selection);
$bgcolor = getaltbg();

	echo "<tr>\n";
echo "<td class=\"$bgcolor\" valign=\"top\">".$lang->table_selection_desc."<br /><br /><a href=\"javascript:changeSelection('select', 0);\">".$lang->select_all."</a><br /><a href=\"javascript:changeSelection('deselect', 0);\">".$lang->deselect_all."</a><br /><a href=\"javascript:changeSelection('forum', '".TABLE_PREFIX."');\">".$lang->select_forum_tables."</a></td>\n";
echo "<td class=\"$bgcolor\">\n";
echo "<select id=\"table_select\" name=\"tables[]\" size=\"20\" multiple=\"multiple\">\n";
$table_list = $db->list_tables($config['database']);
foreach($table_list as $id => $table_name)

	echo "<tr>\n";
echo "<td class=\"$bgcolor\" valign=\"top\">".$lang->table_selection_desc."<br /><br /><a href=\"javascript:changeSelection('select', 0);\">".$lang->select_all."</a><br /><a href=\"javascript:changeSelection('deselect', 0);\">".$lang->deselect_all."</a><br /><a href=\"javascript:changeSelection('forum', '".TABLE_PREFIX."');\">".$lang->select_forum_tables."</a></td>\n";
echo "<td class=\"$bgcolor\">\n";
echo "<select id=\"table_select\" name=\"tables[]\" size=\"20\" multiple=\"multiple\">\n";
$table_list = $db->list_tables($config['database']);
foreach($table_list as $id => $table_name)

	{

	{

		echo "<option value=\"".$table_name."\" selected=\"selected\">".$table_name."</option>\n";
}
echo "</select>\n";

		echo "<option value=\"".$table_name."\" selected=\"selected\">".$table_name."</option>\n";
}
echo "</select>\n";

Zeile 410Zeile 766
		$lang->update_button = '';
makewarning($lang->note_cannot_write_backup);
$cannot_write = true;

		$lang->update_button = '';
makewarning($lang->note_cannot_write_backup);
$cannot_write = true;

	}

	}

	startform('dbtools.php', 'table_selection', 'do_backup');
starttable();
tableheader($lang->backup_database);

	startform('dbtools.php', 'table_selection', 'do_backup');
starttable();
tableheader($lang->backup_database);

Zeile 424Zeile 780
	foreach($table_list as $id => $table_name)
{
echo "<option value=\"".$table_name."\">".$table_name."</option>\n";

	foreach($table_list as $id => $table_name)
{
echo "<option value=\"".$table_name."\">".$table_name."</option>\n";

	}

	}

	echo "</select>\n";
echo "</td>\n";
echo "</tr>\n";

	echo "</select>\n";
echo "</td>\n";
echo "</tr>\n";

Zeile 437Zeile 793
	{
echo "<label><input type=\"radio\" name=\"type\" value=\"gzip\" checked=\"checked\" /> ".$lang->gzip_compressed."</label><br />\n";
echo "<label><input type=\"radio\" name=\"type\" value=\"text\" /> ".$lang->plain_text."</label>\n";

	{
echo "<label><input type=\"radio\" name=\"type\" value=\"gzip\" checked=\"checked\" /> ".$lang->gzip_compressed."</label><br />\n";
echo "<label><input type=\"radio\" name=\"type\" value=\"text\" /> ".$lang->plain_text."</label>\n";

	}

	}

	else
{
echo "<label><input type=\"radio\" name=\"type\" value=\"text\" checked=\"checked\" /> ".$lang->plain_text."</label>\n";

	else
{
echo "<label><input type=\"radio\" name=\"type\" value=\"text\" checked=\"checked\" /> ".$lang->plain_text."</label>\n";

	}
echo "</td>\n";
echo "</tr>\n";
$bgcolor = getaltbg();

	}
echo "</td>\n";
echo "</tr>\n";
$bgcolor = getaltbg();

	echo "<tr>\n";
echo "<td class=\"$bgcolor\">".$lang->download_save."</td>\n";
echo "<td class=\"$bgcolor\">\n";

	echo "<tr>\n";
echo "<td class=\"$bgcolor\">".$lang->download_save."</td>\n";
echo "<td class=\"$bgcolor\">\n";

Zeile 462Zeile 818
	echo "</td>\n";
echo "</tr>\n";
makeyesnocode($lang->analyse_optimise, 'analyse');

	echo "</td>\n";
echo "</tr>\n";
makeyesnocode($lang->analyse_optimise, 'analyse');

 
	makeyesnocode($lang->sequential_backup, 'sequential_backup');

	endtable();
endform($lang->perform_backup);
cpfooter();

	endtable();
endform($lang->perform_backup);
cpfooter();

 
}

function seq_backup($fp, &$contents)
{
global $mybb;

if($mybb->input['sequential_backup'] == 'yes')
{
if($mybb->input['write'] == 'disk')
{
if($mybb->input['type'] == 'gzip')
{
gzwrite($fp, $contents);
}
else
{
fwrite($fp, $contents);
}
}
else
{
if($mybb->input['type'] == "gzip")
{
echo gzencode($contents);
}
else
{
echo $contents;
}
}

$contents = '';
}

}
?>

}
?>