Skip to content

Commit

Permalink
Basic detection if mime-features are available, better check on error
Browse files Browse the repository at this point in the history
situations. See ChangeLog.
  • Loading branch information
Garvin Hicking committed Feb 26, 2003
1 parent 1674ca5 commit 63c5582
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 33 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ $Source$
* libraries/display_tbl.lib.php3: Fixed transformation-link variable
usage for special queries like 'SHOW FIELDS', where certain variables are
not set.
* config.inc.php3, tbl_addfield.php3, tbl_alter.php3, tbl_create.php3,
tbl_move_copy.php3, tbl_properties.inc.php3, tbl_properties_structure.php3,
transformation_wrapper.php3, libraries/config_import.lib.php3,
libraries/display_tbl.lib.php3, libraries/relation.lib.php3,
scripts/create_tables.sql:
Test if MIME-feature are really available. Preparation for PMA_db-based
SQL-History.
Removed a dupe for inserting comments, fixed integrity check when
moving/renaming tables and keeping comments.


2003-02-25 Marc Delisle <lem9@users.sourceforge.net>
* db_details_structure.php3: undefined variable $comment
Expand Down
5 changes: 5 additions & 0 deletions config.inc.php3
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ $cfg['Servers'][$i]['pdf_pages'] = ''; // table to describe pages o
// - leave blank if you don't want to use this
$cfg['Servers'][$i]['column_info'] = ''; // table to store column information
// - leave blank if you don't want to use this
$cfg['Servers'][$i]['history'] = ''; // table to store SQL history
// - leave blank if you don't want to use this
$cfg['Servers'][$i]['verbose_check'] = TRUE; // set to FALSE if you know that your PMA_* tables
// are up to date. This prevents compatibility
// checks and thereby increases performance.
$cfg['Servers'][$i]['AllowDeny']['order'] // Host authentication order, leave blank to not use
= '';
$cfg['Servers'][$i]['AllowDeny']['rules'] // Host authentication rules, leave blank for defaults
Expand Down
8 changes: 8 additions & 0 deletions libraries/config_import.lib.php3
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ if (!defined('PMA_CONFIG_IMPORT_LIB_INCLUDED')) {
$cfg['Servers'][$i]['pdf_pages'] = '';
}

if (!isset($cfg['Servers'][$i]['history'])) {
$cfg['Servers'][$i]['history'] = '';
}

if (!isset($cfg['Servers'][$i]['verbose_check'])) {
$cfg['Servers'][$i]['verbose_check'] = TRUE;
}

if (!isset($cfg['Servers'][$i]['AllowDeny'])) {
$cfg['Servers'][$i]['AllowDeny'] = array ('order' => '',
'rules' => array());
Expand Down
4 changes: 2 additions & 2 deletions libraries/display_tbl.lib.php3
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
$comments_map = array();
}

if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfg']['BrowseMIME']) {
if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
require('./libraries/transformations.lib.php3');
$GLOBALS['mime_map'] = PMA_getMIME($db, $table);
}
Expand Down Expand Up @@ -1001,7 +1001,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
$transform_function = $default_function;
$transform_options = array();

if ($GLOBALS['cfg']['BrowseMIME']) {
if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {

if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation'])) {
// garvin: for security, never allow to break out from transformations directory
Expand Down
50 changes: 49 additions & 1 deletion libraries/relation.lib.php3
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){
$cfgRelation['displaywork'] = FALSE;
$cfgRelation['pdfwork'] = FALSE;
$cfgRelation['commwork'] = FALSE;
$cfgRelation['mimework'] = FALSE;
$cfgRelation['historywork'] = FALSE;
$cfgRelation['allworks'] = FALSE;

// No server selected -> no bookmark table
Expand Down Expand Up @@ -127,6 +129,8 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){
$cfgRelation['column_info'] = $curr_table[0];
} else if ($curr_table[0] == $cfg['Server']['pdf_pages']) {
$cfgRelation['pdf_pages'] = $curr_table[0];
} else if ($curr_table[0] == $cfg['Server']['history']) {
$cfgRelation['history'] = $curr_table[0];
}
} // end while
if (isset($cfgRelation['relation'])) {
Expand All @@ -139,11 +143,42 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){
}
if (isset($cfgRelation['column_info'])) {
$cfgRelation['commwork'] = TRUE;

if ($cfg['Server']['verbose_check']) {
$mime_query = 'SHOW FIELDS FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']);
$mime_rs = PMA_query_as_cu($mime_query, FALSE);

