mirror of
https://github.com/e107inc/e107.git
synced 2025-01-29 10:38:08 +01:00
Xml DB import work, + db_Replace() function added to mySql class. ie. REPLACE INTO etc..
This commit is contained in:
parent
b3fa166ae7
commit
9c16c71089
@ -9,8 +9,8 @@
|
||||
* Administration - Database Utilities
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_admin/db.php,v $
|
||||
* $Revision: 1.23 $
|
||||
* $Date: 2009-08-29 15:30:41 $
|
||||
* $Revision: 1.24 $
|
||||
* $Date: 2009-08-29 18:07:42 $
|
||||
* $Author: e107coders $
|
||||
*
|
||||
*/
|
||||
@ -125,10 +125,7 @@ class system_tools
|
||||
|
||||
//TODO Merge db_verify.php into db.php
|
||||
|
||||
if(!vartrue($_GET['mode']))
|
||||
{
|
||||
$this->render_options();
|
||||
}
|
||||
|
||||
|
||||
if(isset($_POST['delplug']))
|
||||
{
|
||||
@ -180,7 +177,10 @@ class system_tools
|
||||
$this->plugin_viewscan();
|
||||
}
|
||||
|
||||
|
||||
if(!vartrue($_GET['mode']))
|
||||
{
|
||||
$this->render_options();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -412,6 +412,7 @@ class system_tools
|
||||
// SecretR - structure changes / improvements proposal
|
||||
|
||||
$xmlArray = e107::getSingleton('xmlClass')->loadXMLfile($_FILES['file_userfile']['tmp_name'][0],'advanced');
|
||||
$emessage = eMessage::getInstance();
|
||||
|
||||
if(vartrue($xmlArray['prefs']['core'])) // Save Core Prefs
|
||||
{
|
||||
@ -423,6 +424,38 @@ class system_tools
|
||||
}
|
||||
|
||||
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[] = "upload";
|
||||
$exclude[] = "user_extended_country";
|
||||
|
||||
$exclude[] = "plugin";
|
||||
|
||||
|
||||
/*
|
||||
$exclude[] = "banlist"; $exclude[] = "banner";
|
||||
|
@ -9,9 +9,9 @@
|
||||
* mySQL Handler
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
|
||||
* $Revision: 1.39 $
|
||||
* $Date: 2009-07-17 14:20:26 $
|
||||
* $Author: marj_nl_fr $
|
||||
* $Revision: 1.40 $
|
||||
* $Date: 2009-08-29 18:07:42 $
|
||||
* $Author: e107coders $
|
||||
*/
|
||||
|
||||
if(defined('MYSQL_LIGHT'))
|
||||
@ -44,8 +44,8 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
|
||||
* MySQL Abstraction class
|
||||
*
|
||||
* @package e107
|
||||
* @version $Revision: 1.39 $
|
||||
* @author $Author: marj_nl_fr $
|
||||
* @version $Revision: 1.40 $
|
||||
* @author $Author: e107coders $
|
||||
*/
|
||||
class db {
|
||||
|
||||
@ -353,7 +353,7 @@ class db {
|
||||
/**
|
||||
* @return int Last insert ID or false on error
|
||||
* @param string $table
|
||||
* @param string $arg
|
||||
* @param string/array $arg
|
||||
* @param string $debug
|
||||
* @desc Insert a row into the table<br />
|
||||
* <br />
|
||||
@ -368,6 +368,16 @@ class db {
|
||||
$this->mySQLcurTable = $table;
|
||||
if(is_array($arg))
|
||||
{
|
||||
if(isset($arg['_REPLACE']))
|
||||
{
|
||||
$REPLACE = TRUE;
|
||||
unset($arg['_REPLACE']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$REPLACE = FALSE;
|
||||
}
|
||||
|
||||
if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data']))
|
||||
{
|
||||
//Convert data if not using 'new' format
|
||||
@ -378,6 +388,7 @@ class db {
|
||||
}
|
||||
if(!isset($arg['data'])) { return false; }
|
||||
|
||||
|
||||
$fieldTypes = $this->_getTypes($arg);
|
||||
$keyList= '`'.implode('`,`', array_keys($arg['data'])).'`';
|
||||
$tmp = array();
|
||||
@ -387,7 +398,16 @@ class db {
|
||||
}
|
||||
$valList= implode(', ', $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
|
||||
{
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user