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')];
     $locale = $this->extensionManager->getModule('locale');
     $this->site->loadLegacyFile($locale->getPath(true) . '/locale.compare.inc');
     $languages = locale_translatable_language_list();
     $status = locale_translation_get_status();
     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');
         }
     }
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $this->site->loadLegacyFile('/core/modules/system/system.module');
     $status = strtolower($input->getOption('status'));
     $type = strtolower($input->getOption('type'));
     $modules = strtolower($input->getArgument('module'));
     if ($modules) {
         $config = $this->configurationManager->getConfiguration();
         $repo = $config->get('application.composer.repositories.default');
         foreach ($modules as $module) {
             $url = sprintf('%s/packages/drupal/%s.json', $config->get('application.composer.packages.default'), $module);
             try {
                 $data = $this->httpClient->getUrlAsJson($repo . $url);
             } catch (\Exception $e) {
                 $io->error(sprintf($this->trans('commands.module.debug.messages.no-results'), $module));
                 return 1;
             }
             $tableHeader = ['<info>' . $data->package->name . '</info>'];
             $tableRows = [];
             $tableRows[] = [$data->package->description];
             $tableRows[] = ['<comment>' . $this->trans('commands.module.debug.messages.total-downloads') . '</comment>', $data->package->downloads->total];
             $tableRows[] = ['<comment>' . $this->trans('commands.module.debug.messages.total-monthly') . '</comment>', $data->package->downloads->monthly];
             $tableRows[] = ['<comment>' . $this->trans('commands.module.debug.messages.total-daily') . '</comment>', $data->package->downloads->daily];
             $io->table($tableHeader, $tableRows, 'compact');
         }
         return 0;
     }
     if ($status == 'installed') {
         $status = 1;
     } elseif ($status == 'uninstalled') {
         $status = 0;
     } else {
         $status = -1;
     }
     if ($type == 'core') {
         $type = 'core';
     } elseif ($type == 'no-core') {
         $type = '';
     } else {
         $type = null;
     }
     $tableHeader = [$this->trans('commands.module.debug.messages.id'), $this->trans('commands.module.debug.messages.name'), $this->trans('commands.module.debug.messages.package'), $this->trans('commands.module.debug.messages.version'), $this->trans('commands.module.debug.messages.schema-version'), $this->trans('commands.module.debug.messages.status'), $this->trans('commands.module.debug.messages.origin')];
     $tableRows = [];
     $modules = system_rebuild_module_data();
     foreach ($modules as $module_id => $module) {
         if ($status >= 0 && $status != $module->status) {
             continue;
         }
         if ($type !== null && $type !== $module->origin) {
             continue;
         }
         $module_status = $module->status ? $this->trans('commands.module.debug.messages.installed') : $this->trans('commands.module.debug.messages.uninstalled');
         $module_origin = $module->origin ? $module->origin : 'no core';
         $schema_version = drupal_get_installed_schema_version($module_id) != -1 ? drupal_get_installed_schema_version($module_id) : '';
         $tableRows[] = [$module_id, $module->info['name'], $module->info['package'], $module->info['version'], $schema_version, $module_status, $module_origin];
     }
     $io->table($tableHeader, $tableRows, 'compact');
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $composer = $input->getOption('composer');
     $module = $input->getArgument('module');
     $this->site->loadLegacyFile('/core/modules/system/system.module');
     $coreExtension = $this->configFactory->getEditable('core.extension');
     // 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('", "', $moduleList), implode(', ', $dependencies)));
             return 1;
         }
     }
     try {
         $this->moduleInstaller->uninstall($moduleList);
         $io->info(sprintf($this->trans('commands.module.uninstall.messages.success'), implode(', ', $moduleList)));
         $io->comment(sprintf($this->trans('commands.module.uninstall.messages.composer-success'), implode(', ', $moduleList), false));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
 }
