1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 11:50:30 +02:00

Xml DB import work, + db_Replace() function added to mySql class. ie. REPLACE INTO etc..

This commit is contained in:
CaMer0n
2009-08-29 18:07:42 +00:00
parent b3fa166ae7
commit 9c16c71089
2 changed files with 87 additions and 15 deletions

View File

@@ -9,8 +9,8 @@
* Administration - Database Utilities * Administration - Database Utilities
* *
* $Source: /cvs_backup/e107_0.8/e107_admin/db.php,v $ * $Source: /cvs_backup/e107_0.8/e107_admin/db.php,v $
* $Revision: 1.23 $ * $Revision: 1.24 $
* $Date: 2009-08-29 15:30:41 $ * $Date: 2009-08-29 18:07:42 $
* $Author: e107coders $ * $Author: e107coders $
* *
*/ */
@@ -125,10 +125,7 @@ class system_tools
//TODO Merge db_verify.php into db.php //TODO Merge db_verify.php into db.php
if(!vartrue($_GET['mode']))
{
$this->render_options();
}
if(isset($_POST['delplug'])) if(isset($_POST['delplug']))
{ {
@@ -180,7 +177,10 @@ class system_tools
$this->plugin_viewscan(); $this->plugin_viewscan();
} }
if(!vartrue($_GET['mode']))
{
$this->render_options();
}
} }
@@ -412,6 +412,7 @@ class system_tools
// SecretR - structure changes / improvements proposal // SecretR - structure changes / improvements proposal
$xmlArray = e107::getSingleton('xmlClass')->loadXMLfile($_FILES['file_userfile']['tmp_name'][0],'advanced'); $xmlArray = e107::getSingleton('xmlClass')->loadXMLfile($_FILES['file_userfile']['tmp_name'][0],'advanced');
$emessage = eMessage::getInstance();
if(vartrue($xmlArray['prefs']['core'])) // Save Core Prefs if(vartrue($xmlArray['prefs']['core'])) // Save Core Prefs
{ {
@@ -423,6 +424,38 @@ class system_tools
} }
e107::getConfig()->save(FALSE); e107::getConfig()->save(FALSE);
}
if(vartrue($xmlArray['database']))
{
foreach($xmlArray['database']['dbTable'] as $val)
{
$table = $val['@attributes']['name'];
foreach($val['item'] as $item)
{
$insert_array = array();
foreach($item['field'] as $f)
{
$fieldkey = $f['@attributes']['name'];
$fieldval = $f['@value'];
$insert_array[$fieldkey] = $fieldval;
}
if(e107::getDB()->db_Replace($table, $insert_array)!==FALSE)
{
$emessage->add("Inserted $table", E_MESSAGE_SUCCESS);
}
else
{
$emessage->add("Failed to Inserted $table", E_MESSAGE_ERROR);
}
}
}
} }
} }
@@ -753,7 +786,8 @@ function table_list()
$exclude[] = "online"; $exclude[] = "online";
$exclude[] = "upload"; $exclude[] = "upload";
$exclude[] = "user_extended_country"; $exclude[] = "user_extended_country";
$exclude[] = "plugin";
/* /*
$exclude[] = "banlist"; $exclude[] = "banner"; $exclude[] = "banlist"; $exclude[] = "banner";

View File

@@ -9,9 +9,9 @@
* mySQL Handler * mySQL Handler
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
* $Revision: 1.39 $ * $Revision: 1.40 $
* $Date: 2009-07-17 14:20:26 $ * $Date: 2009-08-29 18:07:42 $
* $Author: marj_nl_fr $ * $Author: e107coders $
*/ */
if(defined('MYSQL_LIGHT')) if(defined('MYSQL_LIGHT'))
@@ -44,8 +44,8 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
* MySQL Abstraction class * MySQL Abstraction class
* *
* @package e107 * @package e107
* @version $Revision: 1.39 $ * @version $Revision: 1.40 $
* @author $Author: marj_nl_fr $ * @author $Author: e107coders $
*/ */
class db { class db {
@@ -353,7 +353,7 @@ class db {
/** /**
* @return int Last insert ID or false on error * @return int Last insert ID or false on error
* @param string $table * @param string $table
* @param string $arg * @param string/array $arg
* @param string $debug * @param string $debug
* @desc Insert a row into the table<br /> * @desc Insert a row into the table<br />
* <br /> * <br />
@@ -368,6 +368,16 @@ class db {
$this->mySQLcurTable = $table; $this->mySQLcurTable = $table;
if(is_array($arg)) if(is_array($arg))
{ {
if(isset($arg['_REPLACE']))
{
$REPLACE = TRUE;
unset($arg['_REPLACE']);
}
else
{
$REPLACE = FALSE;
}
if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data'])) if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data']))
{ {
//Convert data if not using 'new' format //Convert data if not using 'new' format
@@ -378,6 +388,7 @@ class db {
} }
if(!isset($arg['data'])) { return false; } if(!isset($arg['data'])) { return false; }
$fieldTypes = $this->_getTypes($arg); $fieldTypes = $this->_getTypes($arg);
$keyList= '`'.implode('`,`', array_keys($arg['data'])).'`'; $keyList= '`'.implode('`,`', array_keys($arg['data'])).'`';
$tmp = array(); $tmp = array();
@@ -387,7 +398,16 @@ class db {
} }
$valList= implode(', ', $tmp); $valList= implode(', ', $tmp);
unset($tmp); unset($tmp);
$query = "INSERT INTO `".$this->mySQLPrefix."{$table}` ({$keyList}) VALUES ({$valList})";
if($REPLACE === FALSE)
{
$query = "INSERT INTO `".$this->mySQLPrefix."{$table}` ({$keyList}) VALUES ({$valList})";
}
else
{
$query = "REPLACE INTO `".$this->mySQLPrefix."{$table}` ({$keyList}) VALUES ({$valList})";
}
} }
else else
{ {
@@ -413,6 +433,24 @@ class db {
} }
} }
/**
* @return int Last insert ID or false on error
* @param string $table
* @param array $arg
* @param string $debug
* @desc Insert/REplace a row into the table<br />
* <br />
* Example:<br />
* <code>$sql->db_Replace("links", $array);</code>
*
* @access public
*/
function db_Replace($table, $arg, $debug = FALSE, $log_type = '', $log_remark = '')
{
$arg['_REPLACE'] = TRUE;
$this->db_Insert($table, $arg, $debug, $log_type, $log_remark);
}
/** /**
* @return int number of affected rows, or false on error * @return int number of affected rows, or false on error