コード例 #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $application = $this->getApplication();
     $manifest = $input->getOption('manifest') ?: 'http://drupalconsole.com/manifest.json';
     $currentVersion = $input->getOption('current-version') ?: $application->getVersion();
     $major = $input->getOption('major');
     if (!extension_loaded('Phar') || !\Phar::running(false)) {
         $io->error($this->trans('commands.self-update.messages.not-phar'));
         $io->block($this->trans('commands.self-update.messages.instructions'));
         return 1;
     }
     $io->info(sprintf($this->trans('commands.self-update.messages.check'), $currentVersion));
     $updater = new Updater(null, false);
     $strategy = new ManifestStrategy($currentVersion, $major, $manifest);
     $updater->setStrategyObject($strategy);
     if (!$updater->hasUpdate()) {
         $io->info(sprintf($this->trans('commands.self-update.messages.current-version'), $currentVersion));
         return 0;
     }
     $oldVersion = $updater->getOldVersion();
     $newVersion = $updater->getNewVersion();
     if (!$io->confirm(sprintf($this->trans('commands.self-update.questions.update'), $oldVersion, $newVersion), true)) {
         return 1;
     }
     $io->comment(sprintf($this->trans('commands.self-update.messages.update'), $newVersion));
     $updater->update();
     $io->success(sprintf($this->trans('commands.self-update.messages.success'), $oldVersion, $newVersion));
     // Errors appear if new classes are instantiated after this stage
     // (namely, Symfony's ConsoleTerminateEvent). This suggests PHP
     // can't read files properly from the overwritten Phar, or perhaps it's
     // because the autoloader's name has changed. We avoid the problem by
     // terminating now.
     exit;
 }
コード例 #2
0
ファイル: DebugCommand.php プロジェクト: jeyram/DrupalConsole
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $group = $input->getArgument('group');
     if ($group) {
         $breakPointData = $this->getBreakpointByName($group);
         foreach ($breakPointData as $key => $breakPoint) {
             $io->comment($key, false);
             $io->block(Yaml::dump($breakPoint));
         }
         return 0;
     }
     $groups = array_keys($this->breakpointManager->getGroups());
     $tableHeader = [$this->trans('commands.breakpoints.debug.messages.name')];
     $io->table($tableHeader, $groups, 'compact');
     return 0;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $interactive = false;
     $learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
     $file = $input->getOption('file');
     if (!$file) {
         $io->error($this->trans('commands.chain.messages.missing_file'));
         return 1;
     }
     $fileSystem = new Filesystem();
     $file = calculateRealPath($file);
     if (!$fileSystem->exists($file)) {
         $io->error(sprintf($this->trans('commands.chain.messages.invalid_file'), $file));
         return 1;
     }
     $placeholder = $input->getOption('placeholder');
     if ($placeholder) {
         $placeholder = $this->inlineValueAsArray($placeholder);
     }
     $chainContent = $this->getFileContents($file);
     $environmentPlaceHolders = $this->extractEnvironmentPlaceHolders($chainContent);
     $envPlaceHolderMap = [];
     $missingEnvironmentPlaceHolders = [];
     foreach ($environmentPlaceHolders as $envPlaceHolder) {
         if (!getenv($envPlaceHolder)) {
             $missingEnvironmentPlaceHolders[$envPlaceHolder] = sprintf('export %s=%s_VALUE', $envPlaceHolder, strtoupper($envPlaceHolder));
             continue;
         }
         $envPlaceHolderMap[$envPlaceHolder] = getenv($envPlaceHolder);
     }
     if ($missingEnvironmentPlaceHolders) {
         $io->error(sprintf($this->trans('commands.chain.messages.missing-environment-placeholders'), implode(', ', array_keys($missingEnvironmentPlaceHolders))));
         $io->info($this->trans('commands.chain.messages.set-environment-placeholders'));
         $io->block(array_values($missingEnvironmentPlaceHolders));
         return 1;
     }
     $envPlaceHolderData = new ArrayDataSource($envPlaceHolderMap);
     $placeholderResolver = new RegexPlaceholderResolver($envPlaceHolderData, '${{', '}}');
     $chainContent = $placeholderResolver->resolvePlaceholder($chainContent);
     $inlinePlaceHolders = $this->extractInlinePlaceHolders($chainContent);
     $inlinePlaceHoldersReplacements = [];
     foreach ($inlinePlaceHolders as $key => $inlinePlaceHolder) {
         if (strpos($inlinePlaceHolder, '|') > 0) {
             $placeholderParts = explode('|', $inlinePlaceHolder);
             $inlinePlaceHoldersReplacements[] = $placeholderParts[0];
             continue;
         }
         $inlinePlaceHoldersReplacements[] = $inlinePlaceHolder;
     }
     $chainContent = str_replace($inlinePlaceHolders, $inlinePlaceHoldersReplacements, $chainContent);
     $inlinePlaceHolders = $inlinePlaceHoldersReplacements;
     $inlinePlaceHolderMap = [];
     foreach ($placeholder as $key => $placeholderItem) {
         $inlinePlaceHolderMap = array_merge($inlinePlaceHolderMap, $placeholderItem);
     }
     $missingInlinePlaceHolders = [];
     foreach ($inlinePlaceHolders as $inlinePlaceHolder) {
         if (!array_key_exists($inlinePlaceHolder, $inlinePlaceHolderMap)) {
             $missingInlinePlaceHolders[$inlinePlaceHolder] = sprintf('--placeholder="%s:%s_VALUE"', $inlinePlaceHolder, strtoupper($inlinePlaceHolder));
         }
     }
     if ($missingInlinePlaceHolders) {
         $io->error(sprintf($this->trans('commands.chain.messages.missing-inline-placeholders'), implode(', ', array_keys($missingInlinePlaceHolders))));
         $io->info($this->trans('commands.chain.messages.set-inline-placeholders'));
         $io->block(array_values($missingInlinePlaceHolders));
         return 1;
     }
     $inlinePlaceHolderData = new ArrayDataSource($inlinePlaceHolderMap);
     $placeholderResolver = new RegexPlaceholderResolver($inlinePlaceHolderData, '%{{', '}}');
     $chainContent = $placeholderResolver->resolvePlaceholder($chainContent);
     $parser = new Parser();
     $configData = $parser->parse($chainContent);
     $commands = [];
     if (array_key_exists('commands', $configData)) {
         $commands = $configData['commands'];
     }
     foreach ($commands as $command) {
         $moduleInputs = [];
         $arguments = !empty($command['arguments']) ? $command['arguments'] : [];
         $options = !empty($command['options']) ? $command['options'] : [];
         foreach ($arguments as $key => $value) {
             $moduleInputs[$key] = is_null($value) ? '' : $value;
         }
         foreach ($options as $key => $value) {
             $moduleInputs['--' . $key] = is_null($value) ? '' : $value;
         }
         $parameterOptions = $input->getOptions();
         unset($parameterOptions['file']);
         foreach ($parameterOptions as $key => $value) {
             if ($value === true) {
                 $moduleInputs['--' . $key] = true;
             }
         }
         $this->chainQueue->addCommand($command['command'], $moduleInputs, $interactive, $learning);
     }
     return 0;
 }