Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/8.1' into 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Aug 5, 2023
2 parents 65c0534 + c889823 commit 209c0ab
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add-pr-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Maybe remove base branch label
Expand Down
2 changes: 1 addition & 1 deletion Neos.Eel/Classes/Helper/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function pregSplit($string, $pattern, $limit = -1)
*/
public function replace($string, $search, $replace)
{
return str_replace($search, $replace, (string)$string);
return str_replace((string)$search, (string)$replace, (string)$string);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Neos.Flow.Log/Classes/Backend/FileBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function append(string $message, int $severity = LOG_INFO, $additionalDat
}
$ipAddress = ($this->logIpAddress === true) ? str_pad(($_SERVER['REMOTE_ADDR'] ?? ''), 15) : '';
$severityLabel = $this->severityLabels[$severity] ?? 'UNKNOWN ';
$output = (new \DateTime())->format('y-m-d H:m:i') . $processId . ' ' . $ipAddress . $severityLabel . ' ' . str_pad((string)$packageKey, 20) . ' ' . $message;
$output = (new \DateTime())->format('y-m-d H:i:s') . $processId . ' ' . $ipAddress . $severityLabel . ' ' . str_pad((string)$packageKey, 20) . ' ' . $message;

if ($this->logMessageOrigin === true && ($className !== null || $methodName !== null)) {
$output .= ' [logged in ' . $className . '::' . $methodName . '()]';
Expand Down
27 changes: 22 additions & 5 deletions Neos.Flow/Classes/Configuration/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ class ConfigurationManager
protected $cacheNeedsUpdate = false;

/**
* An absolute file path to store configuration caches in. If null no cache will be active.
* An absolute file path to store configuration caches in. If not set, no cache will be active.
*
* @var string
* @var string|null
*/
protected $temporaryDirectoryPath;
protected $temporaryDirectoryPath = null;

/**
* @var array
Expand All @@ -174,12 +174,18 @@ public function __construct(ApplicationContext $context)
}

/**
* Set an absolute file path to store configuration caches in. If null no cache will be active.
* Set an absolute file path to store configuration caches in.
*
* If never called no cache will be active.
*
* @param string $temporaryDirectoryPath
*/
public function setTemporaryDirectoryPath(string $temporaryDirectoryPath): void
{
if (!is_dir($temporaryDirectoryPath)) {
throw new \RuntimeException(sprintf('Cannot set temporaryDirectoryPath to "%s" for the ConfigurationManager cache, as it must be a valid directory.', $temporaryDirectoryPath));
}

$this->temporaryDirectoryPath = $temporaryDirectoryPath;

$this->loadConfigurationsFromCache();
Expand Down Expand Up @@ -246,7 +252,9 @@ private function convertLegacyProcessingType(string $configurationType, string $
return new ObjectsLoader(new YamlSource());
case self::CONFIGURATION_PROCESSING_TYPE_POLICY:
$policyLoader = new PolicyLoader(new YamlSource());
$policyLoader->setTemporaryDirectoryPath($this->temporaryDirectoryPath);
if ($this->temporaryDirectoryPath) {
$policyLoader->setTemporaryDirectoryPath($this->temporaryDirectoryPath);
}
return $policyLoader;
case self::CONFIGURATION_PROCESSING_TYPE_ROUTES:
return new RoutesLoader(new YamlSource(), $this);
Expand Down Expand Up @@ -374,6 +382,9 @@ protected function replaceConfigurationForConfigurationType(string $configuratio
*/
protected function loadConfigurationsFromCache(): void
{
if ($this->temporaryDirectoryPath === null) {
return;
}
$cachePathAndFilename = $this->constructConfigurationCachePath();
/** @noinspection UsingInclusionReturnValueInspection */
$configurations = @include $cachePathAndFilename;
Expand Down Expand Up @@ -423,6 +434,11 @@ protected function processConfigurationType(string $configurationType)
$this->writeConfigurationCacheFile($cachePathAndFilename, $configurationType);
$this->replaceConfigurationForConfigurationType($configurationType, $cachePathAndFilename);
@unlink($cachePathAndFilename);
} else {
// in case the cache is disabled (implicitly, because temporaryDirectoryPath is null)
// we need to still handle replacing the environment variables like `%FLOW_PATH_ROOT%` in the configuration
$configuration = $this->unprocessedConfiguration[$configurationType];
$this->configurations[$configurationType] = eval('return ' . $this->replaceVariablesInPhpString(var_export($configuration, true)) . ';');
}
}

Expand Down Expand Up @@ -547,6 +563,7 @@ protected function replaceVariablesInPhpString(string $phpString): string
*/
protected function constructConfigurationCachePath(): string
{
assert($this->temporaryDirectoryPath !== null, 'ConfigurationManager::$temporaryDirectoryPath must not be null.');
$configurationCachePath = $this->temporaryDirectoryPath . 'Configuration/';
return $configurationCachePath . str_replace('/', '_', (string)$this->context) . 'Configurations.php';
}
Expand Down
100 changes: 75 additions & 25 deletions Neos.Flow/Classes/Core/Booting/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static function initializePackageManagement(Bootstrap $bootstrap)
* @return void
* @throws FlowException
*/
public static function initializeConfiguration(Bootstrap $bootstrap)
public static function initializeConfiguration(Bootstrap $bootstrap, bool $enableCache = true)
{
$context = $bootstrap->getContext();
$environment = new Environment($context);
Expand All @@ -204,7 +204,9 @@ public static function initializeConfiguration(Bootstrap $bootstrap)

$configurationManager = new ConfigurationManager($context);
$configurationManager->setPackages($packageManager->getFlowPackages());
$configurationManager->setTemporaryDirectoryPath($environment->getPathToTemporaryDirectory());
if ($enableCache) {
$configurationManager->setTemporaryDirectoryPath($environment->getPathToTemporaryDirectory());
}

$yamlSource = new YamlSource();
$configurationManager->registerConfigurationType(ConfigurationManager::CONFIGURATION_TYPE_CACHES, new MergeLoader($yamlSource, ConfigurationManager::CONFIGURATION_TYPE_CACHES));
Expand Down Expand Up @@ -668,18 +670,18 @@ public static function initializeResources(Bootstrap $bootstrap)
*
* @param string $commandIdentifier E.g. neos.flow:cache:flush
* @param array $settings The Neos.Flow settings
* @param boolean $outputResults if false the output of this command is only echoed if the execution was not successful
* @param boolean $outputResults Echo the commands output on success
* @param array $commandArguments Command arguments
* @return boolean true if the command execution was successful (exit code = 0)
* @return true Legacy return value. Will always be true. A failure is expressed as a thrown exception
* @throws Exception\SubProcessException The execution of the sub process failed
* @api
* @throws Exception\SubProcessException if execution of the sub process failed
*/
public static function executeCommand(string $commandIdentifier, array $settings, bool $outputResults = true, array $commandArguments = []): bool
{
$command = self::buildSubprocessCommand($commandIdentifier, $settings, $commandArguments);
$output = [];
// Output errors in response
$command .= ' 2>&1';
$output = [];
exec($command, $output, $result);
if ($result !== 0) {
if (count($output) > 0) {
Expand All @@ -691,11 +693,11 @@ public static function executeCommand(string $commandIdentifier, array $settings
// If anything else goes wrong, it may as well not produce any $output, but might do so when run on an interactive
// shell. Thus we dump the command next to the exception dumps.
$exceptionMessage .= ' Try to run the command manually, to hopefully get some hint on the actual error.';

if (!file_exists(FLOW_PATH_DATA . 'Logs/Exceptions')) {
Files::createDirectoryRecursively(FLOW_PATH_DATA . 'Logs/Exceptions');
}
if (file_exists(FLOW_PATH_DATA . 'Logs/Exceptions') && is_dir(FLOW_PATH_DATA . 'Logs/Exceptions') && is_writable(FLOW_PATH_DATA . 'Logs/Exceptions')) {
// Logs the command string `php ./flow foo:bar` inside `Logs/Exceptions/123-command.txt`
$referenceCode = date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5(rand()), 0, 6);
$errorDumpPathAndFilename = FLOW_PATH_DATA . 'Logs/Exceptions/' . $referenceCode . '-command.txt';
file_put_contents($errorDumpPathAndFilename, $command);
Expand All @@ -709,7 +711,8 @@ public static function executeCommand(string $commandIdentifier, array $settings
if ($outputResults) {
echo implode(PHP_EOL, $output);
}
return $result === 0;
// Legacy return value
return true;
}

/**
Expand Down Expand Up @@ -766,7 +769,7 @@ protected static function buildSubprocessCommand(string $commandIdentifier, arra
/**
* @param array $settings The Neos.Flow settings
* @return string A command line command for PHP, which can be extended and then exec()uted
* @throws FlowException
* @throws Exception\SubProcessException in case the phpBinaryPathAndFilename is incorrect
*/
public static function buildPhpCommand(array $settings): string
{
Expand Down Expand Up @@ -815,7 +818,7 @@ public static function buildPhpCommand(array $settings): string
* This avoids config errors where users forget to set Neos.Flow.core.phpBinaryPathAndFilename in CLI.
*
* @param string $phpBinaryPathAndFilename
* @throws FlowException
* @throws Exception\SubProcessException in case the php binary doesn't exist / is a different one for the current cli request
*/
protected static function ensureCLISubrequestsUseCurrentlyRunningPhpBinary($phpBinaryPathAndFilename)
{
Expand All @@ -824,30 +827,50 @@ protected static function ensureCLISubrequestsUseCurrentlyRunningPhpBinary($phpB
return;
}

// Ensure the actual PHP binary is known before checking if it is correct. If empty, we ignore it because it is checked later in the script.
if (strlen($phpBinaryPathAndFilename) === 0) {
return;
// Ensure the actual PHP binary is known before checking if it is correct.
if (!$phpBinaryPathAndFilename || strlen($phpBinaryPathAndFilename) === 0) {
throw new Exception\SubProcessException('"Neos.Flow.core.phpBinaryPathAndFilename" is not set.', 1689676816060);
}

$command = [];
if (PHP_OS_FAMILY !== 'Windows') {
// Handle possible fast cgi: send empty stdin to close possible fast cgi server
//
// in case the phpBinaryPathAndFilename points to a fast cgi php binary we will get caught in an endless process
// the fast cgi will expect input from the stdin and otherwise continue listening
// to close the stdin we send an empty string
// related https://bugs.php.net/bug.php?id=71209
$command[] = 'echo "" | ';
}
$command[] = $phpBinaryPathAndFilename;
$command[] = <<<'EOF'
-r "echo realpath(PHP_BINARY);"
EOF;
$command[] = '2>&1'; // Output errors in response

// Try to resolve which binary file PHP is pointing to
exec($phpBinaryPathAndFilename . ' -r "echo realpath(PHP_BINARY);"', $output, $result);
if ($result === 0 && sizeof($output) === 1) {
exec(join(' ', $command), $output, $result);

if ($result === 0 && count($output) === 1) {
// Resolve any wrapper
$configuredPhpBinaryPathAndFilename = $output[0];
} else {
// Resolve any symlinks that the configured php might be pointing to
$configuredPhpBinaryPathAndFilename = realpath($phpBinaryPathAndFilename);
}

// if the configured PHP binary is empty here, the file does not exist. We ignore that here because it is checked later in the script.
// if the configured PHP binary is empty here, the file does not exist.
if ($configuredPhpBinaryPathAndFilename === false || strlen($configuredPhpBinaryPathAndFilename) === 0) {
return;
throw new Exception\SubProcessException(
sprintf('The configured PHP binary "%s" via setting the "Neos.Flow.core.phpBinaryPathAndFilename" doesnt exist.', $phpBinaryPathAndFilename),
1689676923331
);
}

exec(PHP_BINARY . ' -r "echo realpath(PHP_BINARY);"', $output);
$realPhpBinary = $output[0];
if (strcmp($realPhpBinary, $configuredPhpBinaryPathAndFilename) !== 0) {
throw new FlowException(sprintf(
throw new Exception\SubProcessException(sprintf(
'You are running the Flow CLI with a PHP binary different from the one Flow is configured to use internally. ' .
'Flow has been run with "%s", while the PHP version Flow is configured to use for subrequests is "%s". Make sure to configure Flow to ' .
'use the same PHP binary by setting the "Neos.Flow.core.phpBinaryPathAndFilename" configuration option to "%s". Flush the ' .
Expand All @@ -865,7 +888,7 @@ protected static function ensureCLISubrequestsUseCurrentlyRunningPhpBinary($phpB
* server.
*
* @param string $phpCommand the completely build php string that is used to execute subrequests
* @throws FlowException
* @throws Exception\SubProcessException in case the php binary doesn't exist, or is not suitable for cli usage, or its version doesn't match
*/
protected static function ensureWebSubrequestsUseCurrentlyRunningPhpVersion($phpCommand)
{
Expand All @@ -874,21 +897,48 @@ protected static function ensureWebSubrequestsUseCurrentlyRunningPhpVersion($php
return;
}

exec($phpCommand . ' -r "echo PHP_VERSION;"', $output, $result);
$command = [];
if (PHP_OS_FAMILY !== 'Windows') {
// Handle possible fast cgi: send empty stdin to close possible fast cgi server
//
// in case the phpBinaryPathAndFilename points to a fast cgi php binary we will get caught in an endless process
// the fast cgi will expect input from the stdin and otherwise continue listening
// to close the stdin we send an empty string
// related https://bugs.php.net/bug.php?id=71209
$command[] = 'echo "" | ';
}
$command[] = $phpCommand;
$command[] = <<<'EOF'
-r "echo json_encode(['sapi' => PHP_SAPI, 'version' => PHP_VERSION]);"
EOF;
$command[] = '2>&1'; // Output errors in response

exec(join(' ', $command), $output, $result);

if ($result !== 0) {
return;
$phpInformation = json_decode($output[0] ?? '{}', true) ?: [];

if ($result !== 0 || ($phpInformation['sapi'] ?? null) !== 'cli') {
throw new Exception\SubProcessException(sprintf('PHP binary might not exist or is not suitable for cli usage. Command `%s` didnt succeed.', $phpCommand), 1689676967447);
}

$configuredPHPVersion = $output[0];
if (array_slice(explode('.', $configuredPHPVersion), 0, 2) !== array_slice(explode('.', PHP_VERSION), 0, 2)) {
/**
* Checks if two (php) versions equal by comparing major and minor.
* Differences in the patch level will be ignored.
*
* versionsAlmostEqual(8.1.0, 8.1.1) === true
*/
$versionsAlmostEqual = function (string $oneVersion, string $otherVersion): bool {
return array_slice(explode('.', $oneVersion), 0, 2) === array_slice(explode('.', $otherVersion), 0, 2);
};

if (!$versionsAlmostEqual($phpInformation['version'], PHP_VERSION)) {
throw new FlowException(sprintf(
'You are executing Neos/Flow with a PHP version different from the one Flow is configured to use internally. ' .
'Flow is running with with PHP "%s", while the PHP version Flow is configured to use for subrequests is "%s". Make sure to configure Flow to ' .
'use the same PHP version by setting the "Neos.Flow.core.phpBinaryPathAndFilename" configuration option to a PHP-CLI binary of the version ' .
'%s. Flush the caches by removing the folder Data/Temporary before executing Flow/Neos again.',
PHP_VERSION,
$configuredPHPVersion,
$phpInformation['version'],
PHP_VERSION
), 1536563428);
}
Expand Down
4 changes: 3 additions & 1 deletion Neos.Flow/Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public function boot(Core\Bootstrap $bootstrap)
}
$objectManager = $bootstrap->getObjectManager();
$resourceManager = $objectManager->get(ResourceManager::class);
$resourceManager->getCollection(ResourceManager::DEFAULT_STATIC_COLLECTION_NAME)->publish();
if ($staticCollection = $resourceManager->getCollection(ResourceManager::DEFAULT_STATIC_COLLECTION_NAME)) {
$staticCollection->publish();
}
};

$dispatcher->connect(Monitor\FileMonitor::class, 'filesHaveChanged', $publishResources);
Expand Down
4 changes: 2 additions & 2 deletions Neos.Flow/Classes/Session/SessionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function getId();
public function renewId();

/**
* Returns the contents (array) associated with the given key.
* Returns the content (mixed) associated with the given key.
*
* @param string $key An identifier for the content stored in the session.
* @return array The contents associated with the given key
* @return mixed The contents associated with the given key
* @throws Exception\SessionNotStartedException
*/
public function getData($key);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
`7.3.14 (2023-07-17) <https://github.com/neos/flow-development-collection/releases/tag/7.3.14>`_
================================================================================================

Overview of merged pull requests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`BUGFIX: If bytes to read is not > 0, return empty string <https://github.com/neos/flow-development-collection/pull/3096>`_
---------------------------------------------------------------------------------------------------------------------------

* Fixes: `#2929 <https://github.com/neos/flow-development-collection/issues/2929>`_

**Upgrade instructions**

**Review instructions**


* Packages: ``Flow`` ``Cache``

`TASK: PHP 8.1 deprecations compatibility <https://github.com/neos/flow-development-collection/pull/3094>`_
-----------------------------------------------------------------------------------------------------------

This tweaks the code so that it runs without deprecations on PHP 8.1.

**Upgrade instructions**

None.

**Review instructions**

None.


* Packages: ``Flow``

`TASK: Apply fixes from StyleCI <https://github.com/neos/flow-development-collection/pull/3107>`_
-------------------------------------------------------------------------------------------------

This pull request applies code style fixes from an analysis carried out by `StyleCI <https://github.styleci.io>`_.

---

For more information, click `here <https://github.styleci.io/analyses/nepNQA>`_.

* Packages: ``Flow`` ``Utility.ObjectHandling``

`Detailed log <https://github.com/neos/flow-development-collection/compare/7.3.13...7.3.14>`_
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 comments on commit 209c0ab

Please sign in to comment.