$mime_field_mimetype = FALSE;
$mime_field_transformation = FALSE;
$mime_field_transformation_options = FALSE;
while ($curr_mime_field = @PMA_mysql_fetch_array($mime_rs)) {
if ($curr_mime_field[0] == 'mimetype') {
$mime_field_mimetype = TRUE;
} else if ($curr_mime_field[0] == 'transformation') {
$mime_field_transformation = TRUE;
} else if ($curr_mime_field[0] == 'transformation_options') {
$mime_field_transformation_options = TRUE;
}
}

if ($mime_field_mimetype == TRUE
&& $mime_field_transformation == TRUE
&& $mime_field_transformation_options == TRUE) {
$cfgRelation['mimework'] = TRUE;
}
} else {
$cfgRelation['mimework'] = TRUE;
}
}
} // end if

if (isset($cfgRelation['history'])) {
$cfgRelation['historywork'] = TRUE;
}

if ($cfgRelation['relwork'] == TRUE && $cfgRelation['displaywork'] == TRUE
&& $cfgRelation['pdfwork'] == TRUE && $cfgRelation['commwork'] == TRUE) {
&& $cfgRelation['pdfwork'] == TRUE && $cfgRelation['commwork'] == TRUE
&& $cfgRelation['mimework'] && $cfgRelation['historywork']) {
$cfgRelation['allworks'] = TRUE;
}
if ($tab_rs) {
Expand Down Expand Up @@ -197,6 +232,19 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){
echo ' <tr><td colspan=2 align="center">' . $GLOBALS['strColComFeat'] . ': '
. (($cfgRelation['commwork'] == TRUE) ? $enabled : $disabled)
. '</td></tr>' . "\n";
echo ' <tr><td colspan=2 align="center">MIME: '
. (($cfgRelation['mimework'] == TRUE) ? $enabled : $disabled)
. '</td></tr>' . "\n";

// . '<br />(MIME: ' . (($cfgRelation['mimework'] == TRUE) ? $enabled : $disabled) . ')'

echo ' <tr><th align="left">$cfg[\'Servers\'][$i][\'history\'] ... </th><td align="right">'
. ((isset($cfgRelation['history'])) ? $hit : sprintf($shit, 'history'))
. '</td></tr>' . "\n";
echo ' <tr><td colspan=2 align="center">' . $GLOBALS['strQuerySQLHistory'] . ': '
. (($cfgRelation['historywork'] == TRUE) ? $enabled : $disabled)
. '</td></tr>' . "\n";

echo '</table>' . "\n";
} // end if ($verbose == TRUE) {

Expand Down
11 changes: 11 additions & 0 deletions scripts/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,14 @@ CREATE TABLE `PMA_column_comments` (
PRIMARY KEY (id),
UNIQUE KEY db_name (db_name, table_name, column_name)
) TYPE=MyISAM COMMENT='Comments for Columns';

CREATE TABLE `PMA_history` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`username` VARCHAR( 64 ) NOT NULL ,
`db` VARCHAR( 64 ) NOT NULL ,
`table` VARCHAR( 64 ) NOT NULL ,
`timevalue` TIMESTAMP NOT NULL ,
`sqlquery` TEXT NOT NULL ,
PRIMARY KEY ( `id` ) ,
INDEX ( `username` , `db` , `table` , `timevalue` )
) TYPE=MyISAM COMMENT='SQL history';
17 changes: 1 addition & 16 deletions tbl_addfield.php3
Original file line number Diff line number Diff line change
Expand Up @@ -207,28 +207,13 @@ if (isset($submit)) {
}

// garvin: Update comment table for mime types [MIME]
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfg['BrowseMIME']) {
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
@reset($field_mimetype);
while(list($fieldindex, $mimetype) = each($field_mimetype)) {
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
}
}

// garvin: If comments were sent, enable relation stuff
require('./libraries/relation.lib.php3');
require('./libraries/transformations.lib.php3');

$cfgRelation = PMA_getRelationsParam();

// garvin: Update comment table for mime types [MIME]
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfg['BrowseMIME']) {
@reset($field_mimetype);
while(list($fieldindex, $mimetype) = each($field_mimetype)) {
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
}
}


// Go back to the structure sub-page
$sql_query = $sql_query_cpy;
unset($sql_query_cpy);
Expand Down
2 changes: 1 addition & 1 deletion tbl_alter.php3
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if (isset($submit)) {
}

