Skip to content

Commit

Permalink
FEATURE: maintenance konsolen befehl vereinheitlicht
Browse files Browse the repository at this point in the history
  • Loading branch information
crydotsnake committed Feb 14, 2025
1 parent e758802 commit c77781a
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 63 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,19 @@ Dazu einfach die aktuelle IP des Servers, auf dem REDAXO installiert ist und von

## Konsole

Es wird die im Backend ausgewählte Sperrseite angezeigt. Aktivieren der Frontendsperre
Es wird die im Backend ausgewählte Sperrseite angezeigt.

Mit `maintenance:on` oder `frontend:off`
Aktivieren des Wartungsmodus:

Deaktivieren mit `maintenance:off` oder `frontend:on`
```bash
php redaxo/bin/console maintenance:toggle on
```

Deaktivieren des Wartungsmodus:

```bash
php redaxo/bin/console maintenance:toggle off
```

## Autor

Expand Down
8 changes: 6 additions & 2 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ maintenance_docs_title = Hilfe

// Console-Commands

maintenance_command_off_description = Schaltet den Wartungsmodus aus
maintenance_command_on_description = Schaltet den Wartungsmodus ein
maintenance_command_description = Schaltet den Wartungsmodus ein, oder aus
maintenance_command_mode_description = Wartungsmodus einstellen: „ein“ oder “aus“

maintenance_mode_activated = Wartungsmodus Aktiviert
maintenance_mode_deactivated = Wartungsmodus deaktiviert
maintenance_mode_already_activated = Der Wartungsmodus ist bereits aktiviert
maintenance_mode_already_deactivated = Der Wartungsmodus ist bereits deaktiviert
maintenance_mode_invalid = Ungültiges Argument! Benutze „on“ oder „off“

// Einstellungsseite Backend

Expand Down
8 changes: 6 additions & 2 deletions lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ maintenance_docs_title = Documentation

// Console-Commands

maintenance_command_off_description = Turns off maintenance mode
maintenance_command_on_description = Turns on maintenance mode
maintenance_command_description = Turns the maintenance mode on or off
maintenance_command_mode_description = Set maintenance mode: "on" or "off"

maintenance_mode_activated = Maintenance mode activated
maintenance_mode_deactivated = Maintenance mode deactivated
maintenance_mode_already_activated = Maintenance mode is already activated
maintenance_mode_already_deactivated = Maintenance mode is already deactivated
maintenance_mode_invalid = Invalid argument! Use "on" or "off"

// Backend Settings Page

Expand Down
62 changes: 62 additions & 0 deletions lib/command/maintenance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class rex_maintenance_command extends rex_console_command
{

#[Override]
protected function configure(): void
{
$this
->setName('maintenance:toggle')
->setDescription(rex_i18n::msg('maintenance_command_description'))
->addArgument(
"state",
InputArgument::OPTIONAL,
rex_i18n::msg('maintenance_command_mode_description'),
);
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = $this->getStyle($input, $output);
$io->title(rex_i18n::msg('maintenance_title'));

$state = $input->getArgument('state');

$addon = rex_addon::get('maintenance');
$currentBlockFrontendConfiguration = $addon->getConfig();

if ($currentBlockFrontendConfiguration['block_frontend'] === 1 && $state === "on")
{
$io->info(rex_i18n::msg('maintenance_mode_already_activated'));
return Command::FAILURE;
}

if ($currentBlockFrontendConfiguration['block_frontend'] === 0 && $state === "off")
{
$io->info(rex_i18n::msg('maintenance_mode_already_deactivated'));
return Command::FAILURE;
}


if ($state === "on")
{
$addon->setConfig('block_frontend', 1);
$io->success(rex_i18n::msg('maintenance_mode_activated'));
return Command::SUCCESS;
} elseif ($state === "off") {
$addon->setConfig('block_frontend', 0);
$io->success(rex_i18n::msg('maintenance_mode_deactivated'));
return Command::SUCCESS;
} else {
$io->error(rex_i18n::msg('maintenance_mode_invalid'));
return Command::INVALID;
}
}
}
25 changes: 0 additions & 25 deletions lib/command/maintenance_off.php

This file was deleted.

25 changes: 0 additions & 25 deletions lib/command/maintenance_on.php

This file was deleted.

7 changes: 1 addition & 6 deletions package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ permissions:
maintenance[frontend]: translate:maintenance[frontend] # Recht für Frontend-Einstellungen

console_commands:
maintenance:activate: rex_maintenance_command_activate
maintenance:deactivate: rex_maintenance_command_deactivate
maintenance:on: rex_maintenance_command_activate
maintenance:off: rex_maintenance_command_deactivate
frontend:off: rex_maintenance_command_activate
frontend:on: rex_maintenance_command_deactivate
maintenance:toggle: rex_maintenance_command

default_config:
http_response_code: 503 # 503, 403
Expand Down

0 comments on commit c77781a

Please sign in to comment.