Removed unused code from db_operations.php. Changed blobstreaming.lib.php so that it check to see if blob streaming is enabled before doing anything and also uses an indirect method to create the 'pbms' database if it doesn't exist.

This commit is contained in:
Leslie
2010-07-16 10:33:53 -07:00
committed by Marc Delisle
parent a8e5b0f275
commit b6349cd626
2 changed files with 47 additions and 100 deletions

View File

@@ -438,92 +438,6 @@ if (!$is_information_schema) {
</form> </form>
<?php <?php
/*
* BLOB streaming support
*/
// load PMA_Config
$PMA_Config = $GLOBALS['PMA_Config'];
// if all blobstreaming plugins exist, begin checking for blobstreaming tables
if (!empty($PMA_Config))
{
if ($PMA_Config->get('PBXT_NAME') !== strtolower($db))
{
if ($PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST'))
{
$bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
$bs_tables = $bs_tables[$db];
$oneBSTableExists = FALSE;
$allBSTablesExist = TRUE;
// first check that all blobstreaming tables do not exist
foreach ($bs_tables as $table_key=>$tbl)
if ($bs_tables[$table_key]['Exists'])
$oneBSTableExists = TRUE;
else
$allBSTablesExist = FALSE;
?>
<form method="post" action="./db_operations.php">
<?php echo PMA_generate_common_hidden_inputs($db); ?>
<fieldset>
<legend>
<?php echo PMA_getIcon('b_edit.png', __('BLOB Repository'), false, true); ?>
</legend>
<?php echo __('Status'); ?>:
<?php
// if the blobstreaming tables exist, provide option to disable the BLOB repository
if ($allBSTablesExist)
{
?>
<?php echo _pgettext('BLOB repository', 'Enabled'); ?>
</fieldset>
<fieldset class="tblFooters">
<input type="hidden" name="db_blob_streaming_op" value="disable" />
<input type="submit" onclick="return confirmDisableRepository('<?php echo $db; ?>');" value="<?php echo __('Disable'); ?>" />
</fieldset>
<?php
}
else
{
// if any of the blobstreaming tables are missing, provide option to repair the BLOB repository
if ($oneBSTableExists && !$allBSTablesExist)
{
?>
<?php echo __('Damaged'); ?>
</fieldset>
<fieldset class="tblFooters">
<input type="hidden" name="db_blob_streaming_op" value="repair" />
<input type="submit" value="<?php echo _pgettext('BLOB repository', 'Repair'); ?>" />
</fieldset>
<?php
}
// if none of the blobstreaming tables exist, provide option to enable BLOB repository
else
{
?>
<?php echo _pgettext('BLOB repository', 'Disabled'); ?>
</fieldset>
<fieldset class="tblFooters">
<input type="hidden" name="db_blob_streaming_op" value="enable" />
<input type="submit" value="<?php echo __('Enable'); ?>" />
</fieldset>
<?php
}
} // end if ($allBSTablesExist)
?>
</form>
<?php
} // end if ($PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST'))
} // end if ($PMA_Config->get('PBXT_NAME') !== strtolower($db))
}
/** /**
* Change database charset * Change database charset

View File

@@ -4,6 +4,39 @@
* @package BLOBStreaming * @package BLOBStreaming
*/ */
function initPBMSDatabase()
{
$query = "create database IF NOT EXISTS pbms;"; // If no other choice then try this.
/*
* The user may not have privileges to create the 'pbms' database
* so if it doesn't exist then we perform a select on a pbms system
* 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)) {
$target = "";
foreach ($db_array as $current_db) {
if ($current_db == 'pbms')
return TRUE;
if ($target == "") {
if (($current_db != 'pbxt') && ($current_db != 'mysql') && ($current_db != 'information_schema'))
$target = $current_db;
}
}
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)
return FALSE;
return TRUE;
}
/** /**
* checks whether the necessary plugins for BLOBStreaming exist * checks whether the necessary plugins for BLOBStreaming exist
* *
@@ -27,12 +60,6 @@ function checkBLOBStreamingPlugins()
return FALSE; return FALSE;
} }
// At this point we might already know that plugins do not exist
// because this was recorded in the session (cache).
if (PMA_cacheGet('skip_blobstreaming', true)) {
return false;
}
// If we don't know that we can skip blobstreaming, we continue // If we don't know that we can skip blobstreaming, we continue
// verifications; anyway, in case we won't skip blobstreaming, // verifications; anyway, in case we won't skip blobstreaming,
// we still need to set some variables in non-persistent settings, // we still need to set some variables in non-persistent settings,
@@ -95,8 +122,8 @@ function checkBLOBStreamingPlugins()
// get BS server port // get BS server port
$BS_PORT = $bs_variables['pbms_port']; $BS_PORT = $bs_variables['pbms_port'];
// if no BS server port exists, set plugin existance to false and return // if no BS server port or 'pbms' database exists, set plugin existance to false and return
if (! $BS_PORT) { if ((! $BS_PORT) || (! initPBMSDatabase())) {
$PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE); $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE);
PMA_cacheSet('skip_blobstreaming', true, true); PMA_cacheSet('skip_blobstreaming', true, true);
return FALSE; return FALSE;
@@ -109,12 +136,6 @@ function checkBLOBStreamingPlugins()
$PMA_Config->set('PHP_PBMS_EXISTS', FALSE); $PMA_Config->set('PHP_PBMS_EXISTS', FALSE);
$PMA_Config->set('FILEINFO_EXISTS', FALSE); $PMA_Config->set('FILEINFO_EXISTS', FALSE);
// Create the 'pbms' database if it doesn't exist.
// PBMS creates this database automaticly as soon as
// a PBMS enabled table is accessed but we may need it earlier
// when a select is done on pbms.pbms_enabled.
PMA_DBI_query("create database IF NOT EXISTS pbms;" );
// check if PECL's fileinfo library exist // check if PECL's fileinfo library exist
$finfo = NULL; $finfo = NULL;
@@ -240,6 +261,9 @@ function PMA_do_disconnect()
*/ */
function PMA_BS_IsPBMSReference($bs_reference, $db_name) function PMA_BS_IsPBMSReference($bs_reference, $db_name)
{ {
if (PMA_cacheGet('skip_blobstreaming', true))
return FALSE;
if (PMA_do_connect($db_name, TRUE) == FALSE) { if (PMA_do_connect($db_name, TRUE) == FALSE) {
return FALSE; return FALSE;
} }
@@ -316,6 +340,9 @@ function PMA_BS_CreateReferenceLink($bs_reference, $db_name)
// they are not currently needed. // they are not currently needed.
function PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type) function PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type)
{ {
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; return FALSE;
@@ -345,6 +372,9 @@ function PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type)
function PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name) function PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name)
{ {
if (PMA_cacheGet('skip_blobstreaming', true))
return FALSE;
if (PMA_do_connect($db_name, FALSE) == FALSE) { if (PMA_do_connect($db_name, FALSE) == FALSE) {
return FALSE; return FALSE;
} }
@@ -372,6 +402,9 @@ function PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name)
//------------ //------------
function PMA_BS_SetContentType($db_name, $bsTable, $blobReference, $contentType) function PMA_BS_SetContentType($db_name, $bsTable, $blobReference, $contentType)
{ {
if (PMA_cacheGet('skip_blobstreaming', true))
return FALSE;
// This is a really ugly way to do this but currently there is nothing better. // 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 // In a future version of PBMS the system tables will be redesigned to make this
// more eficient. // more eficient.