protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $resource_id = $input->getArgument('resource-id'); $rest_resources = $this->getRestResources(); $rest_resources_ids = array_merge(array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled'])); if (!$resource_id) { $resource_id = $io->choiceNoList($this->trans('commands.rest.enable.arguments.resource-id'), $rest_resources_ids); } $this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator()); $input->setArgument('resource-id', $resource_id); // Calculate states available by resource and generate the question $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]); $states = $plugin->availableMethods(); $state = $io->choice($this->trans('commands.rest.enable.arguments.states'), $states); $io->writeln($this->trans('commands.rest.enable.messages.selected-state') . ' ' . $state); // Get Authentication Provider and generate the question $authenticationProviders = $this->authenticationCollector->getSortedProviders(); $authenticationProvidersSelected = $io->choice($this->trans('commands.rest.enable.messages.authentication-providers'), array_keys($authenticationProviders), 0, true); $io->writeln($this->trans('commands.rest.enable.messages.selected-authentication-providers') . ' ' . implode(', ', $authenticationProvidersSelected)); $rest_settings = $this->getRestDrupalConfig(); $rest_settings[$resource_id][$state]['supported_formats'] = $formats; $rest_settings[$resource_id][$state]['supported_auth'] = $authenticationProvidersSelected; $config = $this->configFactory->getEditable('rest.settings'); $config->set('resources', $rest_settings); $config->save(); return 0; }
protected function themeDetail(DrupalStyle $io, $themeId) { $theme = null; $themes = $this->getThemeHandler()->rebuildThemeData(); if (isset($themes[$themeId])) { $theme = $themes[$themeId]; } else { foreach ($themes as $themeAvailableId => $themeAvailable) { if ($themeAvailable->info['name'] == $themeId) { $themeId = $themeAvailableId; $theme = $themeAvailable; break; } } } if ($theme) { $theme = $themes[$themeId]; $status = $this->getThemeStatus($themeId); $io->info($theme->info['name']); $io->comment(sprintf('%s : ', $this->trans('commands.theme.debug.messages.status')), false); $io->writeln($status); $io->comment(sprintf('%s : ', $this->trans('commands.theme.debug.messages.version')), false); $io->writeln($theme->info['version']); $io->comment($this->trans('commands.theme.debug.messages.regions')); $tableRows = $this->addThemeAttributes($theme->info['regions'], $tableRows); $io->table([], $tableRows); } else { $io->error(sprintf($this->trans('commands.theme.debug.messages.invalid-theme'), $themeId)); } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $resource_id = $input->getArgument('resource-id'); $rest_resources = $this->getRestResources(); $rest_resources_ids = array_merge(array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled'])); if (!$resource_id) { $resource_id = $io->choiceNoList($this->trans('commands.rest.enable.arguments.resource-id'), $rest_resources_ids); } $this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator()); $input->setArgument('resource-id', $resource_id); // Calculate states available by resource and generate the question $resourcePluginManager = $this->getPluginManagerRest(); $plugin = $resourcePluginManager->getInstance(array('id' => $resource_id)); $states = $plugin->availableMethods(); $state = $io->choice($this->trans('commands.rest.enable.arguments.states'), $states); $io->writeln($this->trans('commands.rest.enable.messages.selected-state') . ' ' . $state); // Get serializer formats available and generate the question. $serializedFormats = $this->getSerializerFormats(); $formats = $io->choice($this->trans('commands.rest.enable.messages.formats'), $serializedFormats, 0, true); $io->writeln($this->trans('commands.rest.enable.messages.selected-formats') . ' ' . implode(', ', $formats)); // Get Authentication Provider and generate the question $authenticationProviders = $this->getAuthenticationProviders(); $authenticationProvidersSelected = $io->choice($this->trans('commands.rest.enable.messages.authentication-providers'), array_keys($authenticationProviders), 0, true); $io->writeln($this->trans('commands.rest.enable.messages.selected-authentication-providers') . ' ' . implode(', ', $authenticationProvidersSelected)); $rest_settings = $this->getRestDrupalConfig(); $rest_settings[$resource_id][$state]['supported_formats'] = $formats; $rest_settings[$resource_id][$state]['supported_auth'] = $authenticationProvidersSelected; $config = $this->getConfigFactory()->getEditable('rest.settings'); $config->set('resources', $rest_settings); $config->save(); // Run cache rebuild to enable rest routing $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $key = $input->getArgument('key'); if ($key) { $state = $this->getState(); $io->writeln(sprintf('<info>%s:</info>', $key)); $io->writeln(Yaml::encode($state->get($key))); return; } $this->showAllStateKeys($io); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $theme = $input->getArgument('theme'); if (!$theme) { $theme_list = []; $themes = $this->getThemeHandler()->rebuildThemeData(); foreach ($themes as $theme_id => $theme) { if (!empty($theme->info['hidden'])) { continue; } if (!empty($theme->status == 0)) { continue; } $theme_list[$theme_id] = $theme->getName(); } $output->writeln('[+] <info>' . $this->trans('commands.theme.uninstall.messages.installed-themes') . '</info>'); while (true) { $theme_name = $output->choiceNoList($this->trans('commands.theme.uninstall.questions.theme'), array_keys($theme_list)); if (empty($theme_name)) { break; } $theme_list_install[] = $theme_name; if (array_search($theme_name, $theme_list_install, true) >= 0) { unset($theme_list[$theme_name]); } } $input->setArgument('theme', $theme_list_install); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $module = $input->getArgument('module'); if (!$module) { $moduleList = []; $modules = system_rebuild_module_data(); foreach ($modules as $moduleId => $module) { if ($module->status == 1) { continue; } $moduleList[$moduleId] = $module->info['name']; } $output->writeln($this->trans('commands.module.install.messages.disabled-modules')); while (true) { $moduleName = $output->choiceNoList($this->trans('commands.module.install.questions.module'), array_keys($moduleList), null, true); if (empty($moduleName)) { break; } $moduleListInstall[] = $moduleName; if (array_search($moduleName, $moduleListInstall, true) >= 0) { unset($moduleList[$moduleName]); } } $input->setArgument('module', $moduleListInstall); } $overwrite_config = $input->getOption('overwrite-config'); $input->setOption('overwrite-config', $overwrite_config); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $application = $this->getApplication(); $drupal = $this->getDrupalHelper(); // Provide drupal version if it's installed $drupalVersion = $this->trans('commands.site.status.messages.not_installed'); if ($drupal->isInstalled()) { $drupalVersion = sprintf($this->trans('commands.site.status.messages.current_version'), $this->getSite()->getDrupalVersion()); } $aboutTitle = sprintf('%s (%s) | Supports Drupal (%s) | %s', $this->trans('commands.site.status.messages.console'), $application->getVersion(), $application::DRUPAL_SUPPORTED_VERSION, $drupalVersion); $io->setDecorated(false); $io->title($aboutTitle); $io->setDecorated(true); $commands = ['init' => [$this->trans('commands.init.description'), 'drupal init --override'], 'quick-start' => [$this->trans('commands.common.messages.quick-start'), 'drupal chain --file=~/.console/chain/quick-start.yml'], 'site-new' => [$this->trans('commands.site.new.description'), sprintf('drupal site:new drupal8.dev %s', $application::DRUPAL_SUPPORTED_VERSION)], 'site-install' => [$this->trans('commands.site.install.description'), sprintf('drupal site:install')], 'links' => [$this->trans('commands.list.description'), 'drupal list']]; foreach ($commands as $command => $commandInfo) { $io->writeln($commandInfo[0]); $io->newLine(); $io->comment(sprintf(' %s', $commandInfo[1])); $io->newLine(); } $io->setDecorated(false); $io->section($this->trans('commands.self-update.description')); $io->setDecorated(true); $io->comment(' drupal self-update'); $io->newLine(); }
protected function execute(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $this->getDrupalHelper()->loadLegacyFile('/core/includes/utility.inc'); $validators = $this->getValidator(); // Get the --cache option and make validation $cache = $input->getArgument('cache'); $validated_cache = $validators->validateCache($cache); if (!$validated_cache) { $output->error(sprintf($this->trans('commands.cache.rebuild.messages.invalid_cache'), $cache)); return; } // Start rebuilding cache $output->newLine(); $output->writeln(sprintf('<comment>%s</comment>', $this->trans('commands.cache.rebuild.messages.rebuild'))); // Get data needed to rebuild cache $kernelHelper = $this->getKernelHelper(); $classLoader = $kernelHelper->getClassLoader(); $request = $kernelHelper->getRequest(); // Check cache to rebuild if ($cache === 'all') { // If cache is all, then clear all caches drupal_rebuild($classLoader, $request); } else { // Else, clear the selected cache $caches = $validators->getCaches(); $caches[$cache]->deleteAll(); } $output->success($this->trans('commands.cache.rebuild.messages.completed')); }
protected function execute(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $output->newLine(); $output->writeln(sprintf('<comment>%s</comment>', $this->trans('commands.router.rebuild.messages.rebuilding'))); $container = $this->getContainer(); $router_builder = $container->get('router.builder'); $router_builder->rebuild(); $output->success($this->trans('commands.router.rebuild.messages.completed')); }
/** * @param string $target */ private function siteDetail(DrupalStyle $io, $target) { $application = $this->getApplication(); if ($application->getConfig()->loadTarget($target)) { $targetConfig = $application->getConfig()->getTarget($target); $dumper = new Dumper(); $yaml = $dumper->dump($targetConfig, 5); $io->writeln($yaml); return; } }
protected function execute(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $application = $this->getApplication(); $aboutTitle = sprintf('%s (%s) | Supports Drupal %s', $this->trans('commands.site.status.messages.console'), $application->getVersion(), $application::DRUPAL_VERSION); $output->setDecorated(false); $output->title($aboutTitle); $output->setDecorated(true); $commands = ['init' => [$this->trans('commands.init.description'), 'drupal init [--override]'], 'quick-start' => [$this->trans('commands.common.messages.quick-start'), 'drupal chain --file=~/.console/chain/quick-start.yml'], 'site-new' => [$this->trans('commands.site.new.description'), sprintf('drupal site:new drupal8.dev %s', $application::DRUPAL_VERSION)], 'site-install' => [$this->trans('commands.site.install.description'), sprintf('drupal site:install')], 'links' => [$this->trans('commands.list.description'), 'drupal list']]; foreach ($commands as $command => $commandInfo) { $output->writeln($commandInfo[0]); $output->newLine(); $output->writeln(sprintf(' <comment>%s</comment>', $commandInfo[1])); $output->newLine(); } $output->setDecorated(false); $output->section($this->trans('commands.self-update.description')); $output->setDecorated(true); $output->writeln(' <comment>drupal self-update</comment>'); $output->newLine(); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $directory = sprintf('%s/templates/core/druplicon/', $this->appRoot . DRUPAL_CONSOLE); $finder = new Finder(); $finder->files()->name('*.twig')->in($directory); $templates = []; foreach ($finder as $template) { $templates[] = $template->getRelativePathname(); } $druplicon = $this->renderer->render(sprintf('core/druplicon/%s', $templates[array_rand($templates)])); $io->writeln($druplicon); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $renderer = $this->getRenderHelper(); $directory = sprintf('%stemplates/core/elephpant/', $this->getApplication()->getDirectoryRoot()); $finder = new Finder(); $finder->files()->name('*.twig')->in($directory); $templates = []; foreach ($finder as $template) { $templates[] = $template->getRelativePathname(); } $elephpant = $renderer->render(sprintf('core/elephpant/%s', $templates[array_rand($templates)])); $io->writeln($elephpant); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $key = $input->getArgument('key'); if ($key) { $io->info($key); $io->writeln(Yaml::encode($this->state->get($key))); return 0; } $tableHeader = [$this->trans('commands.state.debug.messages.key')]; $keyStoreStates = array_keys($this->keyValue->get('state')->getAll()); $io->table($tableHeader, $keyStoreStates); return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $directory = $input->getOption('directory'); $tar = $input->getOption('tar'); $archiveTar = new ArchiveTar(); if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } if ($tar) { if (!is_dir($directory)) { mkdir($directory, 0777, true); } $dateTime = new \DateTime(); $archiveFile = sprintf('%s/config-%s.tar.gz', $directory, $dateTime->format('Y-m-d-H-i-s')); $archiveTar = new ArchiveTar($archiveFile, 'gz'); } try { $configManager = $this->getConfigManager(); // Get raw configuration data without overrides. foreach ($configManager->getConfigFactory()->listAll() as $name) { $configData = $configManager->getConfigFactory()->get($name)->getRawData(); $configName = sprintf('%s.yml', $name); $ymlData = Yaml::encode($configData); if ($tar) { $archiveTar->addString($configName, $ymlData); continue; } $configFileName = sprintf('%s/%s', $directory, $configName); file_put_contents($configFileName, $ymlData); } } catch (\Exception $e) { $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); } $output->success($this->trans('commands.config.export.messages.directory')); $output->writeln($directory); }
/** * @param DrupalStyle $io * @param array $files * @param string $headerKey * @param string $pathKey * @param string $path */ private function showFiles($io, $files, $headerKey, $pathKey, $path) { if (!$files) { return; } $io->writeln($this->translator->trans($headerKey)); $io->info(sprintf('%s:', $this->translator->trans($pathKey)), false); $io->comment($path, false); $io->newLine(); $index = 1; foreach ($files as $file) { $this->showFile($io, $file, $index); ++$index; } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $group = $input->getArgument('group'); if (!$group) { $groups = $this->getAllLibraries(); $tableHeader = [$this->trans('commands.libraries.debug.messages.name')]; $io->table($tableHeader, $groups, 'compact'); } else { $librariesData = $this->libraryDiscovery->getLibrariesByExtension($group); foreach ($librariesData as $key => $libraries) { $io->comment($key); $io->writeln(Yaml::encode($libraries)); } } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $group = $input->getArgument('group'); if (!$group) { $groups = $this->getAllBreakpoints(); $tableHeader = [$this->trans('commands.breakpoints.debug.messages.name')]; $io->table($tableHeader, $groups, 'compact'); } else { $breakPointData = $this->getBreakpointByName($group); foreach ($breakPointData as $key => $breakPoint) { $io->comment($key); $io->writeln(Yaml::encode($breakPoint)); } } }
/** * @param $io * @param $eventId * @return bool */ private function getEventDetails(DrupalStyle $io, $eventId) { $connection = $this->getDrupalService('database'); $dateFormatter = $this->getDrupalService('date.formatter'); $userStorage = $this->getDrupalService('entity_type.manager')->getStorage('user'); $severity = RfcLogLevel::getLevels(); $dblog = $connection->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', array(':id' => $eventId))->fetchObject(); if (!$dblog) { $io->error(sprintf($this->trans('commands.database.log.debug.messages.not-found'), $eventId)); return false; } $user = $userStorage->load($dblog->uid); $configuration = [$this->trans('commands.database.log.debug.messages.event-id') => $eventId, $this->trans('commands.database.log.debug.messages.type') => $dblog->type, $this->trans('commands.database.log.debug.messages.date') => $dateFormatter->format($dblog->timestamp, 'short'), $this->trans('commands.database.log.debug.messages.user') => $user->getUsername() . ' (' . $user->id() . ')', $this->trans('commands.database.log.debug.messages.severity') => (string) $severity[$dblog->severity], $this->trans('commands.database.log.debug.messages.message') => Html::decodeEntities(strip_tags($this->formatMessage($dblog)))]; $io->writeln(Yaml::encode($configuration)); return true; }
/** * @param DrupalStyle $output * * @return mixed */ public function eventsQuestion(DrupalStyle $output) { $eventCollection = []; $output->writeln($this->trans('commands.common.questions.events.message')); $events = $this->getEvents(); while (true) { $event = $output->choiceNoList($this->trans('commands.common.questions.events.name'), $events); if (empty($event)) { break; } $callbackSuggestion = str_replace('.', '_', $event); $callback = $output->ask($this->trans('commands.generate.event.subscriber.questions.callback-name'), $callbackSuggestion); $eventCollection[$event] = $callback; $eventKey = array_search($event, $events, true); if ($eventKey >= 0) { unset($events[$eventKey]); } } return $eventCollection; }
/** * @param DrupalStyle $io * * @return mixed */ public function servicesQuestion(DrupalStyle $io) { if ($io->confirm($this->trans('commands.common.questions.services.confirm'), false)) { $service_collection = []; $io->writeln($this->trans('commands.common.questions.services.message')); $services = $this->getServices(); while (true) { $service = $io->choiceNoList($this->trans('commands.common.questions.services.name'), $services, null, true); $service = trim($service); if (empty($service)) { break; } array_push($service_collection, $service); $service_key = array_search($service, $services, true); if ($service_key >= 0) { unset($services[$service_key]); } } return $service_collection; } }
protected function testList(DrupalStyle $io, $group) { $testingGroups = $this->getTestDiscovery()->getTestClasses(null); if (empty($group)) { $tableHeader = [$this->trans('commands.test.debug.messages.group')]; } else { $tableHeader = [$this->trans('commands.test.debug.messages.class'), $this->trans('commands.test.debug.messages.type')]; $io->writeln(sprintf('%s: %s', $this->trans('commands.test.debug.messages.group'), $group)); } $tableRows = []; foreach ($testingGroups as $testing_group => $tests) { if (empty($group)) { $tableRows[] = [$testing_group]; continue; } if (!empty($group) && $group != $testing_group) { continue; } foreach ($tests as $test) { if (is_subclass_of($test['name'], 'PHPUnit_Framework_TestCase')) { $test['type'] = 'phpunit'; } else { $test['type'] = 'simpletest'; } $tableRows[] = [$test['name'], $test['type']]; } } $io->table($tableHeader, $tableRows, 'compact'); if ($group) { $io->success(sprintf($this->trans('commands.test.debug.messages.success-group'), $group)); } else { $io->success($this->trans('commands.test.debug.messages.success-groups')); } }
protected function execute(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $httpClient = $this->getHttpClientHelper(); $site_name = $input->getArgument('site-name'); $version = $input->getArgument('version'); if ($version) { $release_selected = $version; } else { // Getting Module page header and parse to get module Node $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.getting-releases')) . '</info>'); // Page for Drupal releases filter by Drupal 8 $project_release_d8 = 'https://www.drupal.org/node/3060/release?api_version%5B%5D=7234'; // Parse release module page to get Drupal 8 releases try { $html = $httpClient->getHtml($project_release_d8); } catch (\Exception $e) { $output->writeln('[+] <error>' . $e->getMessage() . '</error>'); return; } $crawler = new Crawler($html); $releases = []; foreach ($crawler->filter('span.file a') as $element) { if (strpos($element->nodeValue, ".tar.gz") > 0) { $release_name = str_replace('.tar.gz', '', str_replace('drupal-', '', $element->nodeValue)); $releases[$release_name] = $element->nodeValue; } } if (empty($releases)) { $output->writeln('[+] <error>' . $this->trans('commands.module.site.new.no-releases') . '</error>'); return; } // List module releases to enable user to select his favorite release $questionHelper = $this->getQuestionHelper(); $question = new ChoiceQuestion('Please select your favorite release', array_combine(array_keys($releases), array_keys($releases)), 0); $release_selected = $questionHelper->ask($input, $output, $question); } $release_file_path = 'http://ftp.drupal.org/files/projects/drupal-' . $release_selected . '.tar.gz'; // Destination file to download the release $destination = tempnam(sys_get_temp_dir(), 'drupal.') . "tar.gz"; try { // Start the process to download the zip file of release and copy in contrib folter $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.downloading'), $release_selected) . '</info>'); $httpClient->downloadFile($release_file_path, $destination); $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.extracting'), $release_selected) . '</info>'); $zippy = Zippy::load(); $archive = $zippy->open($destination); $archive->extract('./'); try { $fs = new Filesystem(); $fs->rename('./drupal-' . $release_selected, './' . $site_name); } catch (IOExceptionInterface $e) { $output->writeln('[+] <error>' . sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath()) . '</error>'); } $output->success(sprintf($this->trans('commands.site.new.messages.downloaded'), $release_selected, $site_name)); } catch (\Exception $e) { $output->writeln('[+] <error>' . $e->getMessage() . '</error>'); return; } return true; }
/** * {@inheritdoc} */ public function doRun(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $requirementChecker = $this->getContainerHelper()->get('requirement_checker'); $checks = $requirementChecker->validate(); $root = null; $config = $this->getConfig(); $target = $input->getParameterOption(['--target'], null); $commandName = null; if ($input) { $commandName = $this->getCommandName($input); $this->commandName = $commandName; } $targetConfig = []; if ($target && $config->loadTarget($target)) { $targetConfig = $config->getTarget($target); $root = $targetConfig['root']; } if ($targetConfig && $targetConfig['remote']) { $remoteResult = $this->getRemoteHelper()->executeCommand($commandName, $target, $targetConfig, $input->__toString(), $config->getUserHomeDir()); $output->writeln($remoteResult); return 0; } if (!$target) { $root = $input->getParameterOption(['--root'], null); $root = strpos($root, '/') === 0 ? $root : sprintf('%s/%s', getcwd(), $root); } $uri = $input->getParameterOption(['--uri', '-l']); $env = $input->getParameterOption(['--env', '-e'], getenv('DRUPAL_ENV') ?: 'prod'); if ($env) { $this->env = $env; } $debug = getenv('DRUPAL_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; if ($debug) { Debug::enable(); } $drupal = $this->getDrupalHelper(); $this->getCommandDiscoveryHelper()->setApplicationRoot($this->getDirectoryRoot()); $recursive = false; if (!$root) { $root = getcwd(); $recursive = true; } if (!$drupal->isValidRoot($root, $recursive)) { $commands = $this->getCommandDiscoveryHelper()->getConsoleCommands(); if (!$commandName) { $this->errorMessage = $this->trans('application.site.errors.directory'); } $this->registerCommands($commands); } else { $this->getKernelHelper()->setRequestUri($uri); $this->getKernelHelper()->setDebug($debug); $this->getKernelHelper()->setEnvironment($this->env); $this->prepare($drupal); } if ($commandName && $this->has($commandName)) { $command = $this->get($commandName); $parameterOptions = $this->getDefinition()->getOptions(); foreach ($parameterOptions as $optionName => $parameterOption) { $parameterOption = [sprintf('--%s', $parameterOption->getName()), sprintf('-%s', $parameterOption->getShortcut())]; if (true === $input->hasParameterOption($parameterOption)) { $option = $this->getDefinition()->getOption($optionName); $command->getDefinition()->addOption($option); } } } return parent::doRun($input, $output); }
protected function writeSplittedFile($yaml_splitted, $file_output_prefix = '', $file_output_suffix = '', DrupalStyle $output) { $dumper = new Dumper(); $output->writeln('[+] <info>' . $this->trans('commands.yaml.split.messages.generating-split') . '</info>'); foreach ($yaml_splitted as $key => $value) { if ($file_output_prefix) { $key = $file_output_prefix . '.' . $key; } if ($file_output_suffix) { $key .= '.' . $file_output_suffix; } $filename = $key . '.yml'; try { $yaml = $dumper->dump($value, 10); } catch (\Exception $e) { $output->error(sprintf('%s: %s', $this->trans('commands.yaml.merge.messages.error-generating'), $e->getMessage())); return; } try { file_put_contents($filename, $yaml); } catch (\Exception $e) { $output->error(sprintf('%s: %s', $this->trans('commands.yaml.merge.messages.error-writing'), $e->getMessage())); return; } $output->success(sprintf($this->trans('commands.yaml.split.messages.split-generated'), $filename)); } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $resource_id = $input->getArgument('resource-id'); $rest_resources = $this->getRestResources(); $rest_resources_ids = array_merge(array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled'])); if (!$resource_id) { $resource_id = $io->choiceNoList($this->trans('commands.rest.enable.arguments.resource-id'), $rest_resources_ids); } $this->validateRestResource($resource_id, $rest_resources_ids, $this->translator); $input->setArgument('resource-id', $resource_id); // Calculate states available by resource and generate the question. $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]); $methods = $plugin->availableMethods(); $method = $io->choice($this->trans('commands.rest.enable.arguments.methods'), $methods); $io->writeln($this->trans('commands.rest.enable.messages.selected-method') . ' ' . $method); $format = $io->choice($this->trans('commands.rest.enable.arguments.formats'), $this->formats); $io->writeln($this->trans('commands.rest.enable.messages.selected-format') . ' ' . $format); // Get Authentication Provider and generate the question $authenticationProviders = $this->authenticationCollector->getSortedProviders(); $authenticationProvidersSelected = $io->choice($this->trans('commands.rest.enable.messages.authentication-providers'), array_keys($authenticationProviders), 0, true); $io->writeln($this->trans('commands.rest.enable.messages.selected-authentication-providers') . ' ' . implode(', ', $authenticationProvidersSelected)); $format_resource_id = str_replace(':', '.', $resource_id); $config = $this->entityManager->getStorage('rest_resource_config')->load($format_resource_id); if (!$config) { $config = $this->entityManager->getStorage('rest_resource_config')->create(['id' => $format_resource_id, 'granularity' => RestResourceConfigInterface::METHOD_GRANULARITY, 'configuration' => []]); } $configuration = $config->get('configuration') ?: []; $configuration[$method] = ['supported_formats' => [$format], 'supported_auth' => $authenticationProvidersSelected]; $config->set('configuration', $configuration); $config->save(); $message = sprintf($this->trans('commands.rest.enable.messages.success'), $resource_id); $io->info($message); return true; }
protected function runInstaller(DrupalStyle $output, InputInterface $input, $database) { $drupal = $this->getDrupalHelper(); $drupal->loadLegacyFile('/core/includes/install.core.inc'); $driver = (string) $database['driver']; $settings = ['parameters' => ['profile' => $input->getArgument('profile'), 'langcode' => $input->getOption('langcode')], 'forms' => ['install_settings_form' => ['driver' => $driver, $driver => $database, 'op' => 'Save and continue'], 'install_configure_form' => ['site_name' => $input->getOption('site-name'), 'site_mail' => $input->getOption('site-mail'), 'account' => array('name' => $input->getOption('account-name'), 'mail' => $input->getOption('account-mail'), 'pass' => array('pass1' => $input->getOption('account-pass'), 'pass2' => $input->getOption('account-pass'))), 'update_status_module' => array(1 => true, 2 => true), 'clean_url' => true, 'op' => 'Save and continue']]]; $output->writeln($this->trans('commands.site.install.messages.installing')); try { install_drupal($drupal->getAutoLoadClass(), $settings); } catch (AlreadyInstalledException $e) { $output->error($this->trans('commands.site.install.messages.already-installed')); return; } catch (\Exception $e) { $output->error($e->getMessage()); return; } $output->success($this->trans('commands.site.install.messages.installed')); }
/** * @param DrupalStyle $io * * @return mixed */ public function formQuestion(DrupalStyle $io) { if ($io->confirm($this->trans('commands.common.questions.inputs.confirm'), true)) { $input_types = ['fieldset', 'text_format']; if (!$this->elementInfoManager) { $io->writeln('Please inject service plugin.manager.element_info'); return false; } foreach ($this->elementInfoManager->getDefinitions() as $definition) { $type = $definition['id']; $elementInfo = $this->elementInfoManager->getInfo($type); if (isset($elementInfo['#input']) && $elementInfo['#input']) { if (!in_array($type, $input_types)) { $input_types[] = $type; } } } sort($input_types); $inputs = []; $fieldSets = []; while (true) { $input_type = $io->choiceNoList($this->trans('commands.common.questions.inputs.type'), $input_types, null, true); if (empty($input_type)) { break; } // Label for input $inputLabelMessage = $input_type == 'fieldset' ? $this->trans('commands.common.questions.inputs.title') : $this->trans('commands.common.questions.inputs.label'); $input_label = $io->ask($inputLabelMessage, null); // Machine name $input_machine_name = $this->stringConverter->createMachineName($input_label); $input_name = $io->ask($this->trans('commands.common.questions.inputs.machine_name'), $input_machine_name); if ($input_type == 'fieldset') { $fieldSets[$input_machine_name] = $input_label; } $inputFieldSet = ''; if ($input_type != 'fieldset' && !empty($fieldSets)) { $inputFieldSet = $io->choiceNoList($this->trans('commands.common.questions.inputs.fieldset'), $fieldSets, null, true); $inputFieldSet = array_search($inputFieldSet, $fieldSets); } $maxlength = null; $size = null; if (in_array($input_type, array('textfield', 'password', 'password_confirm'))) { $maxlength = $io->ask('Maximum amount of characters', '64'); $size = $io->ask('Width of the textfield (in characters)', '64'); } if ($input_type == 'select') { $size = $io->ask('Size of multiselect box (in lines)', '5'); } $input_options = ''; if (in_array($input_type, array('checkboxes', 'radios', 'select'))) { $input_options = $io->ask('Input options separated by comma'); } // Prepare options as an array if (strlen(trim($input_options))) { // remove spaces in options and empty options $input_options = array_filter(array_map('trim', explode(',', $input_options))); // Create array format for options foreach ($input_options as $key => $value) { $input_options_output[$key] = "'{$value}' => \$this->t('" . $value . "')"; } $input_options = 'array(' . implode(', ', $input_options_output) . ')'; } // Description for input $input_description = $io->askEmpty($this->trans('commands.common.questions.inputs.description')); // Default value for input switch ($input_type) { case 'checkboxes': $question = 'commands.common.questions.inputs.default-value.checkboxes'; break; default: $question = 'commands.common.questions.inputs.default-value.default-value'; break; } if ($input_type != 'fieldset') { $default_value = $io->askEmpty($this->trans($question)); } if ($input_type == 'checkboxes') { // Prepare options as an array if (strlen(trim($default_value))) { // remove spaces in options and empty options $default_options = array_filter(array_map('trim', explode(',', $default_value))); $default_value = $default_options; } } // Weight for input $weight = $io->ask($this->trans('commands.common.questions.inputs.weight'), '0'); array_push($inputs, ['name' => $input_name, 'type' => $input_type, 'label' => $input_label, 'options' => $input_options, 'description' => $input_description, 'maxlength' => $maxlength, 'size' => $size, 'default_value' => $default_value, 'weight' => $weight, 'fieldset' => $inputFieldSet]); } return $inputs; } return null; }
/** * {@inheritdoc} */ public function doRun(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $root = null; $commandName = null; $recursive = false; $config = $this->getConfig(); $target = $input->getParameterOption(['--target'], null); if ($input && ($commandName = $this->getCommandName($input))) { $this->commandName = $commandName; } $targetConfig = []; if ($target && $config->loadTarget($target)) { $targetConfig = $config->getTarget($target); $root = $targetConfig['root']; } if ($targetConfig && $targetConfig['remote']) { $remoteResult = $this->getRemoteHelper()->executeCommand($commandName, $target, $targetConfig, $input->__toString(), $config->getUserHomeDir()); $output->writeln($remoteResult); return 0; } if (!$target && $input->hasParameterOption(['--root'])) { $root = $input->getParameterOption(['--root']); $root = strpos($root, '/') === 0 ? $root : sprintf('%s/%s', getcwd(), $root); } $uri = $input->getParameterOption(['--uri', '-l']); /*Checking if the URI has http of not in begenning*/ if ($uri && !preg_match('/^(http|https):\\/\\//', $uri)) { $uri = sprintf('http://%s', $uri); } $env = $input->getParameterOption(['--env', '-e'], getenv('DRUPAL_ENV') ?: 'prod'); if ($env) { $this->env = $env; } $debug = getenv('DRUPAL_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; if ($debug) { Debug::enable(); } $drupal = $this->getDrupalHelper(); $this->getCommandDiscoveryHelper()->setApplicationRoot($this->getDirectoryRoot()); if (!$root) { $root = getcwd(); $recursive = true; } /* validate drupal site */ $this->container->get('site')->isValidRoot($root, $recursive); if (!$drupal->isValidRoot($root, $recursive)) { $commands = $this->getCommandDiscoveryHelper()->getConsoleCommands(); if ($commandName == 'list') { $this->errorMessage = $this->trans('application.site.errors.directory'); } $this->registerCommands($commands); } else { $this->getKernelHelper()->setRequestUri($uri); $this->getKernelHelper()->setDebug($debug); $this->getKernelHelper()->setEnvironment($this->env); $this->prepare($drupal, $commandName); } if ($commandName && $this->has($commandName)) { $command = $this->get($commandName); $parameterOptions = $this->getDefinition()->getOptions(); foreach ($parameterOptions as $optionName => $parameterOption) { $parameterOption = [sprintf('--%s', $parameterOption->getName()), sprintf('-%s', $parameterOption->getShortcut())]; if (true === $input->hasParameterOption($parameterOption)) { $option = $this->getDefinition()->getOption($optionName); $command->getDefinition()->addOption($option); } } } $skipCheck = ['check', 'init']; if (!in_array($commandName, $skipCheck) && $config->get('application.checked') != 'true') { $requirementChecker = $this->getContainerHelper()->get('requirement_checker'); $phpCheckFile = $this->getConfig()->getUserHomeDir() . '/.console/phpcheck.yml'; if (!file_exists($phpCheckFile)) { $phpCheckFile = $this->getDirectoryRoot() . 'config/dist/phpcheck.yml'; } $requirementChecker->validate($phpCheckFile); if (!$requirementChecker->isValid()) { $command = $this->find('check'); return $this->doRunCommand($command, $input, $output); } if ($requirementChecker->isOverwritten()) { $this->getChain()->addCommand('check'); } else { $this->getChain()->addCommand('settings:set', ['setting-name' => 'checked', 'setting-value' => 'true', '--quiet']); } } return parent::doRun($input, $output); }
/** * {@inheritdoc} */ public function doRun(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $root = null; $config = $this->getConfig(); $target = $input->getParameterOption(['--target'], null); if ($input) { $commandName = $this->getCommandName($input); $this->commandName = $commandName; } $targetConfig = []; if ($target && $config->loadTarget($target)) { $targetConfig = $config->getTarget($target); $root = $targetConfig['root']; } if ($targetConfig && $targetConfig['remote']) { $remoteResult = $this->getRemoteHelper()->executeCommand($commandName, $target, $targetConfig, $input->__toString(), $config->getUserHomeDir()); $output->writeln($remoteResult); return 0; } if (!$target) { $root = $input->getParameterOption(['--root'], null); } $uri = $input->getParameterOption(array('--uri', '-l')); $env = $input->getParameterOption(array('--env', '-e'), getenv('DRUPAL_ENV') ?: 'prod'); if (!$env) { $this->env = $env; } $debug = getenv('DRUPAL_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; if ($debug) { Debug::enable(); } $drupal = $this->getDrupalHelper(); $this->getCommandDiscoveryHelper()->setApplicationRoot($this->getDirectoryRoot()); $recursive = false; if (!$root) { $root = getcwd(); $recursive = true; } if (!$drupal->isValidRoot($root, $recursive)) { $commands = $this->getCommandDiscoveryHelper()->getConsoleCommands(); if (!$commandName) { $this->getMessageHelper()->addWarningMessage($this->trans('application.site.errors.directory')); } $this->registerCommands($commands); } else { $this->getKernelHelper()->setRequestUri($uri); $this->getKernelHelper()->setDebug($debug); $this->getKernelHelper()->setEnvironment($this->env); $this->prepare($drupal); } if (true === $input->hasParameterOption(array('--generate-doc', '--gd'))) { $command = $this->get($commandName); $command->addOption('generate-doc', '--gd', InputOption::VALUE_NONE, $this->trans('application.console.arguments.generate-doc')); } return parent::doRun($input, $output); }