Skip to content

Commit

Permalink
Pimcore\Tool\Console: Remove deprecated methods (pimcore#14024)
Browse files Browse the repository at this point in the history
* Pimcore\Tool\Console: Remove deprecated methods

* Remove redundant php doc

* Apply suggestions from code review
  • Loading branch information
blankse authored Jan 16, 2023
1 parent 14549a8 commit 7d15654
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
161 changes: 0 additions & 161 deletions lib/Tool/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d15654

Please sign in to comment.