/** * {@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); $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)); }
/** * {@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; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $uid = $input->getArgument('user'); $user = User::load($uid); if (!$user) { $io->error(sprintf($this->trans('commands.user.password.reset.errors.invalid-user'), $uid)); return; } $password = $input->getArgument('password'); if (!$password) { $io->error(sprintf($this->trans('commands.user.password.reset.errors.empty-password'), $uid)); return; } try { $user->setPassword($password); $user->save(); // Clear all failed login attempts after setup new password to user account. $this->getChain()->addCommand('user:login:clear:attempts', ['uid' => $uid]); } catch (\Exception $e) { $io->error($e->getMessage()); return; } $io->success(sprintf($this->trans('commands.user.password.reset.messages.reset-successful'), $uid)); }
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); $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) { $this->setComposerRepositories("default"); $command = 'composer update ' . $modules . ' --optimize-autoloader --prefer-dist --no-dev --root-reqs '; if ($simulate) { $command .= " --dry-run"; } $shellProcess = $this->get('shell_process'); if ($shellProcess->exec($command)) { $io->success(sprintf($this->trans('commands.module.update.messages.composer'), trim($modules))); } } return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $application = $this->getApplication(); $manifest = $input->getOption('manifest') ?: 'http://drupalconsole.com/manifest.json'; $currentVersion = $input->getOption('current-version') ?: $application->getVersion(); $major = $input->getOption('major'); if (!extension_loaded('Phar') || !\Phar::running(false)) { $io->error($this->trans('commands.self-update.messages.not-phar')); $io->block($this->trans('commands.self-update.messages.instructions')); return 1; } $io->info(sprintf($this->trans('commands.self-update.messages.check'), $currentVersion)); $updater = new Updater(null, false); $strategy = new ManifestStrategy($currentVersion, $major, $manifest); $updater->setStrategyObject($strategy); if (!$updater->hasUpdate()) { $io->info(sprintf($this->trans('commands.self-update.messages.current-version'), $currentVersion)); return 0; } $oldVersion = $updater->getOldVersion(); $newVersion = $updater->getNewVersion(); if (!$io->confirm(sprintf($this->trans('commands.self-update.questions.update'), $oldVersion, $newVersion), true)) { return 1; } $io->comment(sprintf($this->trans('commands.self-update.messages.update'), $newVersion)); $updater->update(); $io->success(sprintf($this->trans('commands.self-update.messages.success'), $oldVersion, $newVersion)); // Errors appear if new classes are instantiated after this stage // (namely, Symfony's ConsoleTerminateEvent). This suggests PHP // can't read files properly from the overwritten Phar, or perhaps it's // because the autoloader's name has changed. We avoid the problem by // terminating now. exit; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $uid = $input->getArgument('user'); $user = User::load($uid); if (!$user) { $io->error(sprintf($this->trans('commands.user.password.reset.errors.invalid-user'), $uid)); return 1; } $password = $input->getArgument('password'); if (!$password) { $io->error(sprintf($this->trans('commands.user.password.reset.errors.empty-password'), $uid)); return 1; } try { $user->setPassword($password); $user->save(); $schema = $this->database->schema(); $flood = $schema->findTables('flood'); if ($flood) { $this - $this->chainQueue->addCommand('user:login:clear:attempts', ['uid' => $uid]); } } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $io->success(sprintf($this->trans('commands.user.password.reset.messages.reset-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()); } }
/** * {@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) { $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 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()); } }
/** * @param \Drupal\Console\Style\DrupalStyle $io * @param $project * @param $version * @param $type * @return string */ public function downloadProject(DrupalStyle $io, $project, $version, $type) { $commandKey = str_replace(':', '.', $this->getName()); $io->comment(sprintf($this->trans('commands.' . $commandKey . '.messages.downloading'), $project, $version)); try { $destination = $this->getDrupalApi()->downloadProjectRelease($project, $version); $drupal = $this->getDrupalHelper(); $projectPath = sprintf('%s/%s', $drupal->isValidInstance() ? $drupal->getRoot() : getcwd(), $this->getExtractPath($type)); if (!file_exists($projectPath)) { if (!mkdir($projectPath, 0777, true)) { $io->error($this->trans('commands.' . $commandKey . '.messages.error-creating-folder') . ': ' . $projectPath); return null; } } $zippy = Zippy::load(); $archive = $zippy->open($destination); $archive->extract($projectPath); unlink($destination); if ($type != 'core') { $io->success(sprintf($this->trans('commands.' . $commandKey . '.messages.downloaded'), $project, $version, sprintf('%s/%s', $projectPath, $project))); } } catch (\Exception $e) { $io->error($e->getMessage()); return null; } return $projectPath; }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $io->newLine(); $io->comment($this->trans('commands.router.rebuild.messages.rebuilding')); $this->routerBuilder->rebuild(); $io->success($this->trans('commands.router.rebuild.messages.completed')); }
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; }
protected function execute(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $output->newLine(); $output->writeln(sprintf('<comment>%s</comment>', $this->trans('commands.router.rebuild.messages.rebuilding'))); $container = $this->getContainer(); $router_builder = $container->get('router.builder'); $router_builder->rebuild(); $output->success($this->trans('commands.router.rebuild.messages.completed')); }
/** * {@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); $uid = $input->getArgument('user-id'); $user = $this->entityTypeManager->getStorage('user')->load($uid); if (!$user) { $io->error(sprintf($this->trans('commands.user.login.url.errors.invalid-user'), $uid)); return 1; } $url = user_pass_reset_url($user); $io->success(sprintf($this->trans('commands.user.login.url.messages.url'), $user->getUsername(), $url)); }
/** * {@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); $vocabularies = $input->getArgument('vocabularies'); $limit = $input->getOption('limit') ?: 10; $nameWords = $input->getOption('name-words') ?: 5; $createTerms = $this->getDrupalApi()->getCreateTerms(); $terms = $createTerms->createTerm($vocabularies, $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; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $nodeId = $input->getArgument('node-id') ?: 1; $limit = $input->getOption('limit') ?: 25; $titleWords = $input->getOption('title-words') ?: 5; $timeRange = $input->getOption('time-range') ?: 31536000; $comments = $this->createCommentData->create($nodeId, $limit, $titleWords, $timeRange); $tableHeader = [$this->trans('commands.create.comments.messages.node-id'), $this->trans('commands.create.comments.messages.comment-id'), $this->trans('commands.create.comments.messages.title'), $this->trans('commands.create.comments.messages.created')]; $io->table($tableHeader, $comments['success']); $io->success(sprintf($this->trans('commands.create.comments.messages.created-comments'), $limit)); return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $entityDefinitionID = $input->getArgument('entity-definition-id'); $entityID = $input->getArgument('entity-id'); try { $this->entityTypeManager->getStorage($entityDefinitionID)->load($entityID)->delete(); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $io->success(sprintf($this->trans('commands.entity.delete.messages.deleted'), $entityDefinitionID, $entityID)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $createNodes = $this->getDrupalApi()->getCreateNodes(); $contentTypes = $input->getArgument('content-types'); $limit = $input->getOption('limit') ?: 10; $titleWords = $input->getOption('title-words') ?: 5; $timeRange = $input->getOption('time-range') ?: 'N'; $nodes = $createNodes->createNode($contentTypes, $limit, $titleWords, $timeRange); $tableHeader = [$this->trans('commands.create.nodes.messages.node-id'), $this->trans('commands.create.nodes.messages.content-type'), $this->trans('commands.create.nodes.messages.title'), $this->trans('commands.create.nodes.messages.created')]; $io->table($tableHeader, $nodes['success']); $io->success(sprintf($this->trans('commands.create.nodes.messages.created-nodes'), $limit)); return; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $operation = $input->getArgument('operation'); $user = $input->getArgument('user'); $role = $input->getArgument('role'); $systemRoles = $this->getApplication()->getDrupalApi()->getRoles(); if (is_numeric($user)) { $userObject = user_load($user); } else { $userObject = user_load_by_name($user); } if (!is_object($userObject)) { if (!filter_var($user, FILTER_VALIDATE_EMAIL) === false) { $userObject = user_load_by_mail($user); } } if (!is_object($userObject)) { $io->error(sprintf($this->trans('commands.user.role.messages.no-user-found'), $user)); return 1; } if (!array_key_exists($role, $systemRoles)) { $io->error(sprintf($this->trans('commands.user.role.messages.no-role-found'), $role)); return 1; } if ("add" == $operation) { $userObject->addRole($role); $userObject->save(); $io->success(sprintf($this->trans('commands.user.role.messages.add-success'), $userObject->name->value . " (" . $userObject->mail->value . ") ", $role)); } if ("remove" == $operation) { $userObject->removeRole($role); $userObject->save(); $io->success(sprintf($this->trans('commands.user.role.messages.remove-success'), $userObject->name->value . " (" . $userObject->mail->value . ") ", $role)); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $roles = $input->getArgument('roles'); $limit = $input->getOption('limit') ?: 10; $password = $input->getOption('password'); $timeRange = $input->getOption('time-range') ?: 'N'; $createUsers = $this->getDrupalApi()->getCreateUsers(); $users = $createUsers->createUser($roles, $limit, $password, $timeRange); $tableHeader = [$this->trans('commands.create.users.messages.user-id'), $this->trans('commands.create.users.messages.username'), $this->trans('commands.create.users.messages.roles'), $this->trans('commands.create.users.messages.created')]; if ($users['success']) { $io->table($tableHeader, $users['success']); $io->success(sprintf($this->trans('commands.create.users.messages.created-users'), $limit)); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $limit = $input->getOption('limit') ?: 25; $nameWords = $input->getOption('name-words') ?: 5; $vocabularies = $this->vocabularyData->create($limit, $nameWords); $tableHeader = [$this->trans('commands.create.vocabularies.messages.vocabulary-id'), $this->trans('commands.create.vocabularies.messages.name')]; if (isset($vocabularies['success'])) { $io->table($tableHeader, $vocabularies['success']); $io->success(sprintf($this->trans('commands.create.vocabularies.messages.created-terms'), $limit)); } else { $io->error(sprintf($this->trans('commands.create.vocabularies.messages.error'), $vocabularies['error'][0]['error'])); } return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $bin = $input->getArgument('bin'); if (!$bin) { $io->error($this->trans('commands.exec.messages.missing-bin')); return 1; } $shellProcess = $this->get('shell_process'); if ($shellProcess->exec($bin, true)) { $io->success(sprintf($this->trans('commands.exec.messages.success'), $bin)); } else { $io->error(sprintf($this->trans('commands.exec.messages.invalid-bin'))); return 1; } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $uid = $input->getArgument('user-id'); $user = $this->getEntityManager()->getStorage('user')->load($uid); if (!$user) { $text = $this->trans('commands.user.login.url.errors.invalid-user'); $text = SafeMarkup::format($text, ['@uid' => $uid]); $io->error($text); return; } $url = user_pass_reset_url($user); $text = $this->trans('commands.user.login.url.messages.url'); $text = SafeMarkup::format($text, ['@name' => $user->getUsername(), '@url' => $url]); $io->success($text); }
/** * {@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()); } }
private function configImport(DrupalStyle $io, StorageComparer $storage_comparer) { $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::lock(), \Drupal::service('config.typed'), \Drupal::moduleHandler(), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation')); if ($config_importer->alreadyImporting()) { $io->success($this->trans('commands.config.import.messages.already-imported')); } else { try { $config_importer->import(); $io->info($this->trans('commands.config.import.messages.importing')); } catch (ConfigImporterException $e) { $message = 'The import failed due for the following reasons:' . "\n"; $message .= implode("\n", $config_importer->getErrors()); $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $message)); } catch (\Exception $e) { $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage())); } } }