From b9dde78466396fa25da58a5111251b985ac6a5a9 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 5 Jan 2025 23:12:22 +0100 Subject: [PATCH] Centralize deprecated check --- src/Console/AbstractConsole.php | 12 ++++++++++++ src/Console/Daemon.php | 4 +--- src/Console/JetstreamDaemon.php | 4 +--- src/Console/Worker.php | 4 +--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Console/AbstractConsole.php b/src/Console/AbstractConsole.php index 8ec0addeb3..be804b43b8 100644 --- a/src/Console/AbstractConsole.php +++ b/src/Console/AbstractConsole.php @@ -23,4 +23,16 @@ abstract class AbstractConsole extends Console * @var string */ public const LOG_CHANNEL = LogChannel::CONSOLE; + + /** + * Checks, if the Console command was executed outside of`bin/console.php` and prints the correct execution + * + * @param string $command the current command + */ + protected function checkDeprecated(string $command): void + { + if (substr($this->executable, -strlen('bin/console.php')) !== 'bin/console.php') { + $this->out(sprintf("'%s' is deprecated and will removed. Please use 'bin/console.php %s' instead", $this->executable, $command)); + } + } } diff --git a/src/Console/Daemon.php b/src/Console/Daemon.php index ce55754803..c8165a1d9b 100644 --- a/src/Console/Daemon.php +++ b/src/Console/Daemon.php @@ -93,9 +93,7 @@ protected function getHelp(): string protected function doExecute() { - if (substr($this->executable, -strlen('bin/console.php')) !== 'bin/console.php') { - $this->out(sprintf("'%s' is deprecated and will removed. Please use 'bin/console.php daemon' instead", $this->executable)); - } + $this->checkDeprecated('daemon'); if ($this->mode->isInstall()) { throw new RuntimeException("Friendica isn't properly installed yet"); diff --git a/src/Console/JetstreamDaemon.php b/src/Console/JetstreamDaemon.php index 06f996fa7f..d34e5780c2 100644 --- a/src/Console/JetstreamDaemon.php +++ b/src/Console/JetstreamDaemon.php @@ -79,9 +79,7 @@ protected function getHelp(): string protected function doExecute() { - if ($this->executable !== 'bin/console.php') { - $this->out(sprintf("'%s' is deprecated and will removed. Please use 'bin/console.php jetstream' instead", $this->executable)); - } + $this->checkDeprecated('jetstream'); if ($this->mode->isInstall()) { throw new RuntimeException("Friendica isn't properly installed yet"); diff --git a/src/Console/Worker.php b/src/Console/Worker.php index 2e68324c7b..1c7eeae002 100644 --- a/src/Console/Worker.php +++ b/src/Console/Worker.php @@ -69,9 +69,7 @@ protected function getHelp(): string protected function doExecute() { - if ($this->executable !== 'bin/console.php') { - $this->out(sprintf("'%s' is deprecated and will removed. Please use 'bin/console.php worker' instead", $this->executable)); - } + $this->checkDeprecated('worker'); $this->mode->setExecutor(Mode::WORKER);