// garvin: Update comment table for mime types [MIME]
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfg['BrowseMIME']) {
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
@reset($field_mimetype);
while(list($fieldindex, $mimetype) = each($field_mimetype)) {
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
Expand Down
2 changes: 1 addition & 1 deletion tbl_create.php3
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ if (isset($submit)) {
}

// garvin: Update comment table for mime types [MIME]
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfg['BrowseMIME']) {
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
@reset($field_mimetype);
while(list($fieldindex, $mimetype) = each($field_mimetype)) {
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
Expand Down
32 changes: 26 additions & 6 deletions tbl_move_copy.php3
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,24 @@ if (isset($new_name) && trim($new_name) != '') {
} else {
// garvin: Create new entries as duplicates from old comments
if ($cfgRelation['commwork']) {
// Write every comment as new copied entry. [MIME]
while ($comments_copy_row = @PMA_mysql_fetch_array($comments_copy_rs)) {
$new_comment_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
. ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ', mimetype, transformation, transformation_options) '
. ' VALUES('
. '\'' . PMA_sqlAddslashes($target_db) . '\','
. '\'' . PMA_sqlAddslashes($new_name) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['column_name']) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['comment']) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['mimetype']) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['transformation']) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['transformation_options']) . '\')';
$new_comment_rs = PMA_query_as_cu($new_comment_query);
} // end while

// Get all comments and MIME-Types for current table
$comments_copy_query = 'SELECT
column_name, ' . PMA_backquote('comment') . '
column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
FROM ' . PMA_backquote($cfgRelation['column_info']) . '
WHERE
db_name = \'' . PMA_sqlAddslashes($db) . '\' AND
Expand All @@ -154,11 +169,16 @@ if (isset($new_name) && trim($new_name) != '') {
// Write every comment as new copied entry. [MIME]
while ($comments_copy_row = @PMA_mysql_fetch_array($comments_copy_rs)) {
$new_comment_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_info'])
. ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') '
. ' VALUES('
. '\'' . PMA_sqlAddslashes($target_db) . '\','
. '\'' . PMA_sqlAddslashes($new_name) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['comment']) . '\')';
. ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') '
. ' VALUES('
. '\'' . PMA_sqlAddslashes($target_db) . '\','
. '\'' . PMA_sqlAddslashes($new_name) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['column_name']) . '\''
. ($cfgRelation['mimework'] ? ',\'' . PMA_handleSlashes($comments_copy_row['comment']) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['mimetype']) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['transformation']) . '\','
. '\'' . PMA_handleSlashes($comments_copy_row['transformation_options']) . '\'' : '')
. ')';
$new_comment_rs = PMA_query_as_cu($new_comment_query);
} // end while
}
Expand Down
6 changes: 3 additions & 3 deletions tbl_properties.inc.php3
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if ($cfgRelation['commwork']) {
$comments_map = PMA_getComments($db, $table);
echo '<th>' . $strComments . '</th>';

if ($cfg['BrowseMIME']) {
if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
$mime_map = PMA_getMIME($db, $table);
$available_mime = PMA_getAvailableMIMEtypes();

Expand Down Expand Up @@ -255,7 +255,7 @@ for ($i = 0 ; $i < $num_fields; $i++) {
}

// garvin: MIME-types
if ($cfg['BrowseMIME'] && $cfgRelation['commwork']) {
if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) {
?>
<td bgcolor="<?php echo $bgcolor; ?>" valign="top">
<select id="field_<?php echo $i; ?>_8" size="1" name="field_mimetype[]">
Expand Down Expand Up @@ -462,7 +462,7 @@ echo "\n";
</tr>

<?php
if ($cfgRelation['commwork'] && $cfg['BrowseMIME']) {
if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
?>
<tr>
<td valign="top" rowspan="2">***&nbsp;</td>
Expand Down
4 changes: 2 additions & 2 deletions tbl_properties_structure.php3
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if ($GLOBALS['cfg']['ShowPropertyComments']) {
if ($cfgRelation['commwork']) {
$comments_map = PMA_getComments($db, $table);

if ($cfg['BrowseMIME']) {
if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
$mime_map = PMA_getMIME($db, $table, true);
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ while ($row = PMA_mysql_fetch_array($fields_rs)) {
}

// garvin: Display basic mimetype [MIME]
if ($cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
$type .= '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
}

Expand Down
2 changes: 1 addition & 1 deletion transformation_wrapper.php3
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ else

$default_ct = 'application/octet-stream';

if ($cfgRelation['commwork']) {
if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
$mime_map = PMA_getMime($db, $table);
$mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));

Expand Down

0 comments on commit 63c5582

Please sign in to comment.