52 lines
1.7 KiB
PHP
Executable File
52 lines
1.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
class DownCommand extends Command
|
|
{
|
|
protected static $defaultName = 'down';
|
|
protected static $defaultDescription = 'Coloca a aplicação em modo de manutenção';
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this
|
|
->addOption('message', 'm', InputOption::VALUE_OPTIONAL, 'A mensagem a ser exibida durante a manutenção', 'O sistema está em manutenção.')
|
|
->addOption('retry', 'r', InputOption::VALUE_OPTIONAL, 'O tempo estimado para o retorno');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$directory = dirname(__DIR__, 3) . '/storage/framework';
|
|
|
|
if (!is_dir($directory)) {
|
|
mkdir($directory, 0755, true);
|
|
}
|
|
|
|
$downFile = $directory . '/down';
|
|
|
|
if (file_exists($downFile)) {
|
|
$output->writeln('<comment>A aplicação já está em modo de manutenção.</comment>');
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
$payload = [
|
|
'time' => time(),
|
|
'message' => $input->getOption('message'),
|
|
'retry' => $input->getOption('retry'),
|
|
];
|
|
|
|
if (file_put_contents($downFile, json_encode($payload, JSON_PRETTY_PRINT))) {
|
|
$output->writeln('<info>Aplicação agora está em modo de manutenção.</info>');
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
$output->writeln('<error>Falha ao colocar a aplicação em modo de manutenção.</error>');
|
|
return Command::FAILURE;
|
|
}
|
|
}
|