diff --git a/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md b/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md index 89c337fb651..7e5cbf33522 100644 --- a/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md +++ b/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md @@ -101,6 +101,7 @@ Please make sure to set your preferred storage location ***before*** migration. - Removed BruteforceProtection - Removed PreAuthenticatedAdminToken - [Logger] Bumped `monolog/monolog` to [^3.2](https://github.com/Seldaek/monolog/blob/main/UPGRADE.md#300) and `symfony/monolog-bundle` to [^3.8](https://github.com/symfony/monolog-bundle/blob/master/CHANGELOG.md#380-2022-05-10) (which adds support for monolog v3). Please adapt your custom implementation accordingly eg. log records are now `LogRecord` Objects instead of array. +- `Pimcore\Tool\Console`: Deprecated methods `getSystemEnvironment()`, `execInBackground()` and `runPhpScriptInBackground()` have been removed, use `Symfony\Component\Process\Process` instead where possible. For long running background tasks (which should run even when parent process has exited), switch to a queue implementation. - [Ecommerce] The constructor of the indexing services (eg. `DefaultMysql`, `AbstractElasticSearch`) and related workers were changed to support the injection of monolog logger, please adapt your custom implementation. - [Bundles] - Removed support for loading bundles through `extensions.php`. diff --git a/lib/Tool/Console.php b/lib/Tool/Console.php index 0bcbcaccf95..baee494ef7f 100644 --- a/lib/Tool/Console.php +++ b/lib/Tool/Console.php @@ -24,32 +24,8 @@ final class Console { - private static ?string $systemEnvironment = null; - protected static array $executableCache = []; - /** - * @deprecated since v.6.9. - * - * @static - * - * @return string "windows" or "unix" - */ - public static function getSystemEnvironment(): string - { - if (self::$systemEnvironment == null) { - if (stripos(php_uname('s'), 'windows') !== false) { - self::$systemEnvironment = 'windows'; - } elseif (stripos(php_uname('s'), 'darwin') !== false) { - self::$systemEnvironment = 'darwin'; - } else { - self::$systemEnvironment = 'unix'; - } - } - - return self::$systemEnvironment; - } - /** * @return ($throwException is true ? string : string|false) * @@ -139,26 +115,6 @@ public static function getExecutable(string $name, bool $throwException = false) return false; } - protected static function checkComposite(string $process): bool - { - return self::checkConvert($process); - } - - protected static function checkConvert(string $executablePath): bool - { - try { - $process = new Process([$executablePath, '--help']); - $process->run(); - if (strpos($process->getOutput() . $process->getErrorOutput(), 'imagemagick.org') !== false) { - return true; - } - } catch (\Exception $e) { - // noting to do - } - - return false; - } - /** * @throws \Exception */ @@ -228,123 +184,6 @@ public static function runPhpScript(string $script, array $arguments = [], strin return $process->getOutput(); } - /** - * @param string $script - * @param array $arguments - * @param string|null $outputFile - * - * @return int - * - * @deprecated since v6.9. For long running background tasks switch to a queue implementation. - */ - public static function runPhpScriptInBackground(string $script, array $arguments = [], string $outputFile = null): int - { - $cmd = self::buildPhpScriptCmd($script, $arguments); - $process = new Process($cmd); - $commandLine = $process->getCommandLine(); - - return self::execInBackground($commandLine, $outputFile); - } - - /** - * @param string $cmd - * @param string|null $outputFile - * - * @return int - * - * @deprecated since v.6.9. Use Symfony\Component\Process\Process instead. For long running background tasks use queues. - * - * @static - */ - public static function execInBackground(string $cmd, string $outputFile = null): int - { - // windows systems - if (self::getSystemEnvironment() == 'windows') { - return self::execInBackgroundWindows($cmd, $outputFile); - } elseif (self::getSystemEnvironment() == 'darwin') { - return self::execInBackgroundUnix($cmd, $outputFile, false); - } else { - return self::execInBackgroundUnix($cmd, $outputFile); - } - } - - /** - * @param string $cmd - * @param ?string $outputFile - * @param bool $useNohup - * - * @return int - * - * @deprecated since v.6.9. For long running background tasks use queues. - * - * @static - */ - protected static function execInBackgroundUnix(string $cmd, ?string $outputFile, bool $useNohup = true): int - { - if (!$outputFile) { - $outputFile = '/dev/null'; - } - - $nice = (string) self::getExecutable('nice'); - if ($nice) { - $nice .= ' -n 19 '; - } - - if ($useNohup) { - $nohup = (string) self::getExecutable('nohup'); - if ($nohup) { - $nohup .= ' '; - } - } else { - $nohup = ''; - } - - /** - * mod_php seems to lose the environment variables if we do not set them manually before the child process is started - */ - if (strpos(php_sapi_name(), 'apache') !== false) { - foreach (['APP_ENV'] as $envVarName) { - if ($envValue = $_SERVER[$envVarName] ?? $_SERVER['REDIRECT_' . $envVarName] ?? null) { - putenv($envVarName . '='.$envValue); - } - } - } - - $commandWrapped = $nohup . $nice . $cmd . ' > '. $outputFile .' 2>&1 & echo $!'; - Logger::debug('Executing command `' . $commandWrapped . '´ on the current shell in background'); - $pid = shell_exec($commandWrapped); - - Logger::debug('Process started with PID ' . $pid); - - return (int)$pid; - } - - /** - * @param string $cmd - * @param string $outputFile - * - * @return int - * - * @deprecated since v.6.9. For long-running background tasks use queues. - * - * @static - */ - protected static function execInBackgroundWindows(string $cmd, string $outputFile): int - { - if (!$outputFile) { - $outputFile = 'NUL'; - } - - $commandWrapped = 'cmd /c ' . $cmd . ' > '. $outputFile . ' 2>&1'; - Logger::debug('Executing command `' . $commandWrapped . '´ on the current shell in background'); - - $WshShell = new \COM('WScript.Shell'); - $WshShell->Run($commandWrapped, 0, false); - Logger::debug('Process started - returning the PID is not supported on Windows Systems'); - - return 0; - } - /** * @param string[]|string $cmd * diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e3fa42ea528..6e17fd2bf1d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -105,11 +105,6 @@ parameters: count: 1 path: lib/Targeting/ConditionMatcher.php - - - message: "#^Call to an undefined method COM\\:\\:Run\\(\\)\\.$#" - count: 1 - path: lib/Tool/Console.php - - message: "#^Dead catch \\- Throwable is never thrown in the try block\\.$#" count: 1