Executes the given command as a sub-request to the Flow CLI system.
public static executeCommand ( string $commandIdentifier, array $settings, boolean $outputResults = true, array $commandArguments = [] ) : boolean | ||
$commandIdentifier | string | E.g. neos.flow:cache:flush |
$settings | array | The Neos.Flow settings |
$outputResults | boolean | if FALSE the output of this command is only echoed if the execution was not successful |
$commandArguments | array | Command arguments |
Результат | boolean | TRUE if the command execution was successful (exit code = 0) |
/** * @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(); }