Skip to content

Commit e8c3985

Browse files
committed
Inline the RelationController::updateForForeignKeys() method
This allows the removal of the ResponseRenderer::callExit() method. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 73844a9 commit e8c3985

2 files changed

Lines changed: 42 additions & 56 deletions

File tree

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6386,7 +6386,7 @@ parameters:
63866386
path: src/Controllers/Table/RelationController.php
63876387

63886388
-
6389-
message: "#^Only booleans are allowed in \\|\\|, mixed given on the right side\\.$#"
6389+
message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#"
63906390
count: 1
63916391
path: src/Controllers/Table/RelationController.php
63926392

src/Controllers/Table/RelationController.php

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,47 @@ public function __invoke(ServerRequest $request): void
9797
}
9898

9999
// updates for foreign keys
100-
$this->updateForForeignKeys($table, $options, $relationsForeign);
100+
$multiEditColumnsName = $_POST['foreign_key_fields_name'] ?? null;
101+
$previewSqlData = '';
102+
$seenError = false;
103+
104+
// (for now, one index name only; we keep the definitions if the
105+
// foreign db is not the same)
106+
if (
107+
isset($_POST['destination_foreign_db'], $_POST['destination_foreign_table'])
108+
&& isset($_POST['destination_foreign_column'])
109+
) {
110+
[$html, $previewSqlData, $displayQuery, $seenError] = $table->updateForeignKeys(
111+
$_POST['destination_foreign_db'],
112+
$multiEditColumnsName,
113+
$_POST['destination_foreign_table'],
114+
$_POST['destination_foreign_column'],
115+
$options,
116+
$GLOBALS['table'],
117+
array_key_exists('foreign_keys_data', $relationsForeign)
118+
? $relationsForeign['foreign_keys_data']
119+
: [],
120+
);
121+
$this->response->addHTML($html);
122+
}
123+
124+
// If there is a request for SQL previewing.
125+
if (isset($_POST['preview_sql'])) {
126+
Core::previewSQL($previewSqlData);
127+
128+
return;
129+
}
130+
131+
if (! empty($displayQuery) && ! $seenError) {
132+
$GLOBALS['display_query'] = $displayQuery;
133+
$this->response->addHTML(
134+
Generator::getMessage(
135+
__('Your SQL query has been executed successfully.'),
136+
null,
137+
'success',
138+
),
139+
);
140+
}
101141

102142
// Updates for display field
103143
if ($relationParameters->displayFeature !== null && isset($_POST['display_field'])) {
@@ -234,60 +274,6 @@ private function updateForDisplayField(Table $table, DisplayFeature $displayFeat
234274
);
235275
}
236276

237-
/**
238-
* Update for FK
239-
*
240-
* @param Table $table Table
241-
* @param mixed[] $options Options
242-
* @param mixed[] $relationsForeign External relations
243-
*/
244-
private function updateForForeignKeys(Table $table, array $options, array $relationsForeign): void
245-
{
246-
$multiEditColumnsName = $_POST['foreign_key_fields_name'] ?? null;
247-
$previewSqlData = '';
248-
$seenError = false;
249-
250-
// (for now, one index name only; we keep the definitions if the
251-
// foreign db is not the same)
252-
if (
253-
isset($_POST['destination_foreign_db'], $_POST['destination_foreign_table'])
254-
&& isset($_POST['destination_foreign_column'])
255-
) {
256-
[$html, $previewSqlData, $displayQuery, $seenError] = $table->updateForeignKeys(
257-
$_POST['destination_foreign_db'],
258-
$multiEditColumnsName,
259-
$_POST['destination_foreign_table'],
260-
$_POST['destination_foreign_column'],
261-
$options,
262-
$GLOBALS['table'],
263-
array_key_exists('foreign_keys_data', $relationsForeign)
264-
? $relationsForeign['foreign_keys_data']
265-
: [],
266-
);
267-
$this->response->addHTML($html);
268-
}
269-
270-
// If there is a request for SQL previewing.
271-
if (isset($_POST['preview_sql'])) {
272-
Core::previewSQL($previewSqlData);
273-
274-
$this->response->callExit();
275-
}
276-
277-
if (empty($displayQuery) || $seenError) {
278-
return;
279-
}
280-
281-
$GLOBALS['display_query'] = $displayQuery;
282-
$this->response->addHTML(
283-
Generator::getMessage(
284-
__('Your SQL query has been executed successfully.'),
285-
null,
286-
'success',
287-
),
288-
);
289-
}
290-
291277
/**
292278
* Update for internal relation
293279
*

0 commit comments

Comments
 (0)