some doc and globals
This commit is contained in:
@@ -1,12 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
/* $Id$ */
|
/* vim: expandtab sw=4 ts=4 sts=4: */
|
||||||
// vim: expandtab sw=4 ts=4 sts=4:
|
/**
|
||||||
|
* Library that provides common import functions that are used by import plugins
|
||||||
|
*
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
/* Library that provides common import functions that are used by import plugins */
|
/**
|
||||||
|
* We need to know something about user
|
||||||
|
*/
|
||||||
|
require_once './libraries/check_user_privileges.lib.php';
|
||||||
|
|
||||||
// We need to know something about user
|
/**
|
||||||
require_once('./libraries/check_user_privileges.lib.php');
|
* We do this check, DROP DATABASE does not need to be confirmed elsewhere
|
||||||
// We do this check
|
*/
|
||||||
define('PMA_CHK_DROP', 1);
|
define('PMA_CHK_DROP', 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,17 +67,18 @@ function PMA_detectCompression($filepath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs query inside import buffer. This is needed to allow displaying
|
* Runs query inside import buffer. This is needed to allow displaying
|
||||||
* of last SELECT, SHOW or HANDLER results and similar nice stuff.
|
* of last SELECT, SHOW or HANDLER results and similar nice stuff.
|
||||||
*
|
*
|
||||||
* @param string query to run
|
* @uses $GLOBALS['finished'] read and write
|
||||||
* @param string query to display, this might be commented
|
* @param string query to run
|
||||||
* @param bool whether to use control user for queries
|
* @param string query to display, this might be commented
|
||||||
* @access public
|
* @param bool whether to use control user for queries
|
||||||
|
* @access public
|
||||||
*/
|
*/
|
||||||
function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
|
function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
|
||||||
{
|
{
|
||||||
global $import_run_buffer, $go_sql, $complete_query, $display_query, $sql_query, $cfg, $my_die, $error, $reload, $finished, $timeout_passed, $skip_queries, $executed_queries, $max_sql_len, $read_multiply, $cfg, $sql_query_disabled, $db, $run_query, $is_superuser, $message, $show_error_header;
|
global $import_run_buffer, $go_sql, $complete_query, $display_query, $sql_query, $cfg, $my_die, $error, $reload, $timeout_passed, $skip_queries, $executed_queries, $max_sql_len, $read_multiply, $cfg, $sql_query_disabled, $db, $run_query, $is_superuser, $message, $show_error_header;
|
||||||
$read_multiply = 1;
|
$read_multiply = 1;
|
||||||
if (isset($import_run_buffer)) {
|
if (isset($import_run_buffer)) {
|
||||||
// Should we skip something?
|
// Should we skip something?
|
||||||
@@ -90,7 +98,7 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
|
|||||||
$error = TRUE;
|
$error = TRUE;
|
||||||
} else {
|
} else {
|
||||||
$executed_queries++;
|
$executed_queries++;
|
||||||
if ($run_query && $finished && empty($sql) && !$error && (
|
if ($run_query && $GLOBALS['finished'] && empty($sql) && !$error && (
|
||||||
(!empty($import_run_buffer['sql']) && preg_match('/^[\s]*(SELECT|SHOW|HANDLER)/i', $import_run_buffer['sql'])) ||
|
(!empty($import_run_buffer['sql']) && preg_match('/^[\s]*(SELECT|SHOW|HANDLER)/i', $import_run_buffer['sql'])) ||
|
||||||
($executed_queries == 1)
|
($executed_queries == 1)
|
||||||
)) {
|
)) {
|
||||||
@@ -190,16 +198,22 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns next part of imported file/buffer
|
* Returns next part of imported file/buffer
|
||||||
*
|
*
|
||||||
* @param integer size of buffer to read (this is maximal size
|
* @uses $GLOBALS['offset'] read and write
|
||||||
|
* @uses $GLOBALS['import_file'] read only
|
||||||
|
* @uses $GLOBALS['import_text'] read and write
|
||||||
|
* @uses $GLOBALS['finished'] read and write
|
||||||
|
* @uses $GLOBALS['read_limit'] read only
|
||||||
|
* @param integer size of buffer to read (this is maximal size
|
||||||
* function will return)
|
* function will return)
|
||||||
* @return string part of file/buffer
|
* @return string part of file/buffer
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function PMA_importGetNextChunk($size = 32768)
|
function PMA_importGetNextChunk($size = 32768)
|
||||||
{
|
{
|
||||||
global $import_file, $import_text, $finished, $compression, $import_handle, $offset, $charset_conversion, $charset_of_file, $charset, $read_multiply, $read_limit;
|
global $compression, $import_handle, $charset_conversion, $charset_of_file,
|
||||||
|
$charset, $read_multiply;
|
||||||
|
|
||||||
// Add some progression while reading large amount of data
|
// Add some progression while reading large amount of data
|
||||||
if ($read_multiply <= 8) {
|
if ($read_multiply <= 8) {
|
||||||
@@ -210,26 +224,26 @@ function PMA_importGetNextChunk($size = 32768)
|
|||||||
$read_multiply++;
|
$read_multiply++;
|
||||||
|
|
||||||
// We can not read too much
|
// We can not read too much
|
||||||
if ($size > $read_limit) {
|
if ($size > $GLOBALS['read_limit']) {
|
||||||
$size = $read_limit;
|
$size = $GLOBALS['read_limit'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PMA_checkTimeout()) {
|
if (PMA_checkTimeout()) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if ($finished) {
|
if ($GLOBALS['finished']) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($import_file == 'none') {
|
if ($GLOBALS['import_file'] == 'none') {
|
||||||
// Well this is not yet supported and tested, but should return content of textarea
|
// Well this is not yet supported and tested, but should return content of textarea
|
||||||
if (strlen($import_text) < $size) {
|
if (strlen($GLOBALS['import_text']) < $size) {
|
||||||
$finished = TRUE;
|
$GLOBALS['finished'] = TRUE;
|
||||||
return $import_text;
|
return $GLOBALS['import_text'];
|
||||||
} else {
|
} else {
|
||||||
$r = substr($import_text, 0, $size);
|
$r = substr($GLOBALS['import_text'], 0, $size);
|
||||||
$offset += $size;
|
$GLOBALS['offset'] += $size;
|
||||||
$import_text = substr($import_text, $size);
|
$GLOBALS['import_text'] = substr($GLOBALS['import_text'], $size);
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,23 +251,23 @@ function PMA_importGetNextChunk($size = 32768)
|
|||||||
switch ($compression) {
|
switch ($compression) {
|
||||||
case 'application/bzip2':
|
case 'application/bzip2':
|
||||||
$result = bzread($import_handle, $size);
|
$result = bzread($import_handle, $size);
|
||||||
$finished = feof($import_handle);
|
$GLOBALS['finished'] = feof($import_handle);
|
||||||
break;
|
break;
|
||||||
case 'application/gzip':
|
case 'application/gzip':
|
||||||
$result = gzread($import_handle, $size);
|
$result = gzread($import_handle, $size);
|
||||||
$finished = feof($import_handle);
|
$GLOBALS['finished'] = feof($import_handle);
|
||||||
break;
|
break;
|
||||||
case 'application/zip':
|
case 'application/zip':
|
||||||
$result = substr($import_text, 0, $size);
|
$result = substr($GLOBALS['import_text'], 0, $size);
|
||||||
$import_text = substr($import_text, $size);
|
$GLOBALS['import_text'] = substr($GLOBALS['import_text'], $size);
|
||||||
$finished = empty($import_text);
|
$GLOBALS['finished'] = empty($GLOBALS['import_text']);
|
||||||
break;
|
break;
|
||||||
case 'none':
|
case 'none':
|
||||||
$result = fread($import_handle, $size);
|
$result = fread($import_handle, $size);
|
||||||
$finished = feof($import_handle);
|
$GLOBALS['finished'] = feof($import_handle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$offset += $size;
|
$GLOBALS['offset'] += $size;
|
||||||
|
|
||||||
if ($charset_conversion) {
|
if ($charset_conversion) {
|
||||||
return PMA_convert_string($charset_of_file, $charset, $result);
|
return PMA_convert_string($charset_of_file, $charset, $result);
|
||||||
@@ -265,7 +279,7 @@ function PMA_importGetNextChunk($size = 32768)
|
|||||||
*
|
*
|
||||||
* @todo BOM could be used for charset autodetection
|
* @todo BOM could be used for charset autodetection
|
||||||
*/
|
*/
|
||||||
if ($offset == $size) {
|
if ($GLOBALS['offset'] == $size) {
|
||||||
// UTF-8
|
// UTF-8
|
||||||
if (strncmp($result, "\xEF\xBB\xBF", 3) == 0) {
|
if (strncmp($result, "\xEF\xBB\xBF", 3) == 0) {
|
||||||
$result = substr($result, 3);
|
$result = substr($result, 3);
|
||||||
@@ -277,7 +291,4 @@ function PMA_importGetNextChunk($size = 32768)
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user