@param BaseCommand $command
@param Workflow $workflow

@return bool
554578
public function doApplyEnterPassword(BaseCommand $command, Workflow $workflow)
    {
        $subject = $command->storage;
        $password = $this->captureUserAndPassword($command->input)[0];

        if ($password && $workflow->can($subject, 'enter_password')) {
            if ($password === 'demo') {
                $workflow->apply($subject, 'enter_password');

                $command->storage->setLineLastLogin(new \DateTimeImmutable());
                $command->storage->setLineActiveCmd(null);
                $command->storage->setLineCommandData([]);
                $command->active = false;
                $command->message->text = 'Success!';
            } else {
                $command->message->text = 'Password not match, Try again ...';
            }

            return true;
        }

        return false;
    }
449686
protected function execute($command)
    {
        $process = proc_open($command, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
        fclose($pipes[2]);
        $this->output = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        $status = proc_get_status($process);
        $this->status = $status['exitcode'];
        proc_close($process);
    }
758828
static function getWorkflowState($workflow_key) {
        $status = self::STATUS_COMPLETED;
        $created_after = "-20 years";
        $data = DataStore::retrieveMostCurrentWorkflowJobByAgeAndStatus($workflow_key, $status, $created_after);
        if ($data) {
            return $data["end_state"];
        } else {
            $workflow = DataStore::retrieveWorkflow($workflow_key);
            if (!$workflow) {
                throw new \Exception("Error retrieving workflow for key $workflow_key can't determine state.");
            }
            $data = $workflow->getData();
            return $data[self::CONF_INITIAL_STATE];
        }
    }
270944
public function updateworkflow($data, Form $form, $request)
    {
        /** @var WorkflowService $service */
        $service = singleton(WorkflowService::class);
        /** @var DataObject $record */
        $record = $form->getRecord();
        $workflow = $service->getWorkflowFor($record);
        if (!$workflow) {
            return null;
        }

        $action = $workflow->CurrentAction();

        if (!$record || !$record->canEditWorkflow()) {
            return null;
        }

        $allowedFields = $workflow->getWorkflowFields()->saveableFields();
        unset($allowedFields['TransitionID']);

        $allowed = array_keys($allowedFields);
        if (count($allowed)) {
            $form->saveInto($action, $allowed);
            $action->write();
        }

        if (isset($data['TransitionID']) && $data['TransitionID']) {
            $service->executeTransition($record, $data['TransitionID']);
        } else {
            // otherwise, just try to execute the current workflow to see if it
            // can now proceed based on user input
            $workflow->execute();
        }

        return $this->returnResponse($form);
    }
340810
public function configureWorkflow($workflowName)
    {
        $this->workflowName = $workflowName;

        $this->workflow = $this->container->getParameter('free_agent_workflow.workflows.'.$this->workflowName, null);

        if (is_null($this->workflow)) {
            throw new WorkflowException('The workflow "'.$this->workflowName.'" does not exist');
        }

        $defaultStep = $this->workflow['default_step'];
        if (!array_key_exists($defaultStep, $this->workflow['steps'])) {
            throw new WorkflowException('The default step of "'.$this->workflowName.'" does not exist');
        }

        foreach ($this->workflow['steps'] as $stepName => $stepConfiguration) {
            $this->steps->offsetSet($stepName, new Step($stepName, $stepConfiguration));
        }

        $this->defaultStep = new Step($defaultStep, $this->workflow['steps'][$defaultStep]);
        $this->actions     = array_key_exists('actions', $this->workflow) ? $this->workflow['actions'] : array();
        $this->validations = array_key_exists('validations', $this->workflow) ? $this->workflow['validations'] : array();

        return $this->getSteps();
    }
1170650
protected function loadWorkflow(WorkflowConfig $c, $validate = true)
    {
        $validate = (boolean)$validate;
        try {
            $c->descriptor = WorkflowLoader::load($c->url, $validate);
        } catch (\Exception $e) {
            $errMsg = "Некорректный дескрипторв workflow: {$c->url}";
            throw new FactoryException($errMsg, $e->getCode(), $e);
        }
    }
1096171
static function runFromKey($workflow_key) {
        $workflow_job_config = [];
        $start_time = microtime(true);
        /**
         * First doing a simple setup... does this work?
         * Nothing get saved at this point errors here is most likely to be
         * a runtime problem. Like locking errorous jobs or that a job is already running.
         */
        try {
            $workflow_config = self::getWorkflowConfig($workflow_key);
            $workflow_job_key = self::createWorkflowJobKey();
            $workflow_job_config = self::createJobConfig($workflow_config);
            $start_state = self::getWorkflowState($workflow_key);
            $workflow_job_config = self::startJob($workflow_job_key, $workflow_job_config, $start_state);
        } catch (\Exception $exception) {
            syslog(LOG_ERR, $exception->getMessage());
            $workflow_job_config["status"] = self::STATUS_ERROR;
            $workflow_job_config["message"] = "Got this error: " . $exception->getMessage();
            $workflow_job_config["runtime"] = microtime(true) - $start_time;
            return $workflow_job_config;
        }
        /**
         * Continues with a working setup and trying to do the config run.
         */
        try {
            ob_start();
            $end_state = self::runFromConfig($workflow_config, $start_state);
            $workflow_job_config["message"] = ob_get_clean();
            $workflow_job_config["runtime"] = microtime(true) - $start_time;
            if ($end_state) {
                return self::endJob($workflow_job_key, $workflow_job_config, $end_state);
            } else {
                return self::failJob($workflow_job_key, $workflow_job_config, "Job didn't emit an endstate.");
            }
        } catch (\Exception $exception) {
            $workflow_job_config["runtime"] = microtime(true) - $start_time;
            return self::failJob($workflow_job_key, $workflow_job_config, $exception->getMessage());
        }
    }
609453
public static function validateCommand($command)
    {
        try {
            list($class, $method, $args) = self::parseCommand($command);
        } catch (TaskManagerException $e) {
            return false;
        }
        $args = array_map(function ($elem) {
            return trim($elem);
        }, $args);
        return $class . '::' . $method . '(' . trim(implode(',', $args), ',') . ')';
    }
91879
public static function hasCommand($command)
    {
        if (!is_string($command) || strlen($command) < 1) {
            throw new BadMethodCallException('Parameter command is not a valid string');
        }
        $instance = self::getInstance();

        return isset($instance->commands[$command]);
    }
632637
protected function triggerWorkflowEvent($eventName, $origin = null, $context = [])
    {
        $this->getEventsHandler()->trigger($eventName, $origin, $context, new WorkflowEvent($this));
    }
155197
public function setIsWorkflowInEffect()
    {
        // if there is a workflow applied, we can't set the publishing date directly, only the 'desired' publishing date
        $effective = $this->getWorkflowService()->getDefinitionFor($this->owner);
        $this->isWorkflowInEffect = $effective ? true : false;
    }
499281
public function registerTasks(Workflow $workflow, Deployment $deployment)
    {
        parent::registerTasks($workflow, $deployment);

        $this->checkIfMandatoryOptionsExist();
        $this->buildConfiguration();
        $this->defineTasks($workflow, $deployment);

        if ($this->getOption('enableTests') !== false) {
            $workflow
                ->addTask([
                    UnitTestTask::class,
                    FunctionalTestTask::class
                ], 'test', $this);
        }

        $workflow->addTask([
                'TYPO3\\Surf\\DefinedTask\\CreateZipDistributionTask',
                'TYPO3\\Surf\\DefinedTask\\CreateTarGzDistributionTask',
                'TYPO3\\Surf\\DefinedTask\\CreateTarBz2DistributionTask',
            ], 'cleanup', $this);

        if ($this->hasOption('enableSourceforgeUpload') && $this->getOption('enableSourceforgeUpload') === true) {
            $workflow->addTask(SourceforgeUploadTask::class, 'cleanup', $this);
        }
        if ($this->hasOption('releaseHost')) {
            $workflow->addTask(PrepareReleaseTask::class, 'initialize', $this);
            $workflow->addTask(ReleaseTask::class, 'cleanup', $this);
        }
        if ($this->hasOption('releaseHost') && $this->hasOption('enableSourceforgeUpload') && $this->getOption('enableSourceforgeUpload') === true) {
            $workflow->addTask(AddDownloadTask::class, 'cleanup', $this);
        }
        if ($this->hasOption('createTags') && $this->getOption('createTags') === true) {
            $workflow->addTask(TagTask::class, 'cleanup', $this);
            if ($this->hasOption('TYPO3\\Surf\\DefinedTask\\Git\\PushTagsTask') && $this->getOption('TYPO3\\Surf\\DefinedTask\\Git\\PushTagsTask') === true) {
                $workflow->afterTask(TagTask::class, 'TYPO3\\Surf\\DefinedTask\\Git\\PushTagsTask', $this);
            }
        }

        $workflow->removeTask(MigrateTask::class);
    }
770854
private function createWorkflow()
    {
        $workflowId = $this->workflowContext instanceof WorkflowContextInterface ? $this->workflowContext->getWorkflowId() : $this->workflowContext;
        $workflow = $this->workflowRepository->findById($workflowId);
        if ($workflow === null) {
            throw new WorkflowNotFoundException(sprintf('The workflow "%s" is not found.', $workflowId));
        }

        return $workflow;
    }
879855
public function validate()
    {
        $conditions = $this->getConditions();
        ValidationHelper::validate($conditions);

        $result = $this->getResult();
        if (null === $result) {
            $errMsg = 'Join должен иметь реузультат';
            throw new InvalidWorkflowDescriptorException($errMsg);
        }

        $result->validate();
    }
723578
private static function areCommands(array $commands): bool
    {
        $areCommands = true;

        foreach ($commands as $command) {
            $areCommands = $areCommands && ($command instanceof BaseCommand);
        }

        return $areCommands;
    }
41300
public function add(BaseCommand $command)
    {
        if ($ret = parent::add($command)) {
            if ($ret instanceof ContextAware) {
                $ret->setContext($this->context);
            }

            if ($ret instanceof PresenterAware) {
                $ret->setPresenter($this->config->getPresenter());
            }

            if (isset($this->commandsMatcher)) {
                $this->commandsMatcher->setCommands($this->all());
            }
        }

        return $ret;
    }
581439
public function doApplyEnterUsername(BaseCommand $command, Workflow $workflow)
    {
        $subject = $command->storage;
        $username = $this->captureUserAndPassword($command->input)[0];

        if ($username && $workflow->can($subject, 'enter_username')) {
            if ($username === 'demo') {
                $workflow->apply($subject, 'enter_username');

                $command->message->text = 'Please Enter password!';
            } else {
                $command->message->text = 'Not found username, Try again ...';
            }

            return true;
        }

        return false;
    }