/** * @test */ public function subProcessCommandEvaluatesSubRequestIniEntriesCorrectly() { $settings = ['core' => ['context' => 'Testing', 'phpBinaryPathAndFilename' => '/must/be/set/according/to/schema', 'subRequestIniEntries' => ['someSetting' => 'withValue', 'someFlagSettingWithoutValue' => '']]]; $actual = $this->scriptsMock->_call('buildSubprocessCommand', 'flow:foo:identifier', $settings); $this->assertContains(sprintf(' -d %s=%s ', escapeshellarg('someSetting'), escapeshellarg('withValue')), $actual); $this->assertContains(sprintf(' -d %s ', escapeshellarg('someFlagSettingWithoutValue')), $actual); }
/** * Run a standalone development server * * Starts an embedded server, see http://php.net/manual/en/features.commandline.webserver.php * Note: This requires PHP 5.4+ * * To change the context Flow will run in, you can set the <b>FLOW_CONTEXT</b> environment variable: * <i>export FLOW_CONTEXT=Development && ./flow server:run</i> * * @param string $host The host name or IP address for the server to listen on * @param integer $port The server port to listen on * @return void */ public function runCommand($host = '127.0.0.1', $port = 8081) { $command = Scripts::buildPhpCommand($this->settings); $address = sprintf('%s:%s', $host, $port); $command .= ' -S ' . escapeshellarg($address) . ' -t ' . escapeshellarg(FLOW_PATH_WEB) . ' ' . escapeshellarg(FLOW_PATH_FLOW . '/Scripts/PhpDevelopmentServerRouter.php'); $this->outputLine('Server running. Please go to <b>http://' . $address . '</b> to browse the application.'); exec($command); }
/** * @inheritdoc */ public function submit($payload, array $options = []) { $messageId = Algorithms::generateUUID(); $message = new Message($messageId, $payload); $commandArguments = [$this->name, base64_encode(serialize($message))]; if ($this->async) { if (!method_exists(Scripts::class, 'executeCommandAsync')) { throw new \RuntimeException('The "async" flag is set, but the currently used Flow version doesn\'t support this (Flow 3.3+ is required)', 1469116604); } Scripts::executeCommandAsync('flowpack.jobqueue.common:job:execute', $this->flowSettings, $commandArguments); } else { Scripts::executeCommand('flowpack.jobqueue.common:job:execute', $this->flowSettings, true, $commandArguments); } return $messageId; }
/** * Refreeze a package * * Refreezes a currently frozen package: all precompiled information is removed * and file monitoring will consider the package exactly once, on the next * request. After that request, the package remains frozen again, just with the * updated data. * * By specifying <b>all</b> as a package key, all currently frozen packages are * refrozen (the default). * * @param string $packageKey Key of the package to refreeze, or 'all' * @return void * @see neos.flow:package:freeze * @see neos.flow:cache:flush */ public function refreezeCommand($packageKey = 'all') { if (!$this->bootstrap->getContext()->isDevelopment()) { $this->outputLine('Package freezing is only supported in Development context.'); $this->quit(3); } $packagesToRefreeze = []; if ($packageKey === 'all') { foreach (array_keys($this->packageManager->getAvailablePackages()) as $packageKey) { if ($this->packageManager->isPackageFrozen($packageKey)) { $packagesToRefreeze[] = $packageKey; } } if ($packagesToRefreeze === []) { $this->outputLine('Nothing to do, no packages were frozen.'); $this->quit(0); } } else { if ($packageKey === null) { $this->outputLine('You must specify a package to refreeze.'); $this->quit(1); } if (!$this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" is not available.', [$packageKey]); $this->quit(2); } if (!$this->packageManager->isPackageFrozen($packageKey)) { $this->outputLine('Package "%s" was not frozen.', [$packageKey]); $this->quit(0); } $packagesToRefreeze = [$packageKey]; } foreach ($packagesToRefreeze as $packageKey) { $this->packageManager->refreezePackage($packageKey); $this->outputLine('Refroze package "%s".', [$packageKey]); } Scripts::executeCommand('neos.flow:cache:flush', $this->settings, false); $this->sendAndExit(0); }
/** * Wait for a job in the given queue and execute it * A worker using this method should catch exceptions * * @param string $queueName * @param integer $timeout * @return Message The message that was processed or NULL if no job was executed and a timeout occurred * @throws \Exception * @api */ public function waitAndExecute($queueName, $timeout = null) { $queue = $this->queueManager->getQueue($queueName); $message = $queue->waitAndReserve($timeout); if ($message === null) { $this->emitMessageTimeout($queue); // timeout return null; } $this->emitMessageReserved($queue, $message); $queueSettings = $this->queueManager->getQueueSettings($queueName); try { if (isset($queueSettings['executeIsolated']) && $queueSettings['executeIsolated'] === true) { Scripts::executeCommand('flowpack.jobqueue.common:job:execute', $this->flowSettings, false, [$queue->getName(), base64_encode(serialize($message))]); } else { $this->executeJobForMessage($queue, $message); } } catch (\Exception $exception) { $maximumNumberOfReleases = isset($queueSettings['maximumNumberOfReleases']) ? (int) $queueSettings['maximumNumberOfReleases'] : 0; if ($message->getNumberOfReleases() < $maximumNumberOfReleases) { $releaseOptions = isset($queueSettings['releaseOptions']) ? $queueSettings['releaseOptions'] : []; $queue->release($message->getIdentifier(), $releaseOptions); $this->emitMessageReleased($queue, $message, $releaseOptions, $exception); throw new JobQueueException(sprintf('Job execution for job (message: "%s", queue: "%s") failed (%d/%d trials) - RELEASE', $message->getIdentifier(), $queue->getName(), $message->getNumberOfReleases() + 1, $maximumNumberOfReleases + 1), 1334056583, $exception); } else { $queue->abort($message->getIdentifier()); $this->emitMessageFailed($queue, $message, $exception); throw new JobQueueException(sprintf('Job execution for job (message: "%s", queue: "%s") failed (%d/%d trials) - ABORTING', $message->getIdentifier(), $queue->getName(), $message->getNumberOfReleases() + 1, $maximumNumberOfReleases + 1), 1334056584, $exception); } } $queue->finish($message->getIdentifier()); $this->emitMessageFinished($queue, $message); return $message; }
/** * 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(); }
/** * Bootstraps the minimal infrastructure, resolves a fitting request handler and * then passes control over to that request handler. * * @return void * @api */ public function run() { Scripts::initializeClassLoader($this); Scripts::initializeSignalSlot($this); Scripts::initializePackageManagement($this); $this->activeRequestHandler = $this->resolveRequestHandler(); $this->activeRequestHandler->handleRequest(); }