projects
/
fa-stable.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Text not gettextized in /admin/backups.php.
[fa-stable.git]
/
admin
/
db
/
maintenance_db.inc
diff --git
a/admin/db/maintenance_db.inc
b/admin/db/maintenance_db.inc
index 700da6d05df9739cee71be4314417d08af06d5b7..c9e07c57ad2d7f059075b8b66dcd6f19fe30d699 100644
(file)
--- a/
admin/db/maintenance_db.inc
+++ b/
admin/db/maintenance_db.inc
@@
-18,6
+18,8
@@
* @param $strSortType String containing either asc or desc [default to asc]
* @desc Naturally sorts an array using by the column $strSortBy
*/
* @param $strSortType String containing either asc or desc [default to asc]
* @desc Naturally sorts an array using by the column $strSortBy
*/
+define('EXPORT_MAX_INSERT', 50000);
+
function array_natsort($aryData, $strIndex, $strSortBy, $strSortType=false)
{
// if the parameters are invalid
function array_natsort($aryData, $strIndex, $strSortBy, $strSortType=false)
{
// if the parameters are invalid
@@
-178,7
+180,7
@@
function update_extensions($extensions) {
}
// update per company files
}
// update per company files
- $cnt =
count($db_connections
);
+ $cnt =
max(1, count($db_connections)
);
for($i = 0; $i < $cnt; $i++)
{
$newexts = $extensions;
for($i = 0; $i < $cnt; $i++)
{
$newexts = $extensions;
@@
-253,14
+255,20
@@
function write_lang()
function db_import($filename, $connection, $force=true)
{
function db_import($filename, $connection, $force=true)
{
- global $db, $go_debug;
+ global $db, $go_debug, $sql_trail;
+
+ $sql_trail = false;
$allowed_commands = array(
"create" => 'table_queries',
$allowed_commands = array(
"create" => 'table_queries',
+ "delimiter" => 'table_queries',
"alter table" => 'table_queries',
"insert" => 'data_queries',
"update" => 'data_queries',
"alter table" => 'table_queries',
"insert" => 'data_queries',
"update" => 'data_queries',
- "drop table if exists" => 'drop_queries');
+ "drop table if exists" => 'drop_queries',
+ "drop function if exists" => 'drop_queries',
+ "drop trigger if exists" => 'drop_queries',
+ );
$ignored_mysql_errors = array( //errors ignored in normal (non forced) mode
'1022', // duplicate key
'1050', // Table %s already exists
$ignored_mysql_errors = array( //errors ignored in normal (non forced) mode
'1022', // duplicate key
'1050', // Table %s already exists
@@
-286,6
+294,7
@@
function db_import($filename, $connection, $force=true)
// parse input file
$query_table = '';
// parse input file
$query_table = '';
+ $delimiter = ';';
foreach($lines as $line_no => $line)
{
$line = trim($line);
foreach($lines as $line_no => $line)
{
$line = trim($line);
@@
-298,6
+307,10
@@
function db_import($filename, $connection, $force=true)
{
if (strtolower(substr($line, 0, strlen($cmd))) == $cmd)
{
{
if (strtolower(substr($line, 0, strlen($cmd))) == $cmd)
{
+ if ($cmd == 'delimiter') {
+ $delimiter = trim(substr($line, 10));
+ continue 2;
+ }
$query_table = $table;
${$query_table}[] = array('', $line_no+1);
break;
$query_table = $table;
${$query_table}[] = array('', $line_no+1);
break;
@@
-307,9
+320,10
@@
function db_import($filename, $connection, $force=true)
if($query_table != '') // inside allowed query
{
$table = $query_table;
if($query_table != '') // inside allowed query
{
$table = $query_table;
- if (substr($line, -1) == ';') // end of query found
+
+ if (substr($line, -strlen($delimiter)) == $delimiter) // end of query found
{
{
- $line = substr($line, 0, strlen($line) -
1); // strip ';'
+ $line = substr($line, 0, strlen($line) -
strlen($delimiter)); // strip delimiter
$query_table = '';
}
${$table}[count(${$table}) - 1][0] .= $line . "\n";
$query_table = '';
}
${$table}[count(${$table}) - 1][0] .= $line . "\n";
@@
-365,8
+379,9
@@
function db_import($filename, $connection, $force=true)
}
}
}
}
}
}
-
+
db_query("SET foreign_key_checks=1");
db_query("SET foreign_key_checks=1");
+ if ($delimiter != ';') db_query("delimiter ;"); // just for any case
if (count($sql_errors)) {
// display first failure message; the rest are probably derivative
if (count($sql_errors)) {
// display first failure message; the rest are probably derivative
@@
-542,12
+557,12
@@
function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF,
// if ($auto_incr[$tablename])
// $out.=" AUTO_INCREMENT=".$auto_incr[$tablename];
$out.=" ;";
// if ($auto_incr[$tablename])
// $out.=" AUTO_INCREMENT=".$auto_incr[$tablename];
$out.=" ;";
- $out.="\n\n
\n
";
+ $out.="\n\n";
// export data
if (!$error)
{
// export data
if (!$error)
{
- $out.="### Data of table `".$tablename."` ###\n
\n
";
+ $out.="### Data of table `".$tablename."` ###\n";
// check if field types are NULL or NOT NULL
$res3 = db_query("SHOW COLUMNS FROM `" . $tablename . "`");
// check if field types are NULL or NOT NULL
$res3 = db_query("SHOW COLUMNS FROM `" . $tablename . "`");
@@
-560,18
+575,40
@@
function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF,
}
$res2 = db_query("SELECT * FROM `" . $tablename . "`");
}
$res2 = db_query("SELECT * FROM `" . $tablename . "`");
+ $maxinsert = 0;
+ $insert = '';
for ($j = 0; $j < db_num_rows($res2); $j++)
{
for ($j = 0; $j < db_num_rows($res2); $j++)
{
- $out .= "INSERT INTO `" . $tablename . "` VALUES (";
$row2 = db_fetch_row($res2);
$row2 = db_fetch_row($res2);
- // run through each field
+ $values = '(';
for ($k = 0; $k < $nf = db_num_fields($res2); $k++)
{
for ($k = 0; $k < $nf = db_num_fields($res2); $k++)
{
- $
out
.= db_escape($row2[$k], $field_null[$k]);
+ $
values
.= db_escape($row2[$k], $field_null[$k]);
if ($k < ($nf - 1))
if ($k < ($nf - 1))
- $out .= ", ";
+ $values .= ', ';
+ }
+ $values .= ')';
+ $len = strlen($values);
+ if ($maxinsert < $len+1)
+ {
+ $maxinsert = EXPORT_MAX_INSERT;
+ if ($insert)
+ {
+ $out .= $insert .';'; // flush insert query
+ $insert = '';
+ }
}
}
- $out .= ");\n";
+
+ if ($insert == '')
+ {
+ $insert = "\nINSERT INTO `" . $tablename . "` VALUES\n";
+ $maxinsert -= strlen($insert);
+ } else {
+ $insert .= ",\n";
+ }
+
+ $maxinsert -= $len;
+ $insert .= $values;
// if saving is successful, then empty $out, else set error flag
if (strlen($out) > $max_size && $zip != "zip")
// if saving is successful, then empty $out, else set error flag
if (strlen($out) > $max_size && $zip != "zip")
@@
-582,7
+619,8
@@
function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF,
$error = true;
}
}
$error = true;
}
}
-
+ if ($insert)
+ $out .= $insert. ';';
// an error occurred! Try to delete file and return error status
}
elseif ($error)
// an error occurred! Try to delete file and return error status
}
elseif ($error)