Skip to content

Commit

Permalink
Extract method to get event scheduler status
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Apr 17, 2020
1 parent 9b7c493 commit fc968a2
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions libraries/classes/Database/Events.php
Expand Up @@ -462,26 +462,33 @@ public function getQueryFromRequest()
return $query;
}

public function getFooterToggleButton(): string
private function getEventSchedulerStatus(): bool
{
global $db, $table;

$es_state = $this->dbi->fetchValue(
"SHOW GLOBAL VARIABLES LIKE 'event_scheduler'",
$state = $this->dbi->fetchValue(
'SHOW GLOBAL VARIABLES LIKE \'event_scheduler\'',
0,
1
);
$es_state = mb_strtolower($es_state);
$state = strtoupper($state);

return $state === 'ON' || $state === '1';
}

public function getFooterToggleButton(): string
{
global $db, $table;

$state = $this->getEventSchedulerStatus();
$options = [
0 => [
'label' => __('OFF'),
'value' => 'SET GLOBAL event_scheduler="OFF"',
'selected' => $es_state != 'on',
'selected' => ! $state,
],
1 => [
'label' => __('ON'),
'value' => 'SET GLOBAL event_scheduler="ON"',
'selected' => $es_state == 'on',
'selected' => $state,
],
];

Expand Down

0 comments on commit fc968a2

Please sign in to comment.