Kompatibilis:
- IPB v2.3.x
Leírás:
- Az ACP "SQL Management" részhez ad néhány új funkciót, SQL adatbázis visszatöltés, stb...

Szerkesztendő fájlok:
./sources/acp_loaders/acp_pages_admin.php
./sources/action_admin/sql_mysql.php
./sources/lib/admin_functions.php
(Mindhárom fájlt mentsd le a gépedre, készíts másolatot ezekről és azokat szerkeszd majd töltsd vissza, ha bármi probléma adódna akkor van másolatod az eredeti fájlokról!)
---------------------------------------------------------------------------------------------
Nyisd meg: ./sources/acp_loaders/acp_pages_admin.php
Keresd meg ezt a sort: 2 => array( 'SQL Back Up' , 'section=admin&act=sql&code=backup' ), Szúrd be alá: 6 => array( 'SQL Restore' , 'section=admin&act=sql&code=restore' ),
---------------------------------------------------------------------------------------------
Nyisd meg: ./sources/action_admin/sql_mysql.php
Keresd meg ezt a sort: [ function auto_run() ] //----------------------------------------- default: $this->list_index(); break; Szúrd be fölé: case 'restore': $this->show_restore_form(); break; case 'dosaferestore': $this->do_safe_restore(); break;
Keresd meg ezt a sort:
//-----------------------------------------
// Internal handler to return content from table
//-----------------------------------------
Szúrd be fölé:
//-----------------------------------------
// Show Restore Form
//-----------------------------------------
function show_restore_form()
{
$this->ipsclass->admin->page_detail = "This section allows you to restore backup data.";
$this->ipsclass->admin->page_title = "mySQL ".$this->true_version." Restore";
$chars = array( 0 => array( 'ISO-8859-1' , 'ISO-8859-1 West European' ),
1 => array( 'ISO-8859-15', 'ISO-8859-15 West European' ),
2 => array( 'UTF-8' , 'UTF-8 Unicode' ),
3 => array( 'cp866' , 'DOS Russian' ),
4 => array( 'cp1251' , 'Windows Cyrillic' ),
5 => array( 'cp1252' , 'cp1252 West European' ),
6 => array( 'KOI8-R' , 'KOI8-R Relcom Russian' ),
7 => array( 'GB2312' , 'GB2312 Simplified Chinese' ),
8 => array( 'BIG5' , 'Big5 Traditional Chinese' ),
9 => array( 'BIG5-HKSCS' , 'Big5-HKSCS Traditional Chinese' ),
10 => array( 'Shift_JIS' , 'Shift-JIS Japanese' ),
11 => array( 'EUC-JP' , 'EUC-JP Japanese' ),
12 => array('ISO-8859-8' , 'Hebrew' ),
13 => array('ISO-8859-9' , 'Latin5(Turkish)' ),
13 => array('ISO-8859-2' , 'Central and Eastern Europe' ),
14 => array('TIS-620' , 'Thai' ),
);
$this->ipsclass->adskin->td_header[] = array(" ", "57%");
$this->ipsclass->adskin->td_header[] = array(" ", "43%");
$this->ipsclass->html .= "<form action='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=dosaferestore' method='post' name='uploadform' enctype='multipart/form-data' id='uploadform'><input type='hidden' name='MAX_FILE_SIZE' value='10000000000' />";
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "SQL Restore" );
if (isset($this->ipsclass->input['tbl']))
{
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( "<font color='red'><b>Successfully Restored Table</b>: {$this->ipsclass->input['tbl']} (".intval($this->ipsclass->input['rows'])." rows imported)</font>" );
}
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"<b>Upload file from your computer</b><br />Imported file compression will be automatically detected from: none, gzip",
$this->ipsclass->adskin->form_upload(),
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"<b><u>OR</u> enter the filename here</b><br />The file must be uploaded into the forum's root folder and must begin with 'ipb_' and end with either '.sql' or '.sql.gz'",
$this->ipsclass->adskin->form_input( 'file_location' ),
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"<b>Number of records to skip from start</b><br />Bypass the specified number of records (queries) from the input dataset before starting the load.",
$this->ipsclass->adskin->form_input( 'skip_start', 0 ),
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"<b>Number of records to skip from end</b><br />Bypass the specified number of records (queries) from the input dataset before ending the load.",
$this->ipsclass->adskin->form_input( 'skip_end', 0 ),
) );
/*
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"<b>Number of records to be processed per cycle</b><br />Specify number of records that are processed each page. This is important to prevent your database from crashing when importing.",
$this->ipsclass->adskin->form_input( 'thread', 500 ),
) );
*/
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"<b>Character set of the file</b><br />Specifies the character set which was used in file.",
$this->ipsclass->adskin->form_dropdown( 'charset', $chars, 'UTF-8' )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"<b>Overwrite existing data?</b><br />If set to 'yes', the restore will replace existing data with backup data and existing data will be lost.",
$this->ipsclass->adskin->form_yes_no( 'empty_old', 1 ),
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"<b>Delete source file after processing?</b><br />If set to 'yes', the restore will automatically delete the source file when the process done.",
$this->ipsclass->adskin->form_yes_no( 'del_source', 1 ),
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form( "Start Restore" );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
//-----------------------------------------
// Restore my data
//-----------------------------------------
function do_safe_restore()
{
$done = $rows = 0;
$start = intval($this->ipsclass->input['skip_start']);
$end = intval($this->ipsclass->input['skip_end']);
$time = time();
$content = "";
$filename = $this->ipsclass->input['file_location'] ? $this->ipsclass->input['file_location'] : $_FILES['FILE_UPLOAD']['name'];
# Read file
if (empty($filename))
{
$this->ipsclass->main_msg = "No upload file or filename was specified.";
$this->show_restore_form();
}
if (empty($this->ipsclass->input['file_location']))
{
$content = $this->ipsclass->admin->import_xml($filename);
}
else
{
if (! file_exists(ROOT_PATH.$filename))
{
$this->ipsclass->main_msg = "Could not locate the file: ".ROOT_PATH.$filename;
$this->show_restore_form();
}
if (preg_match("/\.gz$/i", $filename))
{
if ($FH = @gzopen(ROOT_PATH.$filename, 'rb'))
{
while (! @gzeof($FH))
{
$content .= @gzread($FH, 1024);
}
@gzclose($FH);
}
}
elseif (preg_match("/\.sql$/i", $filename))
{
if ($FH = @fopen(ROOT_PATH.$filename, 'rb'))
{
$content = @fread($FH, filesize(ROOT_PATH.$filename));
@fclose($FH);
}
}
else
{
$this->ipsclass->main_msg = "Sorry, that is not a valid file extension.";
$this->show_restore_form();
}
}
if (empty($content))
{
$this->ipsclass->main_msg = "Unable to restore: no data detected!";
$this->show_restore_form();
}
# Convert charset if necessary
// $content = html_entity_decode($content, ENT_NOQUOTES, strtolower($this->ipsclass->input['charset']));
# Process..
preg_match_all("/CREATE TABLE \S+\s*\(.*\)[^\n]*;/Us", $content, $tables);
preg_match_all("/INSERT INTO .* VALUES\s*\(.*\);?/mi", $content, $inserts);
$total = count($inserts[0]);
foreach ($tables[0] as $row)
{
preg_match("/^CREATE TABLE (\S+)/i", $row, $matches);
$this->ipsclass->DB->return_die = 1;
$this->ipsclass->DB->sql_drop_table(str_replace("ibf_", "", $matches[1]));
$this->ipsclass->DB->query($row);
if ($this->ipsclass->DB->error != "")
{
$this->ipsclass->main_msg = $this->ipsclass->DB->error;
$this->show_restore_form();
}
}
foreach ($inserts[0] as $row)
{
if (++$done > $start)
{
# Fake header to bypass timeout
$now = time();
if ($now >= $time + 30)
{
$time = $now;
@header('X-pmaPing: Pong');
}
# Overwrite existing data?
if ($this->ipsclass->input['empty_old'] && ($done - $start == 1))
{
preg_match("/^INSERT INTO (\S+)/i", $row, $matches);
$this->ipsclass->DB->query("TRUNCATE TABLE ".$matches[1]);
}
# Start insert into DB
if ($done <= ($total - $end))
{
$rows++;
$this->ipsclass->DB->return_die = 1;
$this->ipsclass->DB->query($row);
if ($this->ipsclass->DB->error != "")
{
$this->ipsclass->main_msg = $this->ipsclass->DB->error;
$this->show_restore_form();
}
}
}
}
$tmp = preg_replace("/(?:\[\d+?\])?\.\S+$/i", "", $filename);
$tmp = strtolower($tmp);
if ($rows == ($total - ($start + $end)))
{
# Delete source file?
if ($this->ipsclass->input['file_location'] && $this->ipsclass->input['del_source'])
{
@unlink(ROOT_PATH.$filename);
}
# Rebuild required caches?
if (stristr($tmp, 'forums'))
{
$this->ipsclass->update_forum_cache();
}
if (stristr($tmp, 'groups'))
{
$lib = $this->ipsclass->load_class(ROOT_PATH.'sources/action_admin/groups.php', 'ad_groups');
$lib->rebuild_group_cache();
unset($lib);
}
if (! stristr($tmp, 'conf_settings_titles'))
{
if (stristr($tmp, 'conf_settings'))
{
$lib = $this->ipsclass->load_class(ROOT_PATH.'sources/action_admin/settings.php', 'ad_settings');
$lib->setting_rebuildcache();
unset($lib);
}
if (stristr($tmp, 'titles'))
{
$lib = $this->ipsclass->load_class(ROOT_PATH.'sources/action_admin/member.php', 'ad_member');
$lib->titles_recache();
unset($lib);
}
}
if (stristr($tmp, 'attachments_type'))
{
$lib = $this->ipsclass->load_class(ROOT_PATH.'sources/action_admin/attachments.php', 'ad_attachments');
$lib->attach_type_rebuildcache();
unset($lib);
}
if (stristr($tmp, 'emoticons'))
{
$lib = $this->ipsclass->load_class(ROOT_PATH.'sources/action_admin/emoticons.php', 'ad_emoticons');
$lib->emoticon_rebuildcache();
unset($lib);
}
if (stristr($tmp, 'languages'))
{
$lib = $this->ipsclass->load_class(ROOT_PATH.'sources/action_admin/languages.php', 'ad_languages');
$lib->rebuild_cache();
unset($lib);
}
}
# Done! o_0 phew..
$this->ipsclass->admin->redirect_noscreen($this->ipsclass->base_url."&{$this->ipsclass->form_code}&code=restore&tbl={$tmp}&rows={$rows}");
}Keresd meg ezt a sort: [ function run_tool() ]
for( $i = 0; $i < $cnt; $i++ )
{
$rows[] = $data[ $fields[$i]->name ];
}
Cseréld le ezzel:
for( $i = 0; $i < $cnt; $i++ )
{
$rows[] = ($this->ipsclass->input['tool'] == 'show create') ? nl2br(htmlspecialchars($data[$fields[$i]->name])) : $data[$fields[$i]->name];
}Keresd meg ezt a sort: [ function list_index() ]
function CheckCheckAll(cb) {
var fmobj = document.theForm;
var TotalBoxes = 0;
var TotalOn = 0;
for (var i=0;i<fmobj.elements.length;i++) {
var e = fmobj.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox')) {
TotalBoxes++;
if (e.checked) {
TotalOn++;
}
}
}
if (TotalBoxes==TotalOn) {fmobj.allbox.checked=true;}
else {fmobj.allbox.checked=false;}
}
Szúrd be alá:
function opt_change(v)
{
var des = new Array();
des['optimize'] = 'OPTIMIZE TABLE should be used if you have deleted a large part of a table or if you have made many changes to a table with variable-length rows (tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns). Deleted rows are maintained in a linked list and subsequent INSERT operations reuse old row positions. You can use OPTIMIZE TABLE to reclaim the unused space and to defragment the data file.<br />In most setups, you need not run OPTIMIZE TABLE at all. Even if you do a lot of updates to variable-length rows, it is not likely that you need to do this more than once a week or month and only on certain tables. Note that MySQL locks the table during the time OPTIMIZE TABLE is running.';
des['repair'] = 'REPAIR TABLE repairs a possibly corrupted table.<br />Normally, you should never have to run this statement. However, if disaster strikes, REPAIR TABLE is very likely to get back all your data from a MyISAM table. If your tables become corrupted often, you should try to find the reason for it, to eliminate the need to use REPAIR TABLE.<br />If the server dies during a REPAIR TABLE operation, it is essential after restarting it that you immediately execute another REPAIR TABLE statement for the table before performing any other operations on it. (It is always a good idea to start by making a backup)<br />In the worst case, you might have a new clean index file without information about the data file, and then the next operation you perform could overwrite the data file. This is an unlikely but possible scenario.';
des['check'] = 'CHECK TABLE checks a table or tables for errors. CHECK TABLE can also check views for problems, such as tables that are referenced in the view definition that no longer exist.<br />In some cases, CHECK TABLE changes the table. This happens if the table is marked as ?corrupted? or ?not closed properly? but CHECK TABLE does not find any problems in the table. In this case, CHECK TABLE marks the table as okay.<br />If a table is corrupted, it is most likely that the problem is in the indexes and not in the data part. All of the preceding check types check the indexes thoroughly and should thus find most errors.';
des['checksum'] = 'CHECKSUM TABLE reports a table checksum.';
des['analyze'] = 'ANALYZE TABLE analyzes and stores the key distribution for a table. During the analysis, the table is locked with a read lock. If the table has not changed since the last ANALYZE TABLE statement, the table is not analyzed again.';
des['show create'] = 'Shows the CREATE TABLE statement that creates the given table.';
document.getElementById('desc_span').innerHTML = des[v];
}Keresd meg ezt a sort: [ function list_index() ]
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b><span style='font-size:12px'><a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=runsql&query=".urlencode("SELECT * FROM {$r['Name']}")."'>{$r['Name']}</a></span></b>",
Cseréld le ezzel:
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b><span style='font-size:12px'><a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=runsql&query=".urlencode("SELECT * FROM {$r['Name']}")."'>{$r['Name']}</a></span></b><div class='desctext'>Modified: {$r['Update_time']}</div>",Keresd meg ezt a sort: [ function list_index() ] $this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( "<select id='button' name='tool'> <option value='optimize'>Optimize Selected Tables</option> <option value='repair'>Repair Selected Tables</option> <option value='check'>Check Selected Tables</option> <option value='analyze'>Analyze Selected Tables</option> </select> <input type='submit' value='Go!' class='realbutton'></form>", "center", "tablerow2" ); Cseréld le ezzel: $this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( "<select id='button' name='tool' onchange='opt_change(this.options[this.selectedIndex].value)' onfocus='opt_change(this.options[this.selectedIndex].value)'> <option value='optimize'>Optimize Selected Tables</option> <option value='repair'>Repair Selected Tables</option> <option value='check'>Check Selected Tables</option> <option value='checksum'>Checksum Selected Tables</option> <option value='analyze'>Analyze Selected Tables</option> <option value='show create'>Show Create Selected Tables</option> </select> <input type='submit' value='Go!' class='realbutton' /></form>", "center", "tablerow2" ); $this->ipsclass->html .= "<tr><td class='tablerow2' colspan='4'><span id='desc_span'> </span></td></tr>";
---------------------------------------------------------------------------------------------
Nyisd meg: ./sources/lib/admin_functions.php
Keresd meg ezt a sort: [ function import_xml( $infilename ) ] //----------------------------------------- // Allowed file-types //----------------------------------------- $allowed_files = array( 'xml', 'gz' ); Cseréld le ezzel: //----------------------------------------- // Allowed file-types //----------------------------------------- $allowed_files = array( 'xml', 'gz', 'sql' );
-----------------------------------------------------------------------------------------
Figyelem!!!
Ki nem próbáltam (még) az adatbázis visszatöltést ebben a formában, csak a módosítást csináltam meg, szóval arról fogalmam sincs jelenleg, hogy ugyan úgy megcsinálja-e mint a phpmyadmin felület! Ha valaki kipróbálta és sikerült (vagy nem) az jelezze itt, köszi!
Szerkesztve ashiaor666 által: 2008 december 03 - 07:12

Súgó












