/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $learning = $input->hasOption('learning') ? $input->getOption('learning') : false; $address = $this->validatePort($input->getArgument('address')); $finder = new PhpExecutableFinder(); if (false === ($binary = $finder->find())) { $io->error($this->trans('commands.server.errors.binary')); return; } $router = $this->getRouterPath(); $cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router); if ($learning) { $io->commentBlock($cli); } $io->success(sprintf($this->trans('commands.server.messages.executing'), $binary)); $processBuilder = new ProcessBuilder(explode(' ', $cli)); $process = $processBuilder->getProcess(); $process->setWorkingDirectory($this->appRoot); if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) { $process->setTty('true'); } else { $process->setTimeout(null); } $process->run(); if (!$process->isSuccessful()) { $io->error($process->getErrorOutput()); } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $moduleHandler = $this->moduleHandler; $moduleHandler->loadInclude('locale', 'inc', 'locale.translation'); $moduleHandler->loadInclude('locale', 'module'); $language = $input->getArgument('language'); $languagesObjects = locale_translatable_language_list(); $languages = $this->site->getStandardLanguages(); if (isset($languagesObjects[$language])) { $languageEntity = $languagesObjects[$language]; } elseif (array_search($language, $languages)) { $langcode = array_search($language, $languages); $languageEntity = $languagesObjects[$langcode]; } else { $io->error(sprintf($this->trans('commands.locale.language.delete.messages.invalid-language'), $language)); return 1; } try { $configurable_language_storage = $this->entityTypeManager->getStorage('configurable_language'); $configurable_language_storage->load($languageEntity->getId())->delete(); $io->info(sprintf($this->trans('commands.locale.language.delete.messages.language-deleted-successfully'), $languageEntity->getName())); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $yaml = new Parser(); $dumper = new Dumper(); $yaml_file = $input->getArgument('yaml-file'); $yaml_key = $input->getArgument('yaml-key'); $yaml_new_key = $input->getArgument('yaml-new-key'); try { $yaml_parsed = $yaml->parse(file_get_contents($yaml_file)); } catch (\Exception $e) { $io->error($this->trans('commands.yaml.merge.messages.error-parsing') . ': ' . $e->getMessage()); return; } if (empty($yaml_parsed)) { $io->info(sprintf($this->trans('commands.yaml.merge.messages.wrong-parse'), $yaml_file)); } $nested_array = $this->getNestedArrayHelper(); $parents = explode(".", $yaml_key); $nested_array->replaceKey($yaml_parsed, $parents, $yaml_new_key); try { $yaml = $dumper->dump($yaml_parsed, 10); } catch (\Exception $e) { $io->error($this->trans('commands.yaml.merge.messages.error-generating') . ': ' . $e->getMessage()); return; } try { file_put_contents($yaml_file, $yaml); } catch (\Exception $e) { $io->error($this->trans('commands.yaml.merge.messages.error-writing') . ': ' . $e->getMessage()); return; } $io->info(sprintf($this->trans('commands.yaml.update.value.messages.updated'), $yaml_file)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $siteName = $input->getArgument('name'); $directory = $input->getArgument('directory'); $fileSystem = $this->get('filesystem'); if (!$fileSystem->exists($directory)) { $io->error(sprintf($this->trans('commands.site.import.local.messages.error-missing'), $directory)); return 1; } $drupal = $this->get('site'); if (!$drupal->isValidRoot($directory)) { $io->error(sprintf($this->trans('commands.site.import.local.messages.error-not-drupal'), $directory)); return 1; } $environment = $input->getOption('environment') ?: 'local'; $siteConfig = [$environment => ['root' => $drupal->getRoot(), 'host' => 'local']]; $yaml = $this->get('yaml'); $dump = $yaml::dump($siteConfig); $config = $this->getApplication()->getConfig(); $userPath = sprintf('%s/.console/sites', $config->getUserHomeDir()); $configFile = sprintf('%s/%s.yml', $userPath, $siteName); try { $fileSystem->dumpFile($configFile, $dump); } catch (\Exception $e) { $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage())); return 1; } $io->success(sprintf($this->trans('commands.site.import.local.messages.imported'))); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $uid = $input->getArgument('uid'); $account = User::load($uid); if (!$account) { // Error loading User entity. $io->error(sprintf($this->trans('commands.user.login.clear.attempts.errors.invalid-user'), $uid)); return 1; } // Define event name and identifier. $event = 'user.failed_login_user'; // Identifier is created by uid and IP address, // Then we defined a generic identifier. $identifier = "{$account->id()}-"; // Retrieve current database connection. $database = $this->getDrupalService('database'); $schema = $database->schema(); $flood = $schema->findTables('flood'); if (!$flood) { $io->error($this->trans('commands.user.login.clear.attempts.errors.no-flood')); return 1; } // Clear login attempts. $database->delete('flood')->condition('event', $event)->condition('identifier', $database->escapeLike($identifier) . '%', 'LIKE')->execute(); // Command executed successful. $io->success(sprintf($this->trans('commands.user.login.clear.attempts.messages.successful'), $uid)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $learning = $input->hasOption('learning') ? $input->getOption('learning') : false; $address = $input->getArgument('address'); if (false === strpos($address, ':')) { $address = sprintf('%s:8088', $address); } $finder = new PhpExecutableFinder(); if (false === ($binary = $finder->find())) { $io->error($this->trans('commands.server.errors.binary')); return; } $router = $this->getRouterPath(); $cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router); if ($learning) { $io->commentBlock($cli); } $io->success(sprintf($this->trans('commands.server.messages.executing'), $binary)); $processBuilder = new ProcessBuilder(explode(' ', $cli)); $process = $processBuilder->getProcess(); $process->setWorkingDirectory($this->get('site')->getRoot()); $process->setTty('true'); $process->run(); if (!$process->isSuccessful()) { $io->error($process->getErrorOutput()); } }
/** * @param \Drupal\Console\Style\DrupalStyle $io * @param $eventType * @param $eventSeverity * @param $userId * @return bool */ protected function clearEvents(DrupalStyle $io, $eventType, $eventSeverity, $userId) { $connection = $this->getDatabase(); $severity = RfcLogLevel::getLevels(); $query = $connection->delete('watchdog'); if ($eventType) { $query->condition('type', $eventType); } if ($eventSeverity) { if (!in_array($eventSeverity, $severity)) { $io->error(sprintf($this->trans('commands.database.log.clear.messages.invalid-severity'), $eventSeverity)); return false; } $query->condition('severity', array_search($eventSeverity, $severity)); } if ($userId) { $query->condition('uid', $userId); } $result = $query->execute(); if (!$result) { $io->error($this->trans('commands.database.log.clear.messages.clear-error')); return false; } $io->success($this->trans('commands.database.log.clear.messages.clear-sucess')); return true; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $modules = $input->getArgument('module'); $composer = $input->getOption('composer'); $simulate = $input->getOption('simulate'); if (!$composer) { $io->error($this->trans('commands.module.update.messages.only-composer')); return 1; } if (!$modules) { $io->error($this->trans('commands.module.update.messages.missing-module')); return 1; } if (count($modules) > 1) { $modules = " drupal/" . implode(" drupal/", $modules); } else { $modules = " drupal/" . current($modules); } if ($composer) { // Register composer repository $command = "composer config repositories.drupal composer https://packagist.drupal-composer.org"; $this->shellProcess->exec($command, $this->root); $command = 'composer update ' . $modules . ' --optimize-autoloader --prefer-dist --no-dev --root-reqs '; if ($simulate) { $command .= " --dry-run"; } if ($this->shellProcess->exec($command, $this->root)) { $io->success(sprintf($this->trans('commands.module.update.messages.composer'), trim($modules))); } } return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $moduleHandler = $this->moduleHandler; $moduleHandler->loadInclude('locale', 'inc', 'locale.translation'); $moduleHandler->loadInclude('locale', 'module'); $language = $input->getArgument('language'); $languages = $this->site->getStandardLanguages(); if (isset($languages[$language])) { $langcode = $language; } elseif (array_search($language, $languages)) { $langcode = array_search($language, $languages); } else { $io->error(sprintf($this->trans('commands.locale.language.add.messages.invalid-language'), $language)); return 1; } try { $language = ConfigurableLanguage::createFromLangcode($langcode); $language->type = LOCALE_TRANSLATION_REMOTE; $language->save(); $io->info(sprintf($this->trans('commands.locale.language.add.messages.language-add-successfully'), $language->getName())); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $configName = $input->getArgument('name'); $fileName = $input->getArgument('file'); $config = $this->getDrupalService('config.factory')->getEditable($configName); $ymlFile = new Parser(); if (!empty($fileName) && file_exists($fileName)) { $value = $ymlFile->parse(file_get_contents($fileName)); } else { $value = $ymlFile->parse(stream_get_contents(fopen("php://stdin", "r"))); } if (empty($value)) { $io->error($this->trans('commands.config.import.single.messages.empty-value')); return; } $config->setData($value); try { $config->save(); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $io->success(sprintf($this->trans('commands.config.import.single.messages.success'), $configName)); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $configFactory = $this->getService('config.factory'); $config = $configFactory->getEditable('system.theme'); $themeHandler = $this->getService('theme_handler'); $themeHandler->refreshInfo(); $theme = $input->getArgument('theme'); $themes = $themeHandler->rebuildThemeData(); $themesAvailable = []; $themesUninstalled = []; $themesUnavailable = []; foreach ($theme as $themeName) { if (isset($themes[$themeName]) && $themes[$themeName]->status == 1) { $themesAvailable[$themeName] = $themes[$themeName]->info['name']; } elseif (isset($themes[$themeName]) && $themes[$themeName]->status == 0) { $themesUninstalled[] = $themes[$themeName]->info['name']; } else { $themesUnavailable[] = $themeName; } } if (count($themesAvailable) > 0) { try { foreach ($themesAvailable as $themeKey => $themeName) { if ($themeKey === $config->get('default')) { $io->error(sprintf($this->trans('commands.theme.uninstall.messages.error-default-theme'), implode(',', $themesAvailable))); return; } if ($themeKey === $config->get('admin')) { $io->error(sprintf($this->trans('commands.theme.uninstall.messages.error-admin-theme'), implode(',', $themesAvailable))); return; } } $themeHandler->uninstall($theme); if (count($themesAvailable) > 1) { $io->info(sprintf($this->trans('commands.theme.uninstall.messages.themes-success'), implode(',', $themesAvailable))); } else { $io->info(sprintf($this->trans('commands.theme.uninstall.messages.theme-success'), array_shift($themesAvailable))); } } catch (UnmetDependenciesException $e) { $io->error(sprintf($this->trans('commands.theme.uninstall.messages.dependencies'), $e->getMessage())); drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $theme), 'error'); } } elseif (empty($themesAvailable) && count($themesUninstalled) > 0) { if (count($themesUninstalled) > 1) { $io->info(sprintf($this->trans('commands.theme.uninstall.messages.themes-nothing'), implode(',', $themesUninstalled))); } else { $io->info(sprintf($this->trans('commands.theme.uninstall.messages.theme-nothing'), implode(',', $themesUninstalled))); } } else { if (count($themesUnavailable) > 1) { $io->error(sprintf($this->trans('commands.theme.uninstall.messages.themes-missing'), implode(',', $themesUnavailable))); } else { $io->error(sprintf($this->trans('commands.theme.uninstall.messages.theme-missing'), implode(',', $themesUnavailable))); } } // Run cache rebuild to see changes in Web UI $this->get('chain_queue')->addCommand('cache:rebuild', ['cache' => 'all']); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $httpClient = $this->getHttpClientHelper(); $siteName = $input->getArgument('site-name'); $version = $input->getArgument('version'); if ($version) { $releaseSelected = $version; } else { // Getting Module page header and parse to get module Node $io->info(sprintf($this->trans('commands.site.new.messages.getting-releases'))); // Page for Drupal releases filter by Drupal 8 $projectReleaseSelected = '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($projectReleaseSelected); } catch (\Exception $e) { $io->error($e->getMessage()); return; } $crawler = new Crawler($html); $releases = []; foreach ($crawler->filter('span.file a') as $element) { if (strpos($element->nodeValue, ".tar.gz") > 0) { $releaseName = str_replace('.tar.gz', '', str_replace('drupal-', '', $element->nodeValue)); $releases[$releaseName] = $element->nodeValue; } } if (empty($releases)) { $io->error($this->trans('commands.site.new.messages.no-releases')); return; } $releaseSelected = $io->choice($this->trans('commands.site.new.messages.release'), array_keys($releases)); } $releaseFilePath = 'http://ftp.drupal.org/files/projects/drupal-' . $releaseSelected . '.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 $io->info(sprintf($this->trans('commands.site.new.messages.downloading'), $releaseSelected)); $httpClient->downloadFile($releaseFilePath, $destination); $io->info(sprintf($this->trans('commands.site.new.messages.extracting'), $releaseSelected)); $zippy = Zippy::load(); $archive = $zippy->open($destination); $archive->extract('./'); try { $filesyStem = new Filesystem(); $filesyStem->rename('./drupal-' . $releaseSelected, './' . $siteName); } catch (IOExceptionInterface $e) { $io->error(sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath())); } $io->success(sprintf($this->trans('commands.site.new.messages.downloaded'), $releaseSelected, $siteName)); } catch (\Exception $e) { $io->error($e->getMessage()); return false; } return true; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $composer = $input->getOption('composer'); $module = $input->getArgument('module'); $this->get('site')->loadLegacyFile('/core/modules/system/system.module'); $coreExtension = $this->getDrupalService('config.factory')->getEditable('core.extension'); $moduleInstaller = $this->getDrupalService('module_installer'); // Get info about modules available $moduleData = system_rebuild_module_data(); $moduleList = array_combine($module, $module); if ($composer) { //@TODO: check with Composer if the module is previously required in composer.json! foreach ($module as $moduleItem) { $command = sprintf('composer remove drupal/%s ', $moduleItem); $shellProcess = $this->get('shell_process'); if ($shellProcess->exec($command)) { $io->success(sprintf($this->trans('commands.module.uninstall.messages.composer-success'), $moduleItem)); } } } if ($missingModules = array_diff_key($moduleList, $moduleData)) { $io->error(sprintf($this->trans('commands.module.uninstall.messages.missing'), implode(', ', $module), implode(', ', $missingModules))); return 1; } $installedModules = $coreExtension->get('module') ?: array(); if (!($moduleList = array_intersect_key($moduleList, $installedModules))) { $io->info($this->trans('commands.module.uninstall.messages.nothing')); return 0; } if (!($force = $input->getOption('force'))) { $dependencies = []; while (list($module) = each($moduleList)) { foreach (array_keys($moduleData[$module]->required_by) as $dependency) { if (isset($installedModules[$dependency]) && !isset($moduleList[$dependency]) && $dependency != $profile) { $dependencies[] = $dependency; } } } if (!empty($dependencies)) { $io->error(sprintf($this->trans('commands.module.uninstall.messages.dependents'), implode(', ', $module), implode(', ', $dependencies))); return 1; } } try { $moduleInstaller->uninstall($moduleList); $io->info(sprintf($this->trans('commands.module.uninstall.messages.success'), implode(', ', $moduleList))); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $this->get('chain_queue')->addCommand('cache:rebuild', ['cache' => 'discovery']); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $this->getDrupalHelper()->loadLegacyFile('/core/modules/system/system.module'); $extension_config = $this->getConfigFactory()->getEditable('core.extension'); $moduleInstaller = $this->getModuleInstaller(); // Get info about modules available $module_data = system_rebuild_module_data(); $module = $input->getArgument('module'); $modules = array_filter(array_map('trim', explode(',', $module))); $module_list = array_combine($modules, $modules); // Determine if some module request is missing if ($missing_modules = array_diff_key($module_list, $module_data)) { $io->error(sprintf($this->trans('commands.module.uninstall.messages.missing'), implode(', ', $modules), implode(', ', $missing_modules))); return true; } // Only process currently installed modules. $installed_modules = $extension_config->get('module') ?: array(); if (!($module_list = array_intersect_key($module_list, $installed_modules))) { $io->info($this->trans('commands.module.uninstall.messages.nothing')); return true; } $force = $input->getOption('force'); if (!$force) { // Calculate $dependents $dependents = array(); while (list($module) = each($module_list)) { foreach (array_keys($module_data[$module]->required_by) as $dependent) { // Skip already uninstalled modules. if (isset($installed_modules[$dependent]) && !isset($module_list[$dependent]) && $dependent != $profile) { $dependents[] = $dependent; } } } // Error if there are missing dependencies if (!empty($dependents)) { $io->error(sprintf($this->trans('commands.module.uninstall.messages.dependents'), implode(', ', $modules), implode(', ', $dependents))); return true; } } // Installing modules try { // Uninstall the modules. $moduleInstaller->uninstall($module_list); $io->info(sprintf($this->trans('commands.module.uninstall.messages.success'), implode(', ', $modules))); } catch (\Exception $e) { $io->error($e->getMessage()); return; } // Run cache rebuild to see changes in Web UI $this->getChain()->addCommand('cache:rebuild', ['cache' => 'discovery']); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $this->getDrupalHelper()->loadLegacyFile('/core/includes/install.inc'); $this->getDrupalHelper()->loadLegacyFile('/core/includes/update.inc'); $module = $input->getArgument('module'); $update_n = $input->getArgument('update-n'); $module_handler = $this->getModuleHandler(); drupal_load_updates(); update_fix_compatibility(); $updates = update_get_update_list(); if ($module != 'all') { if (!isset($updates[$module])) { $io->error(sprintf($this->trans('commands.update.execute.messages.no-module-updates'), $module)); return; } else { // filter to execute only a specific module updates $updates = [$module => $updates[$module]]; if ($update_n && !isset($updates[$module]['pending'][$update_n])) { $io->info(sprintf($this->trans('commands.update.execute.messages.module-update-function-not-found'), $module, $update_n)); } } } $io->info($this->trans('commands.site.maintenance.description')); $state = $this->getService('state'); $state->set('system.maintenance_mode', true); foreach ($updates as $module_name => $module_updates) { foreach ($module_updates['pending'] as $update_number => $update) { if ($module != 'all' && $update_n !== null && $update_n != $update_number) { continue; } //Executing all pending updates if ($update_n > $module_updates['start']) { $io->info($this->trans('commands.update.execute.messages.executing-required-previous-updates')); } for ($update_index = $module_updates['start']; $update_index <= $update_number; $update_index++) { $io->info(sprintf($this->trans('commands.update.execute.messages.executing-update'), $update_index, $module_name)); try { $module_handler->invoke($module_name, 'update_' . $update_index); } catch (\Exception $e) { watchdog_exception('update', $e); $io->error($e->getMessage()); } //Update module schema version drupal_set_installed_schema_version($module_name, $update_index); } } } $state->set('system.maintenance_mode', false); $io->info($this->trans('commands.site.maintenance.messages.maintenance-off')); $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $directory = $input->getArgument('directory'); $version = $input->getArgument('version'); $latest = $input->getOption('latest'); $composer = $input->getOption('composer'); if (!$directory) { $io->error($this->trans('commands.site.new.messages.missing-directory')); return 1; } if ($composer) { if (!$version) { $version = '8.x-dev'; } $io->newLine(); $io->comment(sprintf($this->trans('commands.site.new.messages.executing'), 'drupal', $version)); $command = sprintf('composer create-project %s:%s %s --no-interaction', 'drupal-composer/drupal-project', $version, $directory); $io->commentBlock($command); $shellProcess = $this->get('shell_process'); if ($shellProcess->exec($command)) { $io->success(sprintf($this->trans('commands.site.new.messages.composer'), $version, $directory)); return 0; } else { return 1; } } if (!$version && $latest) { $version = current($this->getApplication()->getDrupalApi()->getProjectReleases('drupal', 1, true)); } if (!$version) { $io->error('Missing version'); return 1; } $projectPath = $this->downloadProject($io, 'drupal', $version, 'core'); $downloadPath = sprintf('%sdrupal-%s', $projectPath, $version); if ($this->isAbsolutePath($directory)) { $copyPath = $directory; } else { $copyPath = sprintf('%s%s', $projectPath, $directory); } try { $fileSystem = new Filesystem(); $fileSystem->rename($downloadPath, $copyPath); } catch (IOExceptionInterface $e) { $io->commentBlock(sprintf($this->trans('commands.site.new.messages.downloaded'), $version, $downloadPath)); $io->error(sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath())); return 1; } $io->success(sprintf($this->trans('commands.site.new.messages.downloaded'), $version, $copyPath)); return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $userId = $input->getOption('user-id'); if ($userId && $userId <= 1) { $io->error(sprintf($this->trans('commands.user.delete.errors.invalid-user-id'), $userId)); return; } if ($userId) { $user = $this->getEntityManager()->getStorage('user')->load($userId); if (!$user) { $io->error(sprintf($this->trans('commands.user.delete.errors.invalid-user'), $userId)); return; } try { $user->delete(); $io->info(sprintf($this->trans('commands.user.delete.messages.user-deleted'), $user->getUsername())); } catch (\Exception $e) { $io->error($e->getMessage()); } return; } $roles = $input->getOption('roles'); if ($roles) { $entityManager = $this->getEntityManager(); $userStorage = $entityManager->getStorage('user'); $entityQuery = $this->getEntityQuery(); $query = $entityQuery->get('user'); $query->condition('roles', is_array($roles) ? $roles : [$roles], 'IN'); $query->condition('uid', 1, '>'); $results = $query->execute(); $users = $userStorage->loadMultiple($results); $tableHeader = [$this->trans('commands.user.debug.messages.user-id'), $this->trans('commands.user.debug.messages.username')]; $tableRows = []; foreach ($users as $userId => $user) { try { $user->delete(); $tableRows['success'][] = [$userId, $user->getUsername()]; } catch (\Exception $e) { $tableRows['error'][] = [$userId, $user->getUsername()]; $io->error($e->getMessage()); return; } } if ($tableRows['success']) { $io->table($tableHeader, $tableRows['success']); $io->success(sprintf($this->trans('commands.user.delete.messages.users-deleted'), count($tableRows['success']))); } } }
public function resolveConnection(DrupalStyle $io, $database = 'default') { $connectionInfo = $this->getConnectionInfo(); if (!$connectionInfo || !isset($connectionInfo[$database])) { $io->error(sprintf($this->trans('commands.database.connect.messages.database-not-found'), $database)); return null; } $databaseConnection = $connectionInfo[$database]; if (!in_array($databaseConnection['driver'], $this->supportedDrivers)) { $io->error(sprintf($this->trans('commands.database.connect.messages.database-not-supported'), $databaseConnection['driver'])); return null; } return $databaseConnection; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $interactive = false; $learning = $input->hasOption('learning') ? $input->getOption('learning') : false; $file = null; if ($input->hasOption('file')) { $file = $input->getOption('file'); } if (!$file) { $io->error($this->trans('commands.chain.messages.missing_file')); return; } if (strpos($file, '~') === 0) { $home = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/'); $file = realpath(preg_replace('/~/', $home, $file, 1)); } if (!(strpos($file, '/') === 0)) { $file = sprintf('%s/%s', getcwd(), $file); } if (!file_exists($file)) { $io->error(sprintf($this->trans('commands.chain.messages.invalid_file'), $file)); return; } $configData = $this->getApplication()->getConfig()->getFileContents($file); $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->getChain()->addCommand($command['command'], $moduleInputs, $interactive, $learning); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $viewId = $input->getArgument('view-id'); $view = $this->entityTypeManager->getStorage('view')->load($viewId); if (empty($view)) { $io->error(sprintf($this->trans('commands.views.debug.messages.not-found'), $viewId)); return; } try { $view->disable()->save(); $io->success(sprintf($this->trans('commands.views.disable.messages.disabled-successfully'), $view->get('label'))); } catch (\Exception $e) { $io->error($e->getMessage()); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $vocabularies = $this->getDrupalApi()->getVocabularies(); // Validate provided vocabularies $vids = $input->getArgument('vocabularies'); $invalidVids = array_filter(array_map(function ($vid) use($vocabularies) { if (!isset($vocabularies[$vid])) { return $vid; } else { return null; } }, $vids)); if (!empty($invalidVids)) { $io->error(sprintf($this->trans('commands.create.terms.messages.invalid-vocabularies'), implode(',', $invalidVids))); return; } $limit = $input->getOption('limit') ?: 10; $nameWords = $input->getOption('name-words') ?: 5; $createTerms = $this->getDrupalApi()->getCreateTerms(); $terms = $createTerms->createTerm($vids, $limit, $nameWords); $tableHeader = [$this->trans('commands.create.terms.messages.term-id'), $this->trans('commands.create.terms.messages.vocabulary'), $this->trans('commands.create.terms.messages.name')]; $io->table($tableHeader, $terms['success']); $io->success(sprintf($this->trans('commands.create.terms.messages.created-terms'), $limit)); return; }
private function restDetail(DrupalStyle $io, $resource_id) { $config = $this->getRestDrupalConfig(); $resourcePluginManager = $this->getPluginManagerRest(); $plugin = $resourcePluginManager->getInstance(array('id' => $resource_id)); if (empty($plugin)) { $io->error(sprintf($this->trans('commands.rest.debug.messages.not-found'), $resource_id)); return false; } $resource = $plugin->getPluginDefinition(); $configuration = []; $configuration[] = [$this->trans('commands.rest.debug.messages.id'), $resource['id']]; $configuration[] = [$this->trans('commands.rest.debug.messages.label'), (string) $resource['label']]; $configuration[] = [$this->trans('commands.rest.debug.messages.canonical_url'), $resource['uri_paths']['canonical']]; $configuration[] = [$this->trans('commands.rest.debug.messages.status'), isset($config[$resource['id']]) ? $this->trans('commands.rest.debug.messages.enabled') : $this->trans('commands.rest.debug.messages.disabled')]; $configuration[] = [$this->trans('commands.rest.debug.messages.provider', $resource['provider'])]; $io->comment($resource_id); $io->newLine(); $io->table([], $configuration, 'compact'); $tableHeader = [$this->trans('commands.rest.debug.messages.rest-state'), $this->trans('commands.rest.debug.messages.supported-formats'), $this->trans('commands.rest.debug.messages.supported_auth')]; $tableRows = []; foreach ($config[$resource['id']] as $method => $settings) { $tableRows[] = [$method, implode(', ', $settings['supported_formats']), implode(', ', $settings['supported_auth'])]; } $io->table($tableHeader, $tableRows); }
/** * @param \Drupal\Console\Style\DrupalStyle $io * @param $view_id * @return bool */ private function viewDetail(DrupalStyle $io, $view_id) { $entity_manager = $this->getEntityManager(); $view = $entity_manager->getStorage('view')->load($view_id); if (empty($view)) { $io->error(sprintf($this->trans('commands.views.debug.messages.not-found'), $view_id)); return false; } $configuration = array(); $configuration[] = [$this->trans('commands.views.debug.messages.view-id'), $view->get('id')]; $configuration[] = [$this->trans('commands.views.debug.messages.view-name'), (string) $view->get('label')]; $configuration[] = [$this->trans('commands.views.debug.messages.tag'), $view->get('tag')]; $configuration[] = [$this->trans('commands.views.debug.messages.status'), $view->status() ? $this->trans('commands.common.status.enabled') : $this->trans('commands.common.status.disabled')]; $configuration[] = [$this->trans('commands.views.debug.messages.description'), $view->get('description')]; $io->comment($view_id); $io->table([], $configuration); $tableHeader = [$this->trans('commands.views.debug.messages.display-id'), $this->trans('commands.views.debug.messages.display-name'), $this->trans('commands.views.debug.messages.display-description'), $this->trans('commands.views.debug.messages.display-paths')]; $displays = $this->viewDisplayList($view); $io->info(sprintf($this->trans('commands.views.debug.messages.display-list'), $view_id)); $tableRows = []; foreach ($displays as $display_id => $display) { $tableRows[] = [$display_id, $display['name'], $display['description'], $this->viewDisplayPaths($view, $display_id)]; } $io->table($tableHeader, $tableRows, 'compact'); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $validator_filename = function ($value) use($io) { if (!strlen(trim($value)) || !is_file($value)) { $io->error($this->trans('commands.common.errors.invalid-file-path')); return false; } return $value; }; // --yaml-left option $yaml_left = $input->getArgument('yaml-left'); if (!$yaml_left) { while (true) { $yaml_left = $output->ask($this->trans('commands.yaml.diff.questions.yaml-left'), null, $validator_filename); if ($yaml_left) { break; } } $input->setArgument('yaml-left', $yaml_left); } // --yaml-right option $yaml_right = $input->getArgument('yaml-right'); if (!$yaml_right) { while (true) { $yaml_right = $output->ask($this->trans('commands.yaml.diff.questions.yaml-right'), null, $validator_filename); if ($yaml_right) { break; } } $input->setArgument('yaml-right', $yaml_right); } }
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')); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $passwords = $input->getArgument('password'); if (!$passwords) { $passwords = []; while (true) { $password = $io->ask($this->trans('commands.user.password.hash.questions.password'), '', function ($pass) use($passwords, $io) { if (!empty($pass) || count($passwords) >= 1) { if ($pass == '') { return true; } return $pass; } else { $io->error(sprintf($this->trans('commands.user.password.hash.questions.invalid-pass'), $pass)); return false; } }); if ($password && !is_string($password)) { break; } if (is_string($password)) { $passwords[] = $password; } } $input->setArgument('password', $passwords); } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $modules = $input->getArgument('module'); $module_handler = $this->getDrupalService('module_handler'); $lock = $this->getDrupalService('lock'); // Try to acquire cron lock. if (!$lock->acquire('cron', 900.0)) { $io->warning($this->trans('commands.cron.execute.messages.lock')); return; } if (in_array('all', $modules)) { $modules = $module_handler->getImplementations('cron'); } foreach ($modules as $module) { if ($module_handler->implementsHook($module, 'cron')) { $io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module)); try { $module_handler->invoke($module, 'cron'); } catch (\Exception $e) { watchdog_exception('cron', $e); $io->error($e->getMessage()); } } else { $io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module)); } } // Set last time cron was executed \Drupal::state()->set('system.cron_last', REQUEST_TIME); // Release cron lock. $lock->release('cron'); $this->get('chain_queue')->addCommand('cache:rebuild', ['cache' => 'all']); $io->success($this->trans('commands.cron.execute.messages.success')); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $language = $input->getArgument('language'); $format = $input->getOption('format'); $application = $this->getApplication(); $appRoot = $application->getDirectoryRoot(); $languages = $application->getConfig()->get('application.languages'); unset($languages['en']); if ($language && !isset($languages[$language])) { $io->error(sprintf($this->trans('commands.translation.stats.messages.invalid-language'), $language)); return 1; } if ($language) { $languages = [$language => $languages[$language]]; } $stats = $this->calculateStats($io, $language, $languages, $appRoot); if ($format == 'table') { $tableHeaders = [$this->trans('commands.translation.stats.messages.language'), $this->trans('commands.translation.stats.messages.percentage'), $this->trans('commands.translation.stats.messages.iso')]; $io->table($tableHeaders, $stats); return 0; } if ($format == 'markdown') { $arguments['language'] = $this->trans('commands.translation.stats.messages.language'); $arguments['percentage'] = $this->trans('commands.translation.stats.messages.percentage'); $arguments['languages'] = $stats; $io->writeln($this->getRenderHelper()->render('core/translation/stats.md.twig', $arguments)); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $modules = $input->getArgument('module'); if (!$this->lock->acquire('cron', 900.0)) { $io->warning($this->trans('commands.cron.execute.messages.lock')); return 1; } if (in_array('all', $modules)) { $modules = $this->moduleHandler->getImplementations('cron'); } foreach ($modules as $module) { if (!$this->moduleHandler->implementsHook($module, 'cron')) { $io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module)); continue; } try { $io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module)); $this->moduleHandler->invoke($module, 'cron'); } catch (\Exception $e) { watchdog_exception('cron', $e); $io->error($e->getMessage()); } } $this->state->set('system.cron_last', REQUEST_TIME); $this->lock->release('cron'); $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); $io->success($this->trans('commands.cron.execute.messages.success')); return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $configName = $input->getArgument('name'); $fileName = $input->getArgument('file'); $ymlFile = new Parser(); if (!empty($fileName) && file_exists($fileName)) { $value = $ymlFile->parse(file_get_contents($fileName)); } else { $value = $ymlFile->parse(stream_get_contents(fopen("php://stdin", "r"))); } if (empty($value)) { $io->error($this->trans('commands.config.import.single.messages.empty-value')); return; } try { $source_storage = new StorageReplaceDataWrapper($this->configStorage); $source_storage->replaceData($configName, $value); $storage_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager); if ($this->configImport($io, $storage_comparer)) { $io->success(sprintf($this->trans('commands.config.import.single.messages.success'), $configName)); } } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } }