Inline Triggers::main() into the Triggers\IndexController

The main() method is handling the request/response, so it's better to
move this code to the controller.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2023-05-25 15:40:16 -03:00
parent 74b1ffbf8c
commit 81e988aac8
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
4 changed files with 34 additions and 44 deletions

View File

@ -73,6 +73,31 @@ final class IndexController extends AbstractController
*/
$GLOBALS['errors'] = [];
$this->triggers->main();
$this->triggers->handleEditor();
$this->triggers->export();
$items = Triggers::getDetails($this->dbi, $GLOBALS['db'], $GLOBALS['table']);
$hasTriggerPrivilege = Util::currentUserHasPrivilege('TRIGGER', $GLOBALS['db'], $GLOBALS['table']);
$isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']);
$rows = '';
foreach ($items as $item) {
$rows .= $this->template->render('triggers/row', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'trigger' => $item,
'has_drop_privilege' => $hasTriggerPrivilege,
'has_edit_privilege' => $hasTriggerPrivilege,
'row_class' => $isAjax ? 'ajaxInsert hide' : '',
]);
}
$this->render('triggers/list', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'items' => $items,
'rows' => $rows,
'has_privilege' => $hasTriggerPrivilege,
]);
}
}

View File

@ -44,42 +44,6 @@ class Triggers
) {
}
/**
* Main function for the triggers functionality
*/
public function main(): void
{
/**
* Process all requests
*/
$this->handleEditor();
$this->export();
$items = self::getDetails($this->dbi, $GLOBALS['db'], $GLOBALS['table']);
$hasTriggerPrivilege = Util::currentUserHasPrivilege('TRIGGER', $GLOBALS['db'], $GLOBALS['table']);
$isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']);
$rows = '';
foreach ($items as $item) {
$rows .= $this->template->render('triggers/row', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'trigger' => $item,
'has_drop_privilege' => $hasTriggerPrivilege,
'has_edit_privilege' => $hasTriggerPrivilege,
'row_class' => $isAjax ? 'ajaxInsert hide' : '',
]);
}
echo $this->template->render('triggers/list', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'items' => $items,
'rows' => $rows,
'has_privilege' => $hasTriggerPrivilege,
]);
}
/**
* Handles editor requests for adding or editing an item
*/
@ -469,7 +433,7 @@ class Triggers
echo $message->getDisplay();
}
private function export(): void
public function export(): void
{
if (empty($_GET['export_item']) || empty($_GET['item_name'])) {
return;

View File

@ -4311,10 +4311,11 @@
<MixedAssignment>
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
<code><![CDATA[$GLOBALS['errors']]]></code>
<code>$item</code>
</MixedAssignment>
<PossiblyUnusedParam>
<UnusedParam>
<code>$request</code>
</PossiblyUnusedParam>
</UnusedParam>
</file>
<file src="libraries/classes/Controllers/UserPasswordController.php">
<InvalidArrayOffset>
@ -12943,7 +12944,6 @@
<code><![CDATA[$GLOBALS['errors']]]></code>
<code>$createItem</code>
<code>$exportData</code>
<code>$item</code>
<code><![CDATA[$item['item_original_name']]]></code>
<code><![CDATA[$oneResult['action_timing']]]></code>
<code><![CDATA[$oneResult['definer']]]></code>

View File

@ -78,13 +78,14 @@ class IndexControllerTest extends AbstractTestCase
'has_edit_privilege' => true,
'row_class' => '',
]);
$this->expectOutputString($template->render('triggers/list', [
$expected = $template->render('triggers/list', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'items' => $items,
'rows' => $rows,
'has_privilege' => true,
]));
]);
$this->assertSame($expected, $response->getHTMLResult());
}
}