Merge pull request #19717 from MauricioFauth/relations-bug-fix-for-5.2

Backport #19688 to QA_5_2
This commit is contained in:
Maurício Meneghini Fauth 2025-05-27 12:41:40 -03:00 committed by GitHub
commit e7234a200b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 35 additions and 26 deletions

View File

@ -2241,7 +2241,11 @@ class Table implements Stringable
$masterField = $multiEditColumnsName[$masterFieldMd5];
$foreignTable = $destinationTable[$masterFieldMd5];
$foreignField = $destinationColumn[$masterFieldMd5];
if (! empty($foreignDb) && ! empty($foreignTable) && ! empty($foreignField)) {
if (
$foreignDb !== ''
&& $foreignTable !== '' && $foreignTable !== null
&& $foreignField !== '' && $foreignField !== null
) {
if (! isset($existrel[$masterField])) {
$updQuery = 'INSERT INTO '
. Util::backquote($relationFeature->database)
@ -2345,20 +2349,20 @@ class Table implements Stringable
$emptyFields = false;
foreach ($masterField as $key => $oneField) {
if (
(! empty($oneField) && empty($foreignField[$key]))
|| (empty($oneField) && ! empty($foreignField[$key]))
($oneField !== '' && (! isset($foreignField[$key]) || $foreignField[$key] === ''))
|| ($oneField === '' && (isset($foreignField[$key]) && $foreignField[$key] !== ''))
) {
$emptyFields = true;
}
if (! empty($oneField) || ! empty($foreignField[$key])) {
if ($oneField !== '' || (isset($foreignField[$key]) && $foreignField[$key] !== '')) {
continue;
}
unset($masterField[$key], $foreignField[$key]);
}
if (! empty($foreignDb) && ! empty($foreignTable) && ! $emptyFields) {
if ($foreignDb !== '' && $foreignTable !== '' && ! $emptyFields) {
if (isset($existrelForeign[$masterFieldMd5])) {
$constraintName = $existrelForeign[$masterFieldMd5]['constraint'];
$onDelete = ! empty(
@ -2466,8 +2470,8 @@ class Table implements Stringable
$sqlQueryRecreate = '# Restoring the dropped constraint...' . "\n";
$sqlQueryRecreate .= $this->getSQLToCreateForeignKey(
$table,
$masterField,
$existrelForeign[$masterFieldMd5]['ref_db_name'],
$existrelForeign[$masterFieldMd5]['index_list'],
$existrelForeign[$masterFieldMd5]['ref_db_name'] ?? $GLOBALS['db'],
$existrelForeign[$masterFieldMd5]['ref_table_name'],
$existrelForeign[$masterFieldMd5]['ref_index_list'],
$existrelForeign[$masterFieldMd5]['constraint'],

View File

@ -35032,7 +35032,7 @@ parameters:
-
message: "#^Cannot access offset 'index_list' on mixed\\.$#"
count: 1
count: 2
path: libraries/classes/Table.php
-
@ -35167,7 +35167,7 @@ parameters:
-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 41
count: 30
path: libraries/classes/Table.php
-

View File

@ -13397,7 +13397,7 @@
<InvalidReturnStatement occurrences="1">
<code>$tableAutoIncrement ?? ''</code>
</InvalidReturnStatement>
<MixedArgument occurrences="49">
<MixedArgument occurrences="50">
<code>$GLOBALS['sql_auto_increments']</code>
<code>$GLOBALS['sql_indexes']</code>
<code>$_POST['constraint_name'][$masterFieldMd5]</code>
@ -13413,7 +13413,8 @@
<code>$errorUrl</code>
<code>$existrelForeign[$masterFieldMd5]['constraint']</code>
<code>$existrelForeign[$masterFieldMd5]['constraint']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_db_name']</code>
<code>$existrelForeign[$masterFieldMd5]['index_list']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_db_name'] ?? $GLOBALS['db']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_index_list']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_table_name']</code>
<code>$fields[$column]['expr']</code>
@ -13459,7 +13460,7 @@
<code>$where</code>
<code>$where</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess occurrences="32">
<MixedArrayAccess occurrences="33">
<code>$_SESSION['tmpval']['table_uiprefs'][$serverId][$this-&gt;dbName][$this-&gt;name]</code>
<code>$column['Extra']</code>
<code>$column['Extra']</code>
@ -13469,6 +13470,7 @@
<code>$existrelForeign[$masterFieldMd5]['constraint']</code>
<code>$existrelForeign[$masterFieldMd5]['constraint']</code>
<code>$existrelForeign[$masterFieldMd5]['index_list']</code>
<code>$existrelForeign[$masterFieldMd5]['index_list']</code>
<code>$existrelForeign[$masterFieldMd5]['on_delete']</code>
<code>$existrelForeign[$masterFieldMd5]['on_delete']</code>
<code>$existrelForeign[$masterFieldMd5]['on_update']</code>
@ -13619,21 +13621,23 @@
<code>$_POST['on_update'][$masterFieldMd5]</code>
<code>$_POST['on_update'][$masterFieldMd5]</code>
</PossiblyInvalidArrayOffset>
<PossiblyNullArgument occurrences="10">
<PossiblyNullArgument occurrences="11">
<code>$GLOBALS['showtable']['Name']</code>
<code>$commentsCopyRow['column_name']</code>
<code>$commentsCopyRow['comment']</code>
<code>$commentsCopyRow['mimetype']</code>
<code>$commentsCopyRow['transformation']</code>
<code>$commentsCopyRow['transformation_options']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_db_name']</code>
<code>$existrelForeign[$masterFieldMd5]['index_list']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_db_name'] ?? $GLOBALS['db']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_index_list']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_table_name']</code>
<code>$val</code>
</PossiblyNullArgument>
<PossiblyNullArrayAccess occurrences="7">
<PossiblyNullArrayAccess occurrences="8">
<code>$existrelForeign[$masterFieldMd5]['constraint']</code>
<code>$existrelForeign[$masterFieldMd5]['constraint']</code>
<code>$existrelForeign[$masterFieldMd5]['index_list']</code>
<code>$existrelForeign[$masterFieldMd5]['on_delete']</code>
<code>$existrelForeign[$masterFieldMd5]['on_update']</code>
<code>$existrelForeign[$masterFieldMd5]['ref_db_name']</code>
@ -13653,7 +13657,8 @@
<code>Generator::mysqlDie($tmpErrorCreate, $createQuery, false, '', false)</code>
<code>Generator::mysqlDie($tmpErrorDrop, $dropQuery, false, '', false)</code>
</PossiblyNullOperand>
<PossiblyNullReference occurrences="7">
<PossiblyNullReference occurrences="8">
<code>$existrelForeign[$masterFieldMd5]</code>
<code>$existrelForeign[$masterFieldMd5]</code>
<code>$existrelForeign[$masterFieldMd5]</code>
<code>$existrelForeign[$masterFieldMd5]</code>

View File

@ -44,14 +44,14 @@
{% set foreign_db = one_key['ref_db_name'] is defined
and one_key['ref_db_name'] is not null
? one_key['ref_db_name'] : db %}
{% set foreign_table = false %}
{% set foreign_table = '' %}
{% if foreign_db %}
{% set foreign_table = one_key['ref_table_name'] is defined
and one_key['ref_table_name'] is not null
? one_key['ref_table_name'] : false %}
? one_key['ref_table_name'] : '' %}
{% endif %}
{% set unique_columns = [] %}
{% if foreign_db and foreign_table %}
{% if foreign_db is not same as('') and foreign_table is not same as('') %}
{% set table_obj = table_get(foreign_table, foreign_db) %}
{% set unique_columns = table_obj.getUniqueColumns(false, false) %}
{% endif %}
@ -82,8 +82,8 @@
'table': table,
'url_params': url_params,
'databases': databases,
'foreign_db': foreign_db,
'foreign_table': foreign_table,
'foreign_db': '',
'foreign_table': '',
'unique_columns': unique_columns
} only %}
{% set i = i + 1 %}
@ -134,7 +134,7 @@
in the name attribute (see bug #1746964 ) #}
{% set myfield_md5 = column_hash_array[myfield] %}
{% set foreign_table = false %}
{% set foreign_table = '' %}
{% set foreign_column = false %}
{# Database dropdown #}
@ -155,7 +155,7 @@
{# Column dropdown #}
{% set unique_columns = [] %}
{% if foreign_db and foreign_table %}
{% if foreign_db is not same as('') and foreign_table is not same as('') %}
{% if existrel[myfield] is defined %}
{% set foreign_column = existrel[myfield]['foreign_field'] %}
{% endif %}

View File

@ -113,7 +113,7 @@
</span>
</td>
<td>
{% if foreign_db and foreign_table %}
{% if foreign_table is not same as('') %}
{% for foreign_column in one_key['ref_index_list'] %}
<span class="formelement clearfloat">
{% include 'table/relation/relational_dropdown.twig' with {

View File

@ -3,7 +3,7 @@
{% set seen_key = false %}
{% for value in values %}
<option value="{{ value }}"
{%- if (foreign is not same as(false) and value == foreign) or
{%- if (foreign is not same as('') and value == foreign) or
(not foreign and db is defined and db is same as (value)) %}
selected="selected"
{%- set seen_key = true -%}
@ -11,7 +11,7 @@
{{ value }}
</option>
{% endfor %}
{% if foreign is not same as(false) and foreign != "" and not seen_key %}
{% if foreign is not same as('') and not seen_key %}
<option value="{{ foreign }}" selected="selected">
{{ foreign }}
</option>