Example #4
0
 /**
  * @param  array $dependencies
  * @return array
  */
 private function checkDependencies(array $dependencies)
 {
     $this->site->loadLegacyFile('/core/modules/system/system.module');
     $client = $this->getHttpClient();
     $localModules = array();
     $modules = system_rebuild_module_data();
     foreach ($modules as $module_id => $module) {
         array_push($localModules, basename($module->subpath));
     }
     $checkDependencies = ['local_modules' => [], 'drupal_modules' => [], 'no_modules' => []];
     foreach ($dependencies as $module) {
         if (in_array($module, $localModules)) {
             $checkDependencies['local_modules'][] = $module;
         } else {
             $response = $client->head('https://www.drupal.org/project/' . $module);
             $header_link = explode(';', $response->getHeader('link'));
             if (empty($header_link[0])) {
                 $checkDependencies['no_modules'][] = $module;
             } else {
                 $checkDependencies['drupal_modules'][] = $module;
             }
         }
     }
     return $checkDependencies;
 }
 /**
  * @param \Drupal\Console\Style\DrupalStyle $io
  * @param $updates
  */
 private function runUpdates(DrupalStyle $io, $updates)
 {
     foreach ($updates as $module_name => $module_updates) {
         $modulePath = $this->getApplication()->getSite()->getModulePath($this->module);
         $this->site->loadLegacyFile($modulePath . '/' . $this->module . '.install', false);
         foreach ($module_updates['pending'] as $update_number => $update) {
             if ($this->module != 'all' && $this->update_n !== null && $this->update_n != $update_number) {
                 continue;
             }
             if ($this->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 {
                     $this->moduleHandler->invoke($module_name, 'update_' . $update_index);
                 } catch (\Exception $e) {
                     watchdog_exception('update', $e);
                     $io->error($e->getMessage());
                 }
                 drupal_set_installed_schema_version($module_name, $update_index);
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $module = $input->getArgument('module');
     $latest = $input->getOption('latest');
     $composer = $input->getOption('composer');
     $this->site->loadLegacyFile('/core/includes/bootstrap.inc');
     // check module's requirements
     $this->moduleRequirement($module);
     if ($composer) {
         foreach ($module as $moduleItem) {
             $command = sprintf('composer show drupal/%s ', $moduleItem);
             $shellProcess = $this->get('shell_process');
             if ($shellProcess->exec($command)) {
                 $io->info(sprintf('Module %s was downloaded with Composer.', $moduleItem));
             } else {
                 $io->error(sprintf('Module %s seems not to be installed with Composer. Halting.', $moduleItem));
                 return 0;
             }
         }
         $unInstalledModules = $module;
     } else {
         $resultList = $this->downloadModules($io, $module, $latest);
         $invalidModules = $resultList['invalid'];
         $unInstalledModules = $resultList['uninstalled'];
         if ($invalidModules) {
             foreach ($invalidModules as $invalidModule) {
                 unset($module[array_search($invalidModule, $module)]);
                 $io->error(sprintf('Invalid module name: %s', $invalidModule));
             }
         }
         if (!$unInstalledModules) {
             $io->warning($this->trans('commands.module.install.messages.nothing'));
             return 0;
         }
     }
     try {
         $io->comment(sprintf($this->trans('commands.module.install.messages.installing'), implode(', ', $unInstalledModules)));
         drupal_static_reset('system_rebuild_module_data');
         $this->moduleInstaller->install($unInstalledModules, true);
         $io->success(sprintf($this->trans('commands.module.install.messages.success'), implode(', ', $unInstalledModules)));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
 }
Example #7
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $this->site->loadLegacyFile('/core/includes/update.inc');
     $this->site->loadLegacyFile('/core/includes/schema.inc');
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($io);
         $input->setOption('module', $module);
     }
     $description = $input->getOption('description');
     if (!$description) {
         $description = $io->ask($this->trans('commands.generate.module.questions.description'), 'My Awesome Module');
     }
     $input->setOption('description', $description);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $cache = $input->getArgument('cache');
     $this->site->loadLegacyFile('/core/includes/utility.inc');
     if ($cache && !$this->drupalApi->isValidCache($cache)) {
         $io->error(sprintf($this->trans('commands.cache.rebuild.messages.invalid_cache'), $cache));
         return 1;
     }
     $io->newLine();
     $io->comment($this->trans('commands.cache.rebuild.messages.rebuild'));
     if ($cache === 'all') {
         drupal_rebuild($this->classLoader, $this->requestStack->getCurrentRequest());
     } else {
         $caches = $this->drupalApi->getCaches();
         $caches[$cache]->deleteAll();
     }
     $io->success($this->trans('commands.cache.rebuild.messages.completed'));
     return 0;
 }
Example #9
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $this->site->loadLegacyFile('/core/includes/update.inc');
     $this->site->loadLegacyFile('/core/includes/install.inc');
     drupal_load_updates();
     update_fix_compatibility();
     $requirements = update_check_requirements();
     $severity = drupal_requirements_severity($requirements);
     $updates = update_get_update_list();
     $io->newLine();
     if ($severity == REQUIREMENT_ERROR || $severity == REQUIREMENT_WARNING) {
         $this->populateRequirements($io, $requirements);
     } elseif (empty($updates)) {
         $io->info($this->trans('commands.update.debug.messages.no-updates'));
     } else {
         $this->populateUpdate($io, $updates);
         $this->populatePostUpdate($io);
     }
 }
 protected function getLastUpdate($module)
 {
     $this->site->loadLegacyFile('/core/includes/update.inc');
     $this->site->loadLegacyFile('/core/includes/schema.inc');
     $updates = update_get_update_list();
     if (empty($updates[$module]['pending'])) {
         $lastUpdateSchema = drupal_get_schema_versions($module);
     } else {
         $lastUpdateSchema = reset(array_keys($updates[$module]['pending'], max($updates[$module]['pending'])));
     }
     return $lastUpdateSchema;
 }
Example #11
0
 /**
  * @param string $type
  * @return \Drupal\Core\Extension\Extension[]
  */
 private function discoverExtensions($type)
 {
     if ($type === 'module') {
         $this->site->loadLegacyFile('/core/modules/system/system.module');
         system_rebuild_module_data();
     }
     /*
      * @see Remove DrupalExtensionDiscovery subclass once
      * https://www.drupal.org/node/2503927 is fixed.
      */
     $discovery = new Discovery($this->appRoot);
     $discovery->reset();
     return $discovery->scan($type);
 }
Example #12
0
 public function validateModuleFunctionExist($moduleName, $function, $moduleFile = null)
 {
     //Load module file to prevent issue of missing functions used in update
     $module = $this->getModule($moduleName);
     $modulePath = $module->getPath();
     if ($moduleFile) {
         $this->site->loadLegacyFile($modulePath . '/' . $moduleFile);
     } else {
         $this->site->loadLegacyFile($modulePath . '/' . $module->getName() . '.module');
     }
     if (function_exists($function)) {
         return true;
     }
     return false;
 }
Example #13
0
 protected function runInstaller(DrupalStyle $output, InputInterface $input, $database)
 {
     $this->site->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->info($this->trans('commands.site.install.messages.installing'));
     try {
         $autoload = $this->site->getAutoload();
         install_drupal($autoload, $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'));
 }