/** * @test */ public function saveDoesNotOverwriteExistingHeaderCommentsIfFileExists() { $pathAndFilename = vfsStream::url('testDirectory') . '/YAMLConfiguration'; $comment = '# This comment should stay' . chr(10) . 'Test: foo' . chr(10); file_put_contents($pathAndFilename . '.yaml', $comment); $configurationSource = new YamlSource(); $configurationSource->save($pathAndFilename, ['configurationFileHasBeenLoaded' => true]); $yaml = file_get_contents($pathAndFilename . '.yaml'); $this->assertContains('# This comment should stay' . chr(10) . chr(10), $yaml, 'Header comment was removed from file.'); $this->assertNotContains('Test: foo', $yaml); }
/** * This method is called when the form of this step has been submitted * * @param array $formValues * @return void * @throws \Exception */ public function postProcessFormValues(array $formValues) { $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.driver', $formValues['driver']); $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.dbname', $formValues['dbname']); $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.user', $formValues['user']); $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.password', $formValues['password']); $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.host', $formValues['host']); $this->configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->distributionSettings); $this->configurationManager->flushConfigurationCache(); $settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow'); $connectionSettings = $settings['persistence']['backendOptions']; try { $this->connectToDatabase($connectionSettings); } catch (\Exception $exception) { if (!$exception instanceof DBALException && !$exception instanceof \PDOException) { throw $exception; } try { $this->createDatabase($connectionSettings, $formValues['dbname']); } catch (DBALException $exception) { throw new SetupException(sprintf('Database "%s" could not be created. Please check the permissions for user "%s". DBAL Exception: "%s"', $formValues['dbname'], $formValues['user'], $exception->getMessage()), 1351000841, $exception); } catch (\PDOException $exception) { throw new SetupException(sprintf('Database "%s" could not be created. Please check the permissions for user "%s". PDO Exception: "%s"', $formValues['dbname'], $formValues['user'], $exception->getMessage()), 1346758663, $exception); } try { $this->connectToDatabase($connectionSettings); } catch (DBALException $exception) { throw new SetupException(sprintf('Could not connect to database "%s". Please check the permissions for user "%s". DBAL Exception: "%s"', $formValues['dbname'], $formValues['user'], $exception->getMessage()), 1351000864); } catch (\PDOException $exception) { throw new SetupException(sprintf('Could not connect to database "%s". Please check the permissions for user "%s". PDO Exception: "%s"', $formValues['dbname'], $formValues['user'], $exception->getMessage()), 1346758737); } } $migrationExecuted = Scripts::executeCommand('neos.flow:doctrine:migrate', $settings, false); if ($migrationExecuted !== true) { throw new SetupException(sprintf('Could not execute database migrations. Please check the permissions for user "%s" and execute "./flow neos.flow:doctrine:migrate" manually.', $formValues['user']), 1346759486); } $this->resetPolicyRolesCacheAfterDatabaseChanges(); }
/** * Apply the given processor to the raw results of loading the given configuration * type for the package from YAML. If multiple files exist (context configuration) * all are processed independently. * * @param string $configurationType One of ConfigurationManager::CONFIGURATION_TYPE_* * @param \Closure $processor * @param boolean $saveResult * @return void */ protected function processConfiguration($configurationType, \Closure $processor, $saveResult = false) { if (is_dir($this->targetPackageData['path'] . '/Configuration') === false) { return; } $yamlPathsAndFilenames = Files::readDirectoryRecursively($this->targetPackageData['path'] . '/Configuration', 'yaml', true); $configurationPathsAndFilenames = array_filter($yamlPathsAndFilenames, function ($pathAndFileName) use($configurationType) { if (strpos(basename($pathAndFileName, '.yaml'), $configurationType) === 0) { return true; } else { return false; } }); $yamlSource = new YamlSource(); foreach ($configurationPathsAndFilenames as $pathAndFilename) { $originalConfiguration = $configuration = $yamlSource->load(substr($pathAndFilename, 0, -5)); $processor($configuration); if ($saveResult === true && $configuration !== $originalConfiguration) { $yamlSource->save(substr($pathAndFilename, 0, -5), $configuration); } } }
/** * {@inheritdoc} */ public function postProcessFormValues(array $formValues) { $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Imagine.driver', $formValues['imagineDriver']); $this->configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->distributionSettings); $this->configurationManager->flushConfigurationCache(); }
/** * Checks if the configured PHP binary is executable and the same version as the one * running the current (web server) PHP process. If not or if there is no binary configured, * tries to find the correct one on the PATH. * * Once found, the binary will be written to the configuration, if it is not the default one * (PHP_BINARY or in PHP_BINDIR). * * @return Message An error or warning message or NULL if PHP was detected successfully */ protected function checkAndSetPhpBinaryIfNeeded() { $configurationSource = new YamlSource(); $distributionSettings = $configurationSource->load(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS); if (isset($distributionSettings['TYPO3']['Flow']['core']['phpBinaryPathAndFilename'])) { return $this->checkPhpBinary($distributionSettings['TYPO3']['Flow']['core']['phpBinaryPathAndFilename']); } list($phpBinaryPathAndFilename, $message) = $this->detectPhpBinaryPathAndFilename(); if ($phpBinaryPathAndFilename !== null) { $defaultPhpBinaryPathAndFilename = PHP_BINDIR . '/php'; if (DIRECTORY_SEPARATOR !== '/') { $defaultPhpBinaryPathAndFilename = str_replace('\\', '/', $defaultPhpBinaryPathAndFilename) . '.exe'; } if ($phpBinaryPathAndFilename !== $defaultPhpBinaryPathAndFilename) { $distributionSettings = \Neos\Utility\Arrays::setValueByPath($distributionSettings, 'Neos.Flow.core.phpBinaryPathAndFilename', $phpBinaryPathAndFilename); $configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $distributionSettings); } } return $message; }