Skip to content

Commit

Permalink
blob streaming code cleanup (work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
lem9 committed Jul 22, 2010
1 parent b6349cd commit 56ebe05
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 399 deletions.
24 changes: 11 additions & 13 deletions bs_change_mime_type.php
Expand Up @@ -32,19 +32,17 @@
// necessary variables exist
if ($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>
<?php
} // end if ($result)

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>
<?php
} // end if ($result)
} // end if ($bsDB && $bsTable && $bsReference && $bsNewMIMEType)

?>
15 changes: 11 additions & 4 deletions bs_disp_as_mime_type.php
Expand Up @@ -25,15 +25,21 @@

// 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'];

Expand All @@ -53,8 +59,9 @@
$content .= fread($fHnd, $f_size);
$pos = strlen($content);

if ($pos >= $f_size)
if ($pos >= $f_size) {
break;
}
}

echo $content;
Expand Down
22 changes: 11 additions & 11 deletions bs_play_media.php
Expand Up @@ -15,7 +15,7 @@
$mediaType = isset($_REQUEST['media_type']) ? $_REQUEST['media_type'] : NULL;

/*
* @var string indicates whether media type is of custom type
* @var string indicates whether media type is of custom type
*/
$customType = isset($_REQUEST['custom_type']) ? $_REQUEST['custom_type'] : false;

Expand All @@ -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)
$bs_file_path = 'bs_disp_as_mime_type.php' . PMA_generate_common_url(array('reference' => $bsReference, 'c_type' => $mediaType));
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 (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 {
// Get the BLOB streaming URL
$bs_file_path = PMA_BS_getURL($bsReference);
if (empty($bs_file_path)) {
die(__('No blob streaming server configured!'));
}
}
?>
<html>
<head>
Expand Down
12 changes: 4 additions & 8 deletions db_structure.php
Expand Up @@ -150,17 +150,13 @@
$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;
}
if (PMA_BS_IsHiddenTable($keyname)) {
$tableReductionCount++;
continue;
}

// Get valid statistics whatever is the table type

Expand Down
102 changes: 48 additions & 54 deletions libraries/File.class.php
Expand Up @@ -279,29 +279,26 @@ function setUploadedFromTblChangeRequest($key, $primary = null)
$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)
{
$bs_db = $_REQUEST['db'];
$bs_table = $_REQUEST['table'];
$tmp_filename = $file['tmp_name'];
$tmp_file_type = $file['type'];

if (!$tmp_file_type)
$tmp_file_type = NULL;


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);
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) {
$tmp_file_type = NULL;
}

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
Expand Down Expand Up @@ -399,45 +396,42 @@ function setSelectedFromTblChangeRequest($key, $primary = null)
$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)
{
$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'))
{
// attempt to init fileinfo
$finfo = finfo_open(FILEINFO_MIME);

// fileinfo exists
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
$tmp_file_type = exec("file -bi " . escapeshellarg($tmp_filename));

if (!$tmp_file_type)
$tmp_file_type = NULL;

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')) {
// attempt to init fileinfo
$finfo = finfo_open(FILEINFO_MIME);

// fileinfo exists
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
$tmp_file_type = exec("file -bi " . escapeshellarg($tmp_filename));
}

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);
if (! $tmp_file_type) {
$tmp_file_type = NULL;
}

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]);
Expand Down
7 changes: 4 additions & 3 deletions libraries/StorageEngine.class.php
Expand Up @@ -139,8 +139,9 @@ static public function getEngine($engine)
*/
static public function isValid($engine)
{
if ($engine == "PBMS")
return TRUE;
if ($engine == "PBMS") {
return TRUE;
}
$storage_engines = PMA_StorageEngine::getStorageEngines();
return isset($storage_engines[$engine]);
}
Expand Down Expand Up @@ -303,7 +304,7 @@ function __construct($engine)
$this->support = PMA_ENGINE_SUPPORT_NO;
}
} else {
$this->engine_init();
$this->engine_init();
}
}

Expand Down

0 comments on commit 56ebe05

Please sign in to comment.