1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-14 17:42:10 +02:00

db-verify routines moved to class and integrated into main admin->database page.

This commit is contained in:
CaMer0n 2011-06-08 03:16:47 +00:00
parent ed6a097805
commit dbf47650bc
4 changed files with 136 additions and 172 deletions

View File

@ -8,9 +8,9 @@
*
* Administration - Database Utilities
*
* $Source: /cvs_backup/e107_0.8/e107_admin/db.php,v $
* $URL$
* $Revision$
* $Date$
* $Id$
* $Author$
*
*/
@ -31,30 +31,29 @@ if(isset($_POST['back']))
exit();
}
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
$e_sub_cat = 'database';
require_once (e_HANDLER."form_handler.php");
$frm = new e_form();
require_once (e_HANDLER."message_handler.php");
$emessage = &eMessage::getInstance();
$frm = e107::getForm();
$mes = e107::getMessage();
/*
* Execute trigger
*/
if(isset($_POST['trigger_db_execute']))
if(isset($_POST['db_execute']))
{
$type = key($_POST['db_execute']);
if(!varset($_POST['db_execute']))
{
$emessage->add(DBLAN_53, E_MESSAGE_WARNING);
$mes->add(DBLAN_53, E_MESSAGE_WARNING);
}
else
{
$_POST[$_POST['db_execute']] = true;
$_POST[$type] = true;
}
}
@ -64,25 +63,20 @@ if(isset($_POST['db_update']) || varset($_GET['mode'])=='db_update')
exit();
}
if(isset($_POST['verify_sql']) || varset($_GET['mode'])=='verify_sql')
{
header("location: ".e_ADMIN."db_verify.php");
exit();
}
if(isset($_POST['exportXmlFile']))
{
if(exportXmlFile($_POST['xml_prefs'],$_POST['xml_tables'],$_POST['package_images']))
{
$emessage = eMessage::getInstance();
$emessage->add(LAN_SUCCESS, E_MESSAGE_SUCCESS);
$mes = eMessage::getInstance();
$mes->add(LAN_SUCCESS, E_MESSAGE_SUCCESS);
}
}
require_once ("auth.php");
require_once (e_HANDLER."form_handler.php");
$frm = new e_form();
$st = new system_tools;
@ -136,7 +130,6 @@ class system_tools
//TODO Merge db_verify.php into db.php
if(isset($_POST['delplug']))
{
$this->delete_plugin_entry($_POST['pref_type']);
@ -151,10 +144,18 @@ class system_tools
{
$this->del_pref_val($_POST['pref_type']);
}
if(isset($_POST['verify_sql']) || varset($_GET['mode'])=='verify_sql')
{
require_once(e_HANDLER."db_verify_class.php");
$dbv = new db_verify;
return;
}
if(isset($_POST['verify_sql_record']) || varset($_GET['mode'])=='verify_sql_record' || isset($_POST['check_verify_sql_record']) || isset($_POST['delete_verify_sql_record']))
{
// $this->verify_sql_record(); - currently performed in db_verify.php
//$this->verify_sql_record(); // - currently performed in db_verify_class.php
}
if(isset($_POST['importForm']) || $_GET['mode']=='importForm')
@ -197,9 +198,10 @@ class system_tools
if(vartrue($_POST['perform_utf8_convert']))
{
$this->perform_utf8_convert();
return;
}
if(!vartrue($_GET['mode']))
if(!vartrue($_GET['mode']) && !isset($_POST['db_execute']))
{
$this->render_options();
}
@ -427,7 +429,7 @@ class system_tools
*/
private function render_options()
{
$frm = e107::getSingleton('e_form');
$frm = e107::getForm();
$text = "
<form method='post' action='".e_SELF."' id='core-db-main-form'>
@ -445,7 +447,11 @@ class system_tools
$text .= "<tr>
<td>".$val['diz']."</td>
<td>
".$frm->radio('db_execute', $key).$frm->label($val['label'], 'db_execute', $key)."
<a href='".e_SELF."?mode=".$key."' title=\"".$val['label']."\">".ADMIN_EXECUTE_ICON."</a>
".
// $frm->submit_image('db_execute['.$key.']', '1', 'execute', $val['label']).
// $frm->radio('db_execute', $key).$frm->label($val['label'], 'db_execute', $key).
"
</td>
</tr>\n";
@ -454,16 +460,17 @@ class system_tools
$text .= "
</tbody>
</table>
<div class='buttons-bar center'>
".$frm->admin_button('trigger_db_execute', DBLAN_51, 'execute')."
</div>
</table>";
// $text .= "<div class='buttons-bar center'>
// ".$frm->admin_button('trigger_db_execute', DBLAN_51, 'execute')."
// </div>";
$text .= "
</fieldset>
</form>
";
$emessage = eMessage::getInstance();
e107::getRender()->tablerender(DBLAN_10, $emessage->render().$text);
$mes = e107::getMessage();
e107::getRender()->tablerender(DBLAN_10, $mes->render().$text);
}

View File

@ -6,48 +6,18 @@
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Administration - DB Verify
* Administration - DB Verify Class
*
* $Source: /cvs_backup/e107_0.8/e107_admin/db_verify.php,v $
* $Revision$
* $Date$
* $Author$
* $URL: /cvs_backup/e107_0.8/e107_admin/db_verify.php,v $
* $Revision: 12255 $
* $Id: 2011-06-07 17:16:42 -0700 (Tue, 07 Jun 2011) $
* $Author: e107coders $
*
*/
require_once("../class2.php");
if(varset($_POST['db_tools_back']))
{
header("Location:".e_ADMIN_ABS."db.php");
exit;
}
if (!defined('e107_INIT')) { exit; }
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
$e_sub_cat = 'database';
require_once("auth.php");
if (!$sql_data)
{
// exit(DBLAN_1);
}
if (!getperms("0"))
{
header("Location:".SITEURL."index.php");
exit;
}
$dbv = new db_verify;
// print_a($dbv->tables);
require_once(e_ADMIN."footer.php");
exit;
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_db_verify.php');
class db_verify
{
@ -83,7 +53,7 @@ class db_verify
}
else
{
$emessage->add($filename.DBLAN_22, E_MESSAGE_WARNING);
$emessage->add($filename.DBVLAN_22, E_MESSAGE_WARNING);
}
}
@ -104,8 +74,8 @@ class db_verify
}
else
{
$mes->add("Tables appear to be okay!",E_MESSAGE_SUCCESS);
$text .= "<div class='buttons-bar center'>".$frm->admin_button('back', DBLAN_17, 'back')."</div>";
$mes->add("Tables appear to be okay!",E_MESSAGE_SUCCESS); //TODO LAN
//$text .= "<div class='buttons-bar center'>".$frm->admin_button('back', DBVLAN_17, 'back')."</div>";
$ns->tablerender("Okay",$mes->render().$text);
}
@ -155,11 +125,15 @@ class db_verify
$fileIndexData = $this->getIndex($this->tables[$selection]['data'][$key]);
$sqlIndexData = $this->getIndex($sqlDataArr['data'][0]);
// $debugA = print_r($fileFieldData,TRUE); // Extracted Field Arrays
// $debugB = print_r($sqlFieldData,TRUE); // Extracted Field Arrays
$debugA = print_r($fileFieldData,TRUE); // Extracted Field Arrays
$debugA .= "<h2>Index</h2>";
$debugA .= print_r($fileIndexData,TRUE);
$debugB = print_r($sqlFieldData,TRUE); // Extracted Field Arrays
$debugB .= "<h2>Index</h2>";
$debugB .= print_r($sqlIndexData,TRUE);
$debugA = $this->tables[$selection]['data'][$key]; // Extracted Raw Field Text
$debugB = $sqlDataArr['data'][0]; // Extracted Raw Field Text
// $debugA = $this->tables[$selection]['data'][$key]; // Extracted Raw Field Text
// $debugB = $sqlDataArr['data'][0]; // Extracted Raw Field Text
if($debugA)
{
@ -266,9 +240,9 @@ class db_verify
$mes = e107::getMessage();
$text = "
<form method='post' action='".e_SELF."'>
<form method='post' action='".e_SELF."?".e_QUERY."'>
<fieldset id='core-db-verify-{$selection}'>
<legend id='core-db-verify-{$selection}-legend'>".DBLAN_16." - $what ".DBLAN_18."</legend>
<legend id='core-db-verify-{$selection}-legend'>".DBVLAN_16." - $what ".DBVLAN_18."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='4'>
@ -280,22 +254,22 @@ class db_verify
</colgroup>
<thead>
<tr>
<th>".DBLAN_4.": {$k}</th>
<th>".DBLAN_5."</th>
<th class='center'>".DBLAN_6."</th>
<th>".DBLAN_7."</th>
<th class='center last'>".DBLAN_19."</th>
<th>".DBVLAN_4.": {$k}</th>
<th>".DBVLAN_5."</th>
<th class='center'>".DBVLAN_6."</th>
<th>".DBVLAN_7."</th>
<th class='center last'>".DBVLAN_19."</th>
</tr>
</thead>
<tbody>
";
$info = array(
'missing_table' => DBLAN_13,
'mismatch' => DBLAN_8,
'missing_field' => DBLAN_11,
'missing_table' => DBVLAN_13,
'mismatch' => DBVLAN_8,
'missing_field' => DBVLAN_11,
'ok' => ADMIN_TRUE_ICON,
'missing_index' => DBLAN_25,
'missing_index' => DBVLAN_25,
);
$modes = array(
@ -383,9 +357,9 @@ class db_verify
";
$text .= "
<div class='buttons-bar right'>
".$frm->admin_button('runfix', DBLAN_21, 'execute', '', array('id'=>false))."
".$frm->admin_button('check_all', 'jstarget:fix_active', 'action', LAN_CHECKALL, array('id'=>false))."
".$frm->admin_button('uncheck_all', 'jstarget:fix_active', 'action', LAN_UNCHECKALL, array('id'=>false))."
".$frm->admin_button('runfix', DBVLAN_21, 'execute', '', array('id'=>false))."
".$frm->admin_button('check_all', 'jstarget:fix', 'action', LAN_CHECKALL, array('id'=>false))."
".$frm->admin_button('uncheck_all', 'jstarget:fix', 'action', LAN_UNCHECKALL, array('id'=>false))."
</div>
</fieldset>
@ -393,7 +367,7 @@ class db_verify
";
$ns->tablerender(DBLAN_23.' - '.DBLAN_16, $mes->render().$text);
$ns->tablerender(DBVLAN_23.' - '.DBVLAN_16, $mes->render().$text);
}
@ -431,11 +405,11 @@ class db_verify
$text = "";
if($invalid)
{
$text .= "<strong>".DBLAN_9."</strong>
$text .= "<strong>".DBVLAN_9."</strong>
<div class='indent'>".$invalid."</div>";
}
$text .= "<strong>".DBLAN_10."</strong>
$text .= "<strong>".DBVLAN_10."</strong>
<div class='indent'>".$valid."</div>";
return $text;
@ -653,7 +627,8 @@ class db_verify
function getIndex($data)
{
$regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?`?([\w,]*[\s]?)`?\))?,?/i";
// $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?`?([\w,]*[\s]?)`?\))?,?/i";
$regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w,`]*[\s]?)`?\))?,?/i";
preg_match_all($regex,$data,$m);
$ret = array();
@ -662,10 +637,11 @@ class db_verify
foreach($m[3] as $k=>$val)
{
$val = str_replace("`","",$val);
$ret[$val] = array(
'type' => strtoupper($m[1][$k]),
'keyname' => (vartrue($m[2][$k])) ? $m[2][$k] : $m[3][$k],
'field' => $m[3][$k]
'keyname' => (vartrue($m[2][$k])) ? str_replace("`","",$m[2][$k]) : str_replace("`","",$m[3][$k]),
'field' => str_replace("`","",$m[3][$k])
);
}
@ -738,14 +714,14 @@ class db_verify
$text = "
<form method='post' action='".e_SELF.(e_QUERY ? '?'.e_QUERY : '')."' id='core-db-verify-sql-tables-form'>
<fieldset id='core-db-verify-sql-tables'>
<legend>".DBLAN_14."</legend>
<legend>".DBVLAN_14."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='1'>
<col style='width: 100%'></col>
</colgroup>
<thead>
<tr>
<th class='last'>".$frm->checkbox_toggle('check-all-verify', 'table_').LAN_CHECKALL.' | '.LAN_UNCHECKALL."</th>
<th class='last'>".$frm->checkbox_toggle('check-all-verify', 'verify_table').LAN_CHECKALL.' | '.LAN_UNCHECKALL."</th>
</tr>
</thead>
<tbody>
@ -764,14 +740,14 @@ class db_verify
</tbody>
</table>
<div class='buttons-bar center'>
".$frm->admin_button('db_verify', DBLAN_15)."
".$frm->admin_button('db_tools_back', DBLAN_17, 'back')."
".$frm->admin_button('db_verify', DBVLAN_15)."
".$frm->admin_button('db_tools_back', DBVLAN_17, 'back')."
</div>
</fieldset>
</form>
";
$ns->tablerender(DBLAN_23.' - '.DBLAN_16, $mes->render().$text);
$ns->tablerender(DBVLAN_23.' - '.DBVLAN_16, $mes->render().$text);
}
@ -798,7 +774,7 @@ function check_tables($what)
$text = "
<form method='post' action='".e_SELF."'>
<fieldset id='core-db-verify-{$what}'>
<legend id='core-db-verify-{$what}-legend'>".DBLAN_16." - $what ".DBLAN_18."</legend>
<legend id='core-db-verify-{$what}-legend'>".DBVLAN_16." - $what ".DBVLAN_18."</legend>
";
foreach(array_keys($table_list) as $k)
{ // $k is the DB table name (less prefix)
@ -814,11 +790,11 @@ function check_tables($what)
</colgroup>
<thead>
<tr>
<th>".DBLAN_4.": {$k}</th>
<th>".DBLAN_5."</th>
<th class='center'>".DBLAN_6."</th>
<th>".DBLAN_7."</th>
<th class='center last'>".DBLAN_19."</th>
<th>".DBVLAN_4.": {$k}</th>
<th>".DBVLAN_5."</th>
<th class='center'>".DBVLAN_6."</th>
<th>".DBVLAN_7."</th>
<th class='center last'>".DBVLAN_19."</th>
</tr>
</thead>
<tbody>
@ -954,11 +930,11 @@ function check_tables($what)
if ($fld_err)
{
$body_txt .= "
<td class='center middle error'>".DBLAN_8."</td>
<td class='center middle error'>".DBVLAN_8."</td>
<td>
<strong>".DBLAN_9."</strong>
<strong>".DBVLAN_9."</strong>
<div class='indent'>{$xfparams}</div>
<strong>".DBLAN_10."</strong>
<strong>".DBVLAN_10."</strong>
<div class='indent'>{$fparams}</div>
</td>
<td class='center middle autocheck e-pointer'>".fix_form($k, $fname, $fparams, "alter")."</td>
@ -970,11 +946,11 @@ function check_tables($what)
elseif ($fieldnum != $xfieldnum)
{ // Field numbers different - missing field?
$body_txt .= "
<td class='center middle error'>".DBLAN_5." ".DBLAN_8."</td>
<td class='center middle error'>".DBVLAN_5." ".DBVLAN_8."</td>
<td>
<strong>".DBLAN_9.": </strong>#{$xfieldnum}
<strong>".DBVLAN_9.": </strong>#{$xfieldnum}
<br />
<strong>".DBLAN_10.": </strong>#{$fieldnum}
<strong>".DBVLAN_10.": </strong>#{$fieldnum}
</td>
<td class='center middle'>&nbsp;</td>
@ -999,9 +975,9 @@ function check_tables($what)
{
$prev_fname = $fname; //FIXME - wrong $prev_fname!
$body_txt .= "
<td class='center middle error'>".DBLAN_11."</td>
<td class='center middle error'>".DBVLAN_11."</td>
<td>
<strong>".DBLAN_10."</strong>
<strong>".DBVLAN_10."</strong>
<div class='indent'>{$fparams}</div>
</td>
<td class='center middle autocheck e-pointer'>".fix_form($k, $fname, $fparams, "insert", $prev_fname)."</td>
@ -1030,7 +1006,7 @@ function check_tables($what)
<tr>
<td>$k</td>
<td>$tf</td>
<td class='center middle'>".DBLAN_12."</td>
<td class='center middle'>".DBVLAN_12."</td>
<td>&nbsp;</td>
<td class='center middle autocheck e-pointer'>".fix_form($k, $tf, $fparams, "drop")."</td>
</tr>
@ -1046,7 +1022,7 @@ function check_tables($what)
<tr>
<td>{$k}</td>
<td>&nbsp;</td>
<td class='center middle error'>".DBLAN_13."</td>
<td class='center middle error'>".DBVLAN_13."</td>
<td>&nbsp;</td>
<td class='center middle autocheck e-pointer'>".fix_form($k, $tf, $tablines[$k], "create") . "</td>
</tr>
@ -1100,7 +1076,7 @@ function check_tables($what)
{
$text .= "
<div class='buttons-bar right'>
".$frm->admin_button('do_fix', DBLAN_21, 'execute', '', array('id'=>false))."
".$frm->admin_button('do_fix', DBVLAN_21, 'execute', '', array('id'=>false))."
".$frm->admin_button('check_all', 'jstarget:fix_active', 'action', LAN_CHECKALL, array('id'=>false))."
".$frm->admin_button('uncheck_all', 'jstarget:fix_active', 'action', LAN_UNCHECKALL, array('id'=>false))."
</div>
@ -1120,7 +1096,7 @@ function check_tables($what)
$text .= "
</fieldset>
<div class='buttons-bar center'>
".$frm->admin_button('back', DBLAN_17, 'back')."
".$frm->admin_button('back', DBVLAN_17, 'back')."
</div>
</form>
@ -1135,7 +1111,7 @@ global $table_list;
if(isset($_POST['do_fix']))
{
//$emessage->add(DBLAN_20);
//$emessage->add(DBVLAN_20);
foreach( $_POST['fix_active'] as $key=>$val)
{
@ -1213,7 +1189,7 @@ if(isset($_POST['do_fix']))
$text = "
<form method='post' action='".e_SELF.(e_QUERY ? '?'.e_QUERY : '')."' id='core-db-verify-sql-tables-form'>
<fieldset id='core-db-verify-sql-tables'>
<legend>".DBLAN_14."</legend>
<legend>".DBVLAN_14."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='1'>
<col style='width: 100%'></col>
@ -1240,14 +1216,14 @@ $text .= "
</tbody>
</table>
<div class='buttons-bar center'>
".$frm->admin_button('db_verify', DBLAN_15)."
".$frm->admin_button('db_tools_back', DBLAN_17, 'back')."
".$frm->admin_button('db_verify', DBVLAN_15)."
".$frm->admin_button('db_tools_back', DBVLAN_17, 'back')."
</div>
</fieldset>
</form>
";
$e107->ns->tablerender(DBLAN_23.' - '.DBLAN_16, $emessage->render().$text);
$e107->ns->tablerender(DBVLAN_23.' - '.DBVLAN_16, $emessage->render().$text);
require_once(e_ADMIN."footer.php");
exit;
@ -1343,29 +1319,6 @@ function table_list()
return $tabs;
}
*/
/**
* Handle page DOM within the page header
*
* @return string JS source
*/
function headerjs()
{
require_once (e_HANDLER.'js_helper.php');
$ret = "
<script type='text/javascript'>
if(typeof e107Admin == 'undefined') var e107Admin = {}
/**
* OnLoad Init Control
*/
e107Admin.initRules = {
'Helper': true,
'AdminMenu': false
}
</script>
<script type='text/javascript' src='".e_FILE_ABS."jslib/core/admin.js'></script>
";
return $ret;
}
?>

View File

@ -318,6 +318,7 @@ define("LAN_VISIBILITY", "Visibility");
define("LAN_ICON", "Icon");
define("LAN_LOADING", "Loading...");
define("LAN_FILE", "File");
define("LAN_EXECUTE","Execute");
define("LAN_SECURITYL_0", "Looking for troubles (none)");

View File

@ -9,29 +9,32 @@
| $Author$
+----------------------------------------------------------------------------+
*/
define("DBLAN_1", "Unable to read the sql datafile<br /><br />Please ensure the file <b>core_sql.php</b> exists in the <b>/admin/sql</b> directory.");
define("DBVLAN_1", "Unable to read the sql datafile<br /><br />Please ensure the file <b>core_sql.php</b> exists in the <b>/admin/sql</b> directory.");
// define("DBLAN_2", "Verifying all");
define("DBLAN_4", "Table");
define("DBLAN_5", "Field");
define("DBLAN_6", "Status");
define("DBLAN_7", "Notes");
define("DBLAN_8", "Mismatch");
define("DBLAN_9", "Currently");
define("DBLAN_10", "should be");
define("DBLAN_11", "Field missing!");
define("DBLAN_12", "Extra Field!");
define("DBLAN_13", "Table missing!");
define("DBLAN_14", "Choose table(s) to validate");
define("DBLAN_15", "Start Verify");
define("DBLAN_16", "SQL Verification");
define("DBLAN_17", "Back");
define("DBLAN_18", "tables");
define("DBLAN_19", "Attempt to Fix");
define("DBLAN_20", "Attempting to fix tables");
define("DBLAN_21", "Fix Selected Items");
define("DBLAN_22", " is not readable");
define("DBLAN_23", "Database Utilities");
define("DBLAN_24", "Please select action.");
define("DBLAN_25", "Index missing!");
define("DBVLAN_4", "Table");
define("DBVLAN_5", "Field");
define("DBVLAN_6", "Status");
define("DBVLAN_7", "Notes");
define("DBVLAN_8", "Mismatch");
define("DBVLAN_9", "Currently");
define("DBVLAN_10", "should be");
define("DBVLAN_11", "Field missing!");
define("DBVLAN_12", "Extra Field!");
define("DBVLAN_13", "Table missing!");
define("DBVLAN_14", "Choose table(s) to validate");
define("DBVLAN_15", "Start Verify");
define("DBVLAN_16", "SQL Verification");
define("DBVLAN_17", "Back");
define("DBVLAN_18", "tables");
define("DBVLAN_19", "Attempt to Fix");
define("DBVLAN_20", "Attempting to fix tables");
define("DBVLAN_21", "Fix Selected Items");
define("DBVLAN_22", " is not readable");
define("DBVLAN_23", "Database Utilities");
define("DBVLAN_24", "Please select action.");
define("DBVLAN_25", "Index missing!");
// IMPORTANT NOTE: DBLAN has been replaced by DBBLAN in this file since 0.7 due to conflicts with db.php
?>