blob streaming code cleanup (work in progress)

This commit is contained in:
Marc Delisle
2010-07-22 13:15:27 -04:00
parent b6349cd626
commit 56ebe05af7
15 changed files with 381 additions and 391 deletions

View File

@@ -32,19 +32,17 @@
// necessary variables exist
if ($bsDB && $bsTable && $bsReference && $bsNewMIMEType)
{
if (PMA_BS_SetContentType($bsDB, $bsTable, $bsReference, $bsNewMIMEType))
{
if (PMA_BS_SetContentType($bsDB, $bsTable, $bsReference, $bsNewMIMEType)) {
// determine redirector page
$newLoc = $cfg['PmaAbsoluteUri'] . 'sql.php?' . PMA_generate_common_url ('','', '&') . (isset($bsDB) ? '&db=' . urlencode($bsDB) : '') . (isset($bsTable) ? '&table=' . urlencode($bsTable) : '') . (isset($token) ? '&token=' . urlencode($token) : '') . (isset($goto) ? '&goto=' . urlencode($goto) : '') . '&reload=1&purge=1';
// redirect to specified page
?>
<script>
window.location = "<?php echo $newLoc ?>";
</script>
<script>
window.location = "<?php echo $newLoc ?>";
</script>
<?php
} // end if ($result)
} // end if ($bsDB && $bsTable && $bsReference && $bsNewMIMEType)
?>

View File

@@ -25,15 +25,21 @@ $c_type = preg_replace('/[^A-Za-z0-9/_-]/', '_', $_REQUEST['c_type']);
// Get the blob streaming URL
$filename = PMA_BS_getURL($reference);
if (empty($filename)) die('No blob streaming server configured!');
if (empty($filename)) {
die(__('No blob streaming server configured!'));
}
$hdrs = get_headers($filename, 1);
if ($hdrs === FALSE) die('Failed to fetch headers');
if ($hdrs === FALSE) {
die(__('Failed to fetch headers'));
}
$fHnd = fopen($filename, "rb");
if ($fHnd === FALSE) die('Failed to open remote URL');
if ($fHnd === FALSE) {
die(__('Failed to open remote URL'));
}
$f_size = $hdrs['Content-Length'];
@@ -53,8 +59,9 @@ while (!feof($fHnd)) {
$content .= fread($fHnd, $f_size);
$pos = strlen($content);
if ($pos >= $f_size)
if ($pos >= $f_size) {
break;
}
}
echo $content;

View File

@@ -25,16 +25,16 @@
$bsReference = isset($_REQUEST['bs_reference']) ? $_REQUEST['bs_reference'] : NULL;
// if media type and BS reference are specified
if (isset($mediaType) && isset($bsReference))
{
if (isset($customType) && $customType)
if (isset($mediaType) && isset($bsReference)) {
if (isset($customType) && $customType) {
$bs_file_path = 'bs_disp_as_mime_type.php' . PMA_generate_common_url(array('reference' => $bsReference, 'c_type' => $mediaType));
else {
} else {
// Get the BLOB streaming URL
$bs_file_path = PMA_BS_getURL($bsReference);
if (empty($bs_file_path)) die('No blob streaming server configured!');
if (empty($bs_file_path)) {
die(__('No blob streaming server configured!'));
}
}
?>
<html>
<head>

View File

@@ -150,13 +150,9 @@ $hidden_fields = array();
$odd_row = true;
$sum_row_count_pre = '';
// added by rajk - for blobstreaming
$PMA_Config = $GLOBALS['PMA_Config'];
$tableReductionCount = 0; // the amount to reduce the table count by
foreach ($tables as $keyname => $each_table) {
if (PMA_BS_IsHiddenTable($keyname)) {
$tableReductionCount++;
continue;

View File

@@ -279,29 +279,26 @@ class PMA_File
$is_bs_upload = FALSE;
// check if this field requires a repository upload
if (isset($_REQUEST['upload_blob_repo_' . $key]))
if (isset($_REQUEST['upload_blob_repo_' . $key])) {
$is_bs_upload = ($_REQUEST['upload_blob_repo_' . $key]['multi_edit'][0] == "on") ? TRUE : FALSE;
}
// if request is an upload to the BLOB repository
if ($is_bs_upload)
{
if ($is_bs_upload) {
$bs_db = $_REQUEST['db'];
$bs_table = $_REQUEST['table'];
$tmp_filename = $file['tmp_name'];
$tmp_file_type = $file['type'];
if (!$tmp_file_type)
if (! $tmp_file_type) {
$tmp_file_type = NULL;
}
if (!$bs_db || !$bs_table)
{
if (! $bs_db || ! $bs_table) {
$this->_error_message = $GLOBALS['strUploadErrorUnknown'];
return FALSE;
}
$blob_url = PMA_BS_UpLoadFile($bs_db, $bs_table, $tmp_file_type, $tmp_filename);
PMA_File::setRecentBLOBReference($blob_url);
} // end if ($is_bs_upload)
// check for file upload errors
@@ -399,45 +396,42 @@ class PMA_File
$is_bs_upload = FALSE;
// check if this field requires a repository upload
if (isset($_REQUEST['upload_blob_repo_' . $key]))
if (isset($_REQUEST['upload_blob_repo_' . $key])) {
$is_bs_upload = ($_REQUEST['upload_blob_repo_' . $key]['multi_edit'][0] == "on") ? TRUE : FALSE;
}
// is a request to upload file to BLOB repository using uploadDir mechanism
if ($is_bs_upload)
{
if ($is_bs_upload) {
$bs_db = $_REQUEST['db'];
$bs_table = $_REQUEST['table'];
$tmp_filename = $GLOBALS['cfg']['UploadDir'] . '/' . $_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary];
// check if fileinfo library exists
if ($PMA_Config->get('FILEINFO_EXISTS'))
{
if ($PMA_Config->get('FILEINFO_EXISTS')) {
// attempt to init fileinfo
$finfo = finfo_open(FILEINFO_MIME);
// fileinfo exists
if ($finfo)
{
if ($finfo) {
// pass in filename to fileinfo and close fileinfo handle after
$tmp_file_type = finfo_file($finfo, $tmp_filename);
finfo_close($finfo);
}
}
else // no fileinfo library exists, use file command
} else {
// no fileinfo library exists, use file command
$tmp_file_type = exec("file -bi " . escapeshellarg($tmp_filename));
}
if (!$tmp_file_type)
if (! $tmp_file_type) {
$tmp_file_type = NULL;
}
if (!$bs_db || !$bs_table)
{
if (! $bs_db || !$bs_table) {
$this->_error_message = $GLOBALS['strUploadErrorUnknown'];
return FALSE;
}
$blob_url = PMA_BS_UpLoadFile($bs_db, $bs_table, $tmp_file_type, $tmp_filename);
PMA_File::setRecentBLOBReference($blob_url);
} // end if ($is_bs_upload)
return $this->setLocalSelectedFile($_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary]);

View File

@@ -139,8 +139,9 @@ class PMA_StorageEngine
*/
static public function isValid($engine)
{
if ($engine == "PBMS")
if ($engine == "PBMS") {
return TRUE;
}
$storage_engines = PMA_StorageEngine::getStorageEngines();
return isset($storage_engines[$engine]);
}

View File

@@ -13,29 +13,31 @@ function initPBMSDatabase()
* table in an already existing database which will cause the PBMS
* daemon to create the 'pbms' database.
*/
$db_array =PMA_DBI_fetch_result('SHOW DATABASES;');
if (!empty($db_array)) {
$db_array = PMA_DBI_fetch_result('SHOW DATABASES;');
if (! empty($db_array)) {
$target = "";
foreach ($db_array as $current_db) {
if ($current_db == 'pbms')
if ($current_db == 'pbms') {
return TRUE;
}
if ($target == "") {
if (($current_db != 'pbxt') && ($current_db != 'mysql') && ($current_db != 'information_schema'))
if (($current_db != 'pbxt') && ($current_db != 'mysql') && ($current_db != 'information_schema')) {
$target = $current_db;
}
}
}
if ($target != "")
if ($target != "") {
$query = "select * from $target.pbms_metadata_header"; // If it exists this table will not contain much
}
}
$result = PMA_DBI_query($query );
if (!$result)
if (! $result) {
return FALSE;
return TRUE;
}
return TRUE;
}
/**
* checks whether the necessary plugins for BLOBStreaming exist
@@ -241,8 +243,9 @@ function PMA_do_connect($db_name, $quiet)
$pbms_port = $PMA_Config->get('BLOBSTREAMING_PORT');
if (pbms_connect($pbms_host, $pbms_port, $db_name) == FALSE) {
if ($quiet == FALSE)
if ($quiet == FALSE) {
PMA_BS_ReportPBMSError("PBMS Connectiuon failed: pbms_connect($pbms_host, $pbms_port, $db_name)");
}
return FALSE;
}
return TRUE;
@@ -261,8 +264,9 @@ function PMA_do_disconnect()
*/
function PMA_BS_IsPBMSReference($bs_reference, $db_name)
{
if (PMA_cacheGet('skip_blobstreaming', true))
if (PMA_cacheGet('skip_blobstreaming', true)) {
return FALSE;
}
if (PMA_do_connect($db_name, TRUE) == FALSE) {
return FALSE;
@@ -292,8 +296,9 @@ function PMA_BS_CreateReferenceLink($bs_reference, $db_name)
PMA_do_disconnect();
if (!$content_type)
if (! $content_type) {
$content_type = "image/jpeg";
}
$bs_url = PMA_BS_getURL($bs_reference);
if (empty($bs_url)) {
@@ -304,8 +309,7 @@ function PMA_BS_CreateReferenceLink($bs_reference, $db_name)
$output = "<a href=\"#\" onclick=\"requestMIMETypeChange('" . urlencode($db_name) . "', '" . urlencode($GLOBALS['table']) . "', '" . urlencode($bs_reference) . "', '" . urlencode($content_type) . "')\">$content_type</a>";
// specify custom HTML for various content types
switch ($content_type)
{
switch ($content_type) {
// no content specified
case NULL:
$output = "NULL";
@@ -329,7 +333,6 @@ function PMA_BS_CreateReferenceLink($bs_reference, $db_name)
$output .= ' (<a href="' . $bs_url . '" target="new">' . __('Download file'). '</a>)';
}
//PMA_showMessage("PMA_BS_CreateReferenceLink($bs_reference, $db_name): $output");
return $output;
}
@@ -340,30 +343,35 @@ function PMA_BS_CreateReferenceLink($bs_reference, $db_name)
// they are not currently needed.
function PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type)
{
if (PMA_cacheGet('skip_blobstreaming', true))
if (PMA_cacheGet('skip_blobstreaming', true)) {
return FALSE;
}
if ((isset($tbl_type) == FALSE) || (strlen($tbl_type) == 0))
if ((isset($tbl_type) == FALSE) || (strlen($tbl_type) == 0)) {
return FALSE;
}
// load PMA configuration
$PMA_Config = $GLOBALS['PMA_Config'];
// return if unable to load PMA configuration
if (empty($PMA_Config))
if (empty($PMA_Config)) {
return FALSE;
}
if (!$PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST') )
if (! $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST')) {
return FALSE;
}
// This information should be cached rather than selecting it each time.
//$query = "SELECT count(*) FROM information_schema.TABLES T, pbms.pbms_enabled E where T.table_schema = ". PMA_backquote($db_name) . " and T.table_name = ". PMA_backquote($tbl_name) . " and T.engine = E.name";
$query = "SELECT count(*) FROM pbms.pbms_enabled E where E.name = '". PMA_sqlAddslashes($tbl_type) . "'" ;
$query = "SELECT count(*) FROM pbms.pbms_enabled E where E.name = '" . PMA_sqlAddslashes($tbl_type) . "'";
$result = PMA_DBI_query($query);
$data = PMA_DBI_fetch_row($result);
if ($data[0] == 1)
if ($data[0] == 1) {
return TRUE;
}
return FALSE;
}
@@ -372,15 +380,16 @@ function PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type)
function PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name)
{
if (PMA_cacheGet('skip_blobstreaming', true))
if (PMA_cacheGet('skip_blobstreaming', true)) {
return FALSE;
}
if (PMA_do_connect($db_name, FALSE) == FALSE) {
return FALSE;
}
$fh = fopen($file_name, 'r');
if (!$fh) {
if (! $fh) {
PMA_do_disconnect();
PMA_showMessage("Could not open file: $file_name");
return FALSE;
@@ -389,11 +398,10 @@ function PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name)
pbms_add_metadata("Content-type", $file_type);
$pbms_blob_url = pbms_read_stream($fh, filesize($file_name), $tbl_name);
if (!$pbms_blob_url) {
if (! $pbms_blob_url) {
PMA_BS_ReportPBMSError("pbms_read_stream() Failed");
}
//PMA_showMessage(" PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name): $pbms_blob_url");
fclose($fh);
PMA_do_disconnect();
return $pbms_blob_url;
@@ -402,42 +410,34 @@ function PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name)
//------------
function PMA_BS_SetContentType($db_name, $bsTable, $blobReference, $contentType)
{
if (PMA_cacheGet('skip_blobstreaming', true))
if (PMA_cacheGet('skip_blobstreaming', true)) {
return FALSE;
}
// This is a really ugly way to do this but currently there is nothing better.
// In a future version of PBMS the system tables will be redesigned to make this
// more eficient.
$query = "SELECT Repository_id, Repo_blob_offset FROM pbms_reference WHERE Blob_url='" . PMA_sqlAddslashes($blobReference) . "'";
//error_log(" PMA_BS_SetContentType: $query\n", 3, "/tmp/mylog");
//error_log(" PMA_BS_SetContentType: $query\n", 3, "/tmp/mylog");
$result = PMA_DBI_query($query);
//error_log(" $query\n", 3, "/tmp/mylog");
//error_log(" $query\n", 3, "/tmp/mylog");
// if record exists
if ($data = PMA_DBI_fetch_assoc($result))
{
// if record exists
if ($data = PMA_DBI_fetch_assoc($result)) {
$where = "WHERE Repository_id=" . $data['Repository_id'] . " AND Repo_blob_offset=" . $data['Repo_blob_offset'] ;
$query = "SELECT name from pbms_metadata $where";
$result = PMA_DBI_query($query);
if (PMA_DBI_num_rows($result) == 0)
if (PMA_DBI_num_rows($result) == 0) {
$query = "INSERT into pbms_metadata Values( ". $data['Repository_id'] . ", " . $data['Repo_blob_offset'] . ", 'Content_type', '" . PMA_sqlAddslashes($contentType) . "')";
else
} else {
$query = "UPDATE pbms_metadata SET name = 'Content_type', Value = '" . PMA_sqlAddslashes($contentType) . "' $where";
}
//error_log("$query\n", 3, "/tmp/mylog");
PMA_DBI_query($query);
} else {
// if ($result == FALSE) {
// $err = PMA_DBI_getError();
// error_log("MySQL ERROR: $err\n", 3, "/tmp/mylog");
// } else
// error_log("No results: $query\n", 3, "/tmp/mylog");
return FALSE;
}
return TRUE;
}
@@ -452,7 +452,6 @@ function PMA_BS_IsHiddenTable($table)
case 'pbms_dump' :
return TRUE;
}
return FALSE;
}
@@ -461,18 +460,17 @@ function PMA_BS_getURL($reference)
{
// load PMA configuration
$PMA_Config = $GLOBALS['PMA_Config'];
if (empty($PMA_Config))
if (empty($PMA_Config)) {
return FALSE;
}
// retrieve BS server variables from PMA configuration
$bs_server = $PMA_Config->get('BLOBSTREAMING_SERVER');
if (empty($bs_server))
if (empty($bs_server)) {
return FALSE;
}
$bs_url = 'http://' . $bs_server . '/' . rtrim($reference);
//PMA_showMessage(" PMA_BS_getURL($reference): $bs_url");
return $bs_url;
}
?>

View File

@@ -797,7 +797,6 @@ function PMA_getTableList($db, $tables = null, $limit_offset = 0, $limit_count =
continue;
}
// check for correct row count
if (null === $table['Rows']) {
// Do not check exact row count here,

View File

@@ -312,9 +312,10 @@ function PMA_getTableCount($db)
// do not count hidden blobstreaming tables
while ((($num_tables > 0)) && $data = PMA_DBI_fetch_assoc($tables)) {
if (PMA_BS_IsHiddenTable($data['Tables_in_' . $db]))
if (PMA_BS_IsHiddenTable($data['Tables_in_' . $db])) {
$num_tables--;
}
}
PMA_DBI_free_result($tables);
} else {

View File

@@ -1285,7 +1285,6 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
$vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
} else {
// for blobstreaming
// if valid BS reference exists
if (PMA_BS_IsPBMSReference($row[$i], $db)) {
$blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
@@ -1341,8 +1340,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
// fields
if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
$row[$i] = bin2hex($row[$i]);
}
else {
} else {
$row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
}
} else {

View File

@@ -91,7 +91,7 @@ class PMA_StorageEngine_pbms extends PMA_StorageEngine
function getPageDocumentation()
{
$output = '<p> Documentation and furtther information about PBMS can be found on ' . "\n"
$output = '<p> Documentation and further information about PBMS can be found on ' . "\n"
. '<a href="http://www.blobstreaming.org/" target="_blank">The PrimeBase Media Streaming home page</a>.<br><br>' . "\n"
. '<table id="PBMS_Related_Links" >' . "\n"
. '<tr>' . "\n"

View File

@@ -121,7 +121,7 @@ class PMA_StorageEngine_pbxt extends PMA_StorageEngine
function getPageDocumentation()
{
$output = '<p> Documentation and furtther information about PBXT can be found on the ' . "\n"
$output = '<p> Documentation and further information about PBXT can be found on the ' . "\n"
. '<a href="http://www.primebase.com/xt/" target="_blank">PrimeBase XT Home Page</a>.<br><br>' . "\n"
. '<table id="PBMS_Related_Links" >' . "\n"
. '<tr>' . "\n"

View File

@@ -1,9 +1,8 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* display list of server enignes and additonal information about them
* display list of server engines and additonal information about them
*
* @todo falcon storage enginge is not listed under dev.mysql.com/doc/refman but dev.mysql.com/doc/falcon/
* @package phpMyAdmin
*/

View File

@@ -889,8 +889,7 @@ foreach ($rows as $row_id => $vrow) {
if ($is_upload && $field['is_blob']) {
// check if field type is of longblob and if the table is PBMS enabled.
if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type))
{
if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type)) {
echo '<br />';
echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Upload to BLOB repository');
}