Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
31b6994859
@ -1530,4 +1530,76 @@ function PMA_REL_createPage($newpage, $cfgRelation, $db)
|
||||
isset($GLOBALS['controllink']) ? $GLOBALS['controllink'] : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get child table references for a table column.
|
||||
*
|
||||
* @param string $db name of master table db.
|
||||
* @param string $table name of master table.
|
||||
* @param string $column name of master table column.
|
||||
*
|
||||
* @return array $child_references
|
||||
*/
|
||||
function PMA_getChildReferences($db, $table, $column)
|
||||
{
|
||||
$child_references = array();
|
||||
$i=0;
|
||||
$rel_query = 'SELECT `column_name`,'
|
||||
. ' `table_name`,'
|
||||
. '`table_schema`'
|
||||
. ' FROM `information_schema`.`key_column_usage`'
|
||||
. ' WHERE `referenced_column_name` = \''
|
||||
. PMA_Util::sqlAddSlashes($column) . '\''
|
||||
. ' AND `referenced_table_name` = \''
|
||||
. PMA_Util::sqlAddSlashes($table) . '\''
|
||||
. ' AND `referenced_table_schema` = \''
|
||||
. PMA_Util::sqlAddSlashes($db) . '\'';
|
||||
|
||||
$result = $GLOBALS['dbi']->tryQuery($rel_query, $GLOBALS['controllink']);
|
||||
if ($result == true) {
|
||||
while(($row = $GLOBALS['dbi']->fetchAssoc($result))) {
|
||||
$child_references[$i++] = $row;
|
||||
}
|
||||
}
|
||||
return $child_references;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check child table references and foreign key for a table column.
|
||||
*
|
||||
* @param string $db name of master table db.
|
||||
* @param string $table name of master table.
|
||||
* @param string $column name of master table column.
|
||||
*
|
||||
* @return array $column_status telling about references if foreign key.
|
||||
*/
|
||||
function PMA_checkChildForeignReferences($db, $table, $column)
|
||||
{
|
||||
$column_status = array();
|
||||
$column_status['isEditable'] = false;
|
||||
$column_status['isReferenced'] = false;
|
||||
$column_status['isForeignKey'] = false;
|
||||
$column_status['references'] = array();
|
||||
$foreigners = PMA_getForeigners($db, $table, $column);
|
||||
$child_references = PMA_getChildReferences($db, $table, $column);
|
||||
|
||||
if (sizeof($child_references, 0) > 0 || sizeof($foreigners[$column], 0) > 0) {
|
||||
if (sizeof($child_references, 0) > 0) {
|
||||
$column_status['isReferenced'] = true;
|
||||
foreach ($child_references as $row => $columns) {
|
||||
array_push($column_status['references'],
|
||||
PMA_Util::backquote($columns['table_schema'])
|
||||
. '.' . PMA_Util::backquote($columns['table_name']));
|
||||
}
|
||||
}
|
||||
|
||||
if (sizeof($foreigners[$column], 0) > 0) {
|
||||
$column_status['isForeignKey'] = true;
|
||||
}
|
||||
} else {
|
||||
$column_status['isEditable'] = true;
|
||||
}
|
||||
|
||||
return $column_status;
|
||||
}
|
||||
?>
|
||||
|
||||
@ -79,6 +79,7 @@ if (isset($_REQUEST['submit_num_fields'])) {
|
||||
//if adding new fields, set regenerate to keep the original values
|
||||
$regenerate = 1;
|
||||
}
|
||||
|
||||
for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
|
||||
if (! empty($regenerate)) {
|
||||
list($columnMeta, $submit_length, $submit_attribute,
|
||||
@ -133,6 +134,10 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
|
||||
$columnMeta, $length, $_form_params, $columnNumber
|
||||
);
|
||||
}
|
||||
// Variable tell if current column is bound in a foreign key constraint or not.
|
||||
$columnMeta['column_status'] = PMA_checkChildForeignReferences($_form_params['db'],
|
||||
$_form_params['table'],
|
||||
isset($columnMeta) ? $columnMeta['Field'] : null);
|
||||
|
||||
$content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes(
|
||||
$columnNumber, isset($columnMeta) ? $columnMeta : null, strtoupper($type),
|
||||
@ -148,7 +153,6 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
|
||||
$mime_map
|
||||
);
|
||||
} // end for
|
||||
|
||||
$html = PMA_getHtmlForTableCreateOrAddField(
|
||||
$action, $_form_params, $content_cells, $header_cells
|
||||
);
|
||||
|
||||
@ -562,9 +562,20 @@ function PMA_getColumnMetaForDefault($columnMeta, $isDefault)
|
||||
*/
|
||||
function PMA_getHtmlForColumnName($columnNumber, $ci, $ci_offset, $columnMeta)
|
||||
{
|
||||
$html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
|
||||
$title = '';
|
||||
$title .= (isset($columnMeta['column_status'])
|
||||
&& $columnMeta['column_status']['isReferenced']) ? __('Referenced by ')
|
||||
. implode(",", $columnMeta['column_status']['references']) . "." : '';
|
||||
$title .= (!empty($title) && isset($columnMeta['column_status'])
|
||||
&& $columnMeta['column_status']['isForeignKey']) ? "\n" : '';
|
||||
$title .= (isset($columnMeta['column_status'])
|
||||
&& $columnMeta['column_status']['isForeignKey']) ? __('Is a Foreign Key.') : '';
|
||||
$title .= (empty($title)) ? __('Column') : '';
|
||||
$html = '<input' . (isset($columnMeta['column_status'])
|
||||
&& !$columnMeta['column_status']['isEditable']?' disabled="disabled" ':' ')
|
||||
. 'id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
|
||||
. '"' . ' type="text" name="field_name[' . $columnNumber . ']"'
|
||||
. ' maxlength="64" class="textfield" title="' . __('Column') . '"'
|
||||
. ' maxlength="64" class="textfield" title="' . $title . '"'
|
||||
. ' size="10"'
|
||||
. ' value="'
|
||||
. (isset($columnMeta['Field'])
|
||||
@ -584,11 +595,14 @@ function PMA_getHtmlForColumnName($columnNumber, $ci, $ci_offset, $columnMeta)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getHtmlForColumnType($columnNumber, $ci, $ci_offset, $type_upper)
|
||||
function PMA_getHtmlForColumnType($columnNumber, $ci, $ci_offset,
|
||||
$type_upper, $columnMeta)
|
||||
{
|
||||
$select_id = 'field_' . $columnNumber . '_' . ($ci - $ci_offset);
|
||||
$html = '<select class="column_type" name="field_type[' .
|
||||
$columnNumber . ']"' . ' id="' . $select_id . '">';
|
||||
$html = '<select' . (isset($columnMeta['column_status'])
|
||||
&& !$columnMeta['column_status']['isEditable']?' disabled="disabled" ':' ')
|
||||
. 'class="column_type" name="field_type['
|
||||
. $columnNumber . ']"' . ' id="' . $select_id . '">';
|
||||
$html .= PMA_Util::getSupportedDatatypes(true, $type_upper);
|
||||
$html .= ' </select>';
|
||||
|
||||
@ -1165,7 +1179,7 @@ function PMA_getHtmlForColumnAttributes($columnNumber, $columnMeta, $type_upper,
|
||||
|
||||
// column type
|
||||
$content_cell[$ci] = PMA_getHtmlForColumnType(
|
||||
$columnNumber, $ci, $ci_offset, $type_upper
|
||||
$columnNumber, $ci, $ci_offset, $type_upper, isset($columnMeta) ? $columnMeta : null
|
||||
);
|
||||
$ci++;
|
||||
|
||||
|
||||
@ -617,7 +617,9 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
|
||||
public function testGetHtmlForColumnName()
|
||||
{
|
||||
$result = PMA_getHtmlForColumnName(
|
||||
2, 4, 4, array('Field' => "fieldname")
|
||||
2, 4, 4, array('Field' => "fieldname",
|
||||
'column_status' => array('isReferenced' => false,
|
||||
'isForeignKey' => false, 'isEditable' => true))
|
||||
);
|
||||
|
||||
$this->assertTag(
|
||||
@ -639,7 +641,8 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$GLOBALS['PMA_Types'] = new PMA_Types;
|
||||
$result = PMA_getHtmlForColumnType(
|
||||
1, 4, 3, false
|
||||
1, 4, 3, false, array('column_status' => array('isReferenced' => false,
|
||||
'isForeignKey' => false, 'isEditable' => true))
|
||||
);
|
||||
|
||||
$this->assertTag(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user