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'); try { $yaml_parsed = $yaml->parse(file_get_contents($yaml_file), true); } 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)); } else { $nested_array = $this->getApplication()->getNestedArrayHelper(); $parents = explode(".", $yaml_key); $yaml_value = $nested_array::getValue($yaml_parsed, $parents, $key_exists); if (!$key_exists) { $io->info(sprintf($this->trans('commands.yaml.get.value.messages.invalid-key'), $yaml_key, $yaml_file)); } $output->writeln($yaml_value); } }
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); $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; }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $language = $input->getArgument('language'); $tableHeader = [$this->trans('commands.locale.translation.status.messages.project'), $this->trans('commands.locale.translation.status.messages.version'), $this->trans('commands.locale.translation.status.messages.local-age'), $this->trans('commands.locale.translation.status.messages.remote-age'), $this->trans('commands.locale.translation.status.messages.info')]; $languages = locale_translatable_language_list(); $status = locale_translation_get_status(); $this->getModuleHandler()->loadInclude('locale', 'compare.inc'); if (!$languages) { $io->info($this->trans('commands.locale.translation.status.messages.no-languages')); return; } elseif (empty($status)) { $io->info($this->trans('commands.locale.translation.status.messages.no-translations')); return; } if ($languages) { $projectsStatus = $this->projectsStatus(); foreach ($projectsStatus as $langcode => $rows) { $tableRows = []; if ($language != '' && !($language == $langcode || strtolower($language) == strtolower($languages[$langcode]->getName()))) { continue; } $io->info($languages[$langcode]->getName()); foreach ($rows as $row) { if ($row[0] == 'drupal') { $row[0] = $this->trans('commands.common.messages.drupal-core'); } $tableRows[] = $row; } $io->table($tableHeader, $tableRows, 'compact'); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $yaml = new Parser(); $yaml_left = $input->getArgument('yaml-left'); $yaml_right = $input->getArgument('yaml-right'); $stats = $input->getOption('stats'); $negate = $input->getOption('negate'); $limit = $input->getOption('limit'); $offset = $input->getOption('offset'); if ($negate == 1 || $negate == 'TRUE') { $negate = true; } else { $negate = false; } try { $yamlLeftParsed = $yaml->parse(file_get_contents($yaml_left)); if (empty($yamlLeftParsed)) { $io->error(sprintf($this->trans('commands.yaml.merge.messages.wrong-parse'), $yaml_left)); } $yamlRightParsed = $yaml->parse(file_get_contents($yaml_right)); if (empty($yamlRightParsed)) { $io->error(sprintf($this->trans('commands.yaml.merge.messages.wrong-parse'), $yaml_right)); } } catch (\Exception $e) { $io->error($this->trans('commands.yaml.merge.messages.error-parsing') . ': ' . $e->getMessage()); return; } $statistics = ['total' => 0, 'equal' => 0, 'diff' => 0]; /* print_r($yamlLeftParsed); print_r($yamlRightParsed);*/ $diff = $this->nestedArray->arrayDiff($yamlLeftParsed, $yamlRightParsed, $negate, $statistics); print_r($diff); if ($stats) { $io->info(sprintf($this->trans('commands.yaml.diff.messages.total'), $statistics['total'])); $io->info(sprintf($this->trans('commands.yaml.diff.messages.diff'), $statistics['diff'])); $io->info(sprintf($this->trans('commands.yaml.diff.messages.equal'), $statistics['equal'])); return; } // FLAT YAML file to display full yaml to be used with command yaml:update:key or yaml:update:value $diffFlatten = array(); $keyFlatten = ''; $this->nestedArray->yamlFlattenArray($diff, $diffFlatten, $keyFlatten); if ($limit !== null) { if (!$offset) { $offset = 0; } $diffFlatten = array_slice($diffFlatten, $offset, $limit); } $tableHeader = [$this->trans('commands.yaml.diff.messages.key'), $this->trans('commands.yaml.diff.messages.value')]; $tableRows = []; foreach ($diffFlatten as $yamlKey => $yamlValue) { $tableRows[] = [$yamlKey, $yamlValue]; print $yamlKey . "\n"; print $yamlValue . "\n"; } $io->table($tableHeader, $tableRows, 'compact'); }
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); $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']); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $this->get('site')->loadLegacyFile('/core/includes/update.inc'); $this->get('site')->loadLegacyFile('/core/includes/install.inc'); $updateRegistry = $this->getDrupalService('update.post_update_registry'); drupal_load_updates(); update_fix_compatibility(); $updates = update_get_update_list(); $postUpdates = $updateRegistry->getPendingUpdateInformation(); $requirements = update_check_requirements(); $severity = drupal_requirements_severity($requirements); $io->newLine(); if ($severity == REQUIREMENT_ERROR || $severity == REQUIREMENT_WARNING) { $io->info($this->trans('commands.update.debug.messages.requirements-error')); $tableHeader = [$this->trans('commands.update.debug.messages.severity'), $this->trans('commands.update.debug.messages.title'), $this->trans('commands.update.debug.messages.value'), $this->trans('commands.update.debug.messages.description')]; $tableRows = []; foreach ($requirements as $requirement) { if (isset($requirement['minimum schema']) & in_array($requirement['minimum schema'], array(REQUIREMENT_ERROR, REQUIREMENT_WARNING))) { $tableRows[] = [$requirement['severity'], $requirement['title'], $requirement['value'], $requirement['description']]; } } $io->table($tableHeader, $tableRows); return; } if (empty($updates)) { $io->info($this->trans('commands.update.debug.messages.no-updates')); return; } $tableHeader = [$this->trans('commands.update.debug.messages.module'), $this->trans('commands.update.debug.messages.update-n'), $this->trans('commands.update.debug.messages.description')]; $io->info($this->trans('commands.update.debug.messages.module-list')); $tableRows = []; foreach ($updates as $module => $module_updates) { foreach ($module_updates['pending'] as $update_n => $update) { list(, $description) = explode($update_n . " - ", $update); $tableRows[] = [$module, $update_n, trim($description)]; } } $io->table($tableHeader, $tableRows); $tableHeader = [$this->trans('commands.update.debug.messages.module'), $this->trans('commands.update.debug.messages.post-update'), $this->trans('commands.update.debug.messages.description')]; $io->info($this->trans('commands.update.debug.messages.module-list-post-update')); $tableRows = []; foreach ($postUpdates as $module => $module_updates) { foreach ($module_updates['pending'] as $postUpdateFunction => $message) { $tableRows[] = [$module, $postUpdateFunction, $message]; } } $io->table($tableHeader, $tableRows); }
protected function writeSplittedFile($yaml_splitted, $file_output_prefix = '', $file_output_suffix = '', DrupalStyle $io) { $dumper = new Dumper(); $io->info($this->trans('commands.yaml.split.messages.generating-split')); 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) { $io->error(sprintf('%s: %s', $this->trans('commands.yaml.merge.messages.error-generating'), $e->getMessage())); return; } try { file_put_contents($filename, $yaml); } catch (\Exception $e) { $io->error(sprintf('%s: %s', $this->trans('commands.yaml.merge.messages.error-writing'), $e->getMessage())); return; } $io->success(sprintf($this->trans('commands.yaml.split.messages.split-generated'), $filename)); } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $environment = $input->getArgument('environment'); $loadedConfigurations = []; if (in_array($environment, array('dev', 'prod'))) { $loadedConfigurations = $this->loadConfigurations($environment); } else { $io->error($this->trans('commands.site.mode.messages.invalid-env')); } $configurationOverrideResult = $this->overrideConfigurations($loadedConfigurations['configurations']); foreach ($configurationOverrideResult as $configName => $result) { $io->info($this->trans('commands.site.mode.messages.configuration') . ':', false); $io->comment($configName); $tableHeader = [$this->trans('commands.site.mode.messages.configuration-key'), $this->trans('commands.site.mode.messages.original'), $this->trans('commands.site.mode.messages.updated')]; $io->table($tableHeader, $result); } $servicesOverrideResult = $this->overrideServices($loadedConfigurations['services'], $io); if (!empty($servicesOverrideResult)) { $io->info($this->trans('commands.site.mode.messages.new-services-settings')); $tableHeaders = [$this->trans('commands.site.mode.messages.service'), $this->trans('commands.site.mode.messages.service-parameter'), $this->trans('commands.site.mode.messages.service-value')]; $io->table($tableHeaders, $servicesOverrideResult); } $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); }
/** * {@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; }
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)); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $nestedArray = $this->getNestedArrayHelper(); $application = $this->getApplication(); $config = $application->getConfig(); $configApplication = $config->get('application'); unset($configApplication['autowire']); unset($configApplication['languages']); unset($configApplication['aliases']); unset($configApplication['default']); $configApplicationFlatten = []; $keyFlatten = ''; $nestedArray->yamlFlattenArray($configApplication, $configApplicationFlatten, $keyFlatten); $tableHeader = [$this->trans('commands.settings.debug.messages.config-key'), $this->trans('commands.settings.debug.messages.config-value')]; $tableRows = []; foreach ($configApplicationFlatten as $yamlKey => $yamlValue) { $tableRows[] = [$yamlKey, $yamlValue]; } $io->newLine(); $io->info(sprintf('%s :', $this->trans('commands.settings.debug.messages.config-file')), false); $io->comment(sprintf('%s/.console/config.yml', $config->getUserHomeDir()), true); $io->newLine(); $io->table($tableHeader, $tableRows, 'compact'); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $module = $input->getArgument('module'); $module_handler = $this->getModuleHandler(); if ($module != 'all') { $modules = [$module]; } else { $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)); } } $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']); }
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); $styles = $input->getArgument('styles'); $result = 0; $imageStyle = $this->entityTypeManager->getStorage('image_style'); $stylesNames = []; if (in_array('all', $styles)) { $styles = $imageStyle->loadMultiple(); foreach ($styles as $style) { $stylesNames[] = $style->get('name'); } $styles = $stylesNames; } foreach ($styles as $style) { try { $io->info(sprintf($this->trans('commands.image.styles.flush.messages.executing-flush'), $style)); $imageStyle->load($style)->flush(); } catch (\Exception $e) { watchdog_exception('image', $e); $io->error($e->getMessage()); $result = 1; } } $io->success($this->trans('commands.image.styles.flush.messages.success')); return $result; }
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; }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $state = $this->getState(); $mode = $input->getArgument('mode'); $stateName = 'system.maintenance_mode'; $modeMessage = null; $cacheRebuild = true; if ('ON' === strtoupper($mode)) { $state->set($stateName, true); $modeMessage = 'commands.site.maintenance.messages.maintenance-on'; } if ('OFF' === strtoupper($mode)) { $state->set($stateName, false); $modeMessage = 'commands.site.maintenance.messages.maintenance-off'; } if ($modeMessage === null) { $modeMessage = 'commands.site.maintenance.errors.invalid-mode'; $cacheRebuild = false; } $io->info($this->trans($modeMessage)); if ($cacheRebuild) { $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']); } }
/** * Destroy all existing terms before import * @param $vid * @param $io */ private function deleteExistingTerms($vid = null, DrupalStyle $io) { //Load the vid $termStorage = $this->entityTypeManager->getStorage('taxonomy_term'); $vocabularies = $this->entityTypeManager->getStorage('taxonomy_vocabulary')->loadMultiple(); if ($vid !== 'all') { $vid = [$vid]; } else { $vid = array_keys($vocabularies); } foreach ($vid as $item) { if (!isset($vocabularies[$item])) { $io->error("Invalid vid: {$item}."); } $vocabulary = $vocabularies[$item]; $terms = $termStorage->loadTree($vocabulary->id()); foreach ($terms as $term) { $treal = $termStorage->load($term->tid); if ($treal !== null) { $io->info("Deleting '{$term->name}' and all translations."); $treal->delete(); } } } }
/** * @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'); }
private function downloadModules(DrupalStyle $io, $modules, $latest, $path = null, $resultList = []) { if (!$resultList) { $resultList = ['invalid' => [], 'uninstalled' => [], 'dependencies' => []]; } drupal_static_reset('system_rebuild_module_data'); $validator = $this->getApplication()->getValidator(); $missingModules = $validator->getMissingModules($modules); $invalidModules = []; if ($missingModules) { $io->info(sprintf($this->trans('commands.module.install.messages.getting-missing-modules'), implode(', ', $missingModules))); foreach ($missingModules as $missingModule) { $version = $this->releasesQuestion($io, $missingModule, $latest); if ($version) { $this->downloadProject($io, $missingModule, $version, 'module', $path); } else { $invalidModules[] = $missingModule; unset($modules[array_search($missingModule, $modules)]); } $this->getApplication()->getSite()->discoverModules(); } } $unInstalledModules = $validator->getUninstalledModules($modules); $dependencies = $this->calculateDependencies($unInstalledModules); $resultList = ['invalid' => array_unique(array_merge($resultList['invalid'], $invalidModules)), 'uninstalled' => array_unique(array_merge($resultList['uninstalled'], $unInstalledModules)), 'dependencies' => array_unique(array_merge($resultList['dependencies'], $dependencies))]; if (!$dependencies) { return $resultList; } return $this->downloadModules($io, $dependencies, $latest, $path, $resultList); }
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); $module = $input->getArgument('module'); $absolute = $input->getOption('absolute'); $modulePath = $this->getSite()->getThemePath($module, $absolute); $io->info($modulePath); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $theme = $input->getArgument('theme'); $fullPath = $input->getOption('absolute'); $theme = $this->extensionManager->getTheme($theme); $io->info($theme->getPath($fullPath)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); if ($input->getOption('xml')) { $io->info('The --xml option was deprecated in version 2.7 and will be removed in version 3.0. Use the --format option instead', E_USER_DEPRECATED); $input->setOption('format', 'xml'); } $helper = new DescriptorHelper(); $helper->describe($io, $this->getApplication(), array('format' => $input->getOption('format'), 'raw_text' => $input->getOption('raw'), 'namespace' => $input->getArgument('namespace'))); }
/** * @param string $module * @param DrupalStyle $io */ protected function exportConfigToModule($module, DrupalStyle $io, $message) { $io->info($message); $module = $this->extensionManager->getModule($module); foreach ($this->configExport as $fileName => $config) { $yamlConfig = Yaml::encode($config['data']); if ($config['optional']) { $configDirectory = $module->getConfigOptionalDirectory(false); } else { $configDirectory = $module->getConfigInstallDirectory(false); } $configFile = sprintf('%s/%s.yml', $configDirectory, $fileName); $io->info('- ' . $configFile); // Create directory if doesn't exist if (!file_exists($configDirectory)) { mkdir($configDirectory, 0755, true); } file_put_contents($configFile, $yamlConfig); } }
/** * @param $module * @param \Drupal\Console\Style\DrupalStyle $io */ protected function exportConfig($module, \Drupal\Console\Style\DrupalStyle $io, $message) { $dumper = new Dumper(); $io->info($message); foreach ($this->configExport as $fileName => $config) { $yamlConfig = $dumper->dump($config['data'], 10); if ($config['optional']) { $configDirectory = $this->getSite()->getModuleConfigOptionalDirectory($module, false); } else { $configDirectory = $this->getSite()->getModuleConfigInstallDirectory($module, false); } $configFile = sprintf('%s/%s.yml', $configDirectory, $fileName); $io->info('- ' . $configFile); // Create directory if doesn't exist if (!file_exists($configDirectory)) { mkdir($configDirectory, 0755, true); } file_put_contents($configFile, $yamlConfig); } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $lock = $this->getDrupalService('lock'); try { $lock->release('cron'); $io->info($this->trans('commands.cron.release.messages.released')); } catch (Exception $e) { $io->error($e->getMessage()); } $this->get('chain_queue')->addCommand('cache:rebuild', ['cache' => 'all']); }
/** * {@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']); }