Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $cache = $input->getArgument('cache');
     if (!$cache) {
         $cacheKeys = array_keys($this->drupalApi->getCaches());
         $cache = $io->choiceNoList($this->trans('commands.cache.rebuild.questions.cache'), $cacheKeys, 'all');
         $input->setArgument('cache', $cache);
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $roles = $input->getOption('roles');
     $limit = $input->getOption('limit');
     $uids = $this->splitOption($input->getOption('uid'));
     $usernames = $this->splitOption($input->getOption('username'));
     $mails = $this->splitOption($input->getOption('mail'));
     $userStorage = $this->entityTypeManager->getStorage('user');
     $systemRoles = $this->drupalApi->getRoles();
     $query = $this->entityQuery->get('user');
     $query->condition('uid', 0, '>');
     $query->sort('uid');
     // uid as option
     if (is_array($uids) && $uids) {
         $group = $query->andConditionGroup()->condition('uid', $uids, 'IN');
         $query->condition($group);
     }
     // username as option
     if (is_array($usernames) && $usernames) {
         $group = $query->andConditionGroup()->condition('name', $usernames, 'IN');
         $query->condition($group);
     }
     // mail as option
     if (is_array($mails) && $mails) {
         $group = $query->andConditionGroup()->condition('mail', $mails, 'IN');
         $query->condition($group);
     }
     if ($roles) {
         $query->condition('roles', is_array($roles) ? $roles : [$roles], 'IN');
     }
     if ($limit) {
         $query->range(0, $limit);
     }
     $results = $query->execute();
     $users = $userStorage->loadMultiple($results);
     $tableHeader = [$this->trans('commands.user.debug.messages.user-id'), $this->trans('commands.user.debug.messages.username'), $this->trans('commands.user.debug.messages.roles'), $this->trans('commands.user.debug.messages.status')];
     $tableRows = [];
     foreach ($users as $userId => $user) {
         $userRoles = [];
         foreach ($user->getRoles() as $userRole) {
             $userRoles[] = $systemRoles[$userRole];
         }
         $status = $user->isActive() ? $this->trans('commands.common.status.enabled') : $this->trans('commands.common.status.disabled');
         $tableRows[] = [$userId, $user->getUsername(), implode(', ', $userRoles), $status];
     }
     $io->table($tableHeader, $tableRows);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $username = $input->getArgument('username');
     while (!$username) {
         $username = $io->askEmpty($this->trans('commands.user.create.questions.username'), null);
     }
     $input->setArgument('username', $username);
     $password = $input->getArgument('password');
     if (!$password) {
         $password = $io->askEmpty($this->trans('commands.user.create.questions.password'), null);
     }
     $input->setArgument('password', $password);
     $roles = $input->getOption('roles');
     if (!$roles) {
         $systemRoles = $this->drupalApi->getRoles(false, false, false);
         $roles = $io->choice($this->trans('commands.user.create.questions.roles'), array_values($systemRoles), null, true);
         $roles = array_map(function ($role) use($systemRoles) {
             return array_search($role, $systemRoles);
         }, $roles);
         $input->setOption('roles', $roles);
     }
     $email = $input->getOption('email');
     if (!$email) {
         $email = $io->askEmpty($this->trans('commands.user.create.questions.email'), null);
     }
     $input->setOption('email', $email);
     $status = $input->getOption('status');
     if (!$status) {
         $status = $io->choice($this->trans('commands.user.create.questions.status'), [0, 1], 1);
     }
     $input->setOption('status', $status);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $userId = $input->getOption('user-id');
     if (!$userId) {
         $userId = $io->askEmpty($this->trans('commands.user.delete.questions.user-id'), null);
         $input->setOption('user-id', $userId);
     }
     $roles = $input->getOption('roles');
     if (!$userId && !$roles) {
         $systemRoles = $this->drupalApi->getRoles(false, false, false);
         $roles = $io->choice($this->trans('commands.user.delete.questions.roles'), array_values($systemRoles), null, true);
         $roles = array_map(function ($role) use($systemRoles) {
             return array_search($role, $systemRoles);
         }, $roles);
         $input->setOption('roles', $roles);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $bundles = $this->drupalApi->getBundles();
     foreach ($bundles as $bundleType => $bundleName) {
         $key = sprintf($this->trans('commands.site.statistics.messages.node-type'), $bundleName);
         $statistics[$key] = $this->getNodeTypeCount($bundleType);
     }
     $statistics[$this->trans('commands.site.statistics.messages.comments')] = $this->getCommentCount();
     $statistics[$this->trans('commands.site.statistics.messages.vocabulary')] = $this->getTaxonomyVocabularyCount();
     $statistics[$this->trans('commands.site.statistics.messages.taxonomy-terms')] = $this->getTaxonomyTermCount();
     $statistics[$this->trans('commands.site.statistics.messages.files')] = $this->getFileCount();
     $statistics[$this->trans('commands.site.statistics.messages.users')] = $this->getUserCount();
     $statistics[$this->trans('commands.site.statistics.messages.views')] = $this->getViewCount();
     $statistics[$this->trans('commands.site.statistics.messages.modules-enabled')] = $this->getModuleCount(true);
     $statistics[$this->trans('commands.site.statistics.messages.modules-disabled')] = $this->getModuleCount(false);
     $statistics[$this->trans('commands.site.statistics.messages.themes-enabled')] = $this->getThemeCount(true);
     $statistics[$this->trans('commands.site.statistics.messages.themes-disabled')] = $this->getThemeCount(false);
     $this->statisticsList($io, $statistics);
 }
Exemplo n.º 6
0
 /**
  * {@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->drupalApi->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));
     }
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $vocabularies = $input->getArgument('vocabularies');
     $limit = $input->getOption('limit') ?: 25;
     $nameWords = $input->getOption('name-words') ?: 5;
     if (!$vocabularies) {
         $vocabularies = array_keys($this->drupalApi->getVocabularies());
     }
     $terms = $this->createTermData->create($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 0;
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $roles = $input->getArgument('roles');
     $limit = $input->getOption('limit') ?: 25;
     $password = $input->getOption('password');
     $timeRange = $input->getOption('time-range') ?: 31536000;
     if (!$roles) {
         $roles = $this->drupalApi->getRoles();
     }
     $users = $this->createUserData->create($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));
     }
     return 0;
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $modules = $input->getArgument('module');
     $latest = $input->getOption('latest');
     $path = $input->getOption('path');
     $composer = $input->getOption('composer');
     $unstable = true;
     if ($composer) {
         foreach ($modules as $module) {
             if (!$latest) {
                 $versions = $this->drupalApi->getPackagistModuleReleases($module, 10, $unstable);
                 if (!$versions) {
                     $io->error(sprintf($this->trans('commands.module.download.messages.no-releases'), $module));
                     return 1;
                 } else {
                     $version = $io->choice($this->trans('commands.site.new.questions.composer-release'), $versions);
                 }
             } else {
                 $versions = $this->drupalApi->getPackagistModuleReleases($module, 10, $unstable);
                 if (!$versions) {
                     $io->error(sprintf($this->trans('commands.module.download.messages.no-releases'), $module));
                     return 1;
                 } else {
                     $version = current($this->drupalApi->getPackagistModuleReleases($module, 1, $unstable));
                 }
             }
             // Register composer repository
             $command = "composer config repositories.drupal composer https://packagist.drupal-composer.org";
             $this->shellProcess->exec($command, $this->root);
             $command = sprintf('composer require drupal/%s:%s --prefer-dist --optimize-autoloader --sort-packages --update-no-dev', $module, $version);
             if ($this->shellProcess->exec($command, $this->root)) {
                 $io->success(sprintf($this->trans('commands.module.download.messages.composer'), $module));
             }
         }
     } else {
         $this->downloadModules($io, $modules, $latest, $path);
     }
     return true;
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $contentTypes = $input->getArgument('content-types');
     $limit = $input->getOption('limit') ?: 25;
     $titleWords = $input->getOption('title-words') ?: 5;
     $timeRange = $input->getOption('time-range') ?: 31536000;
     $available_types = array_keys($this->drupalApi->getBundles());
     foreach ($contentTypes as $type) {
         if (!in_array($type, $available_types)) {
             throw new \Exception('Invalid content type name given.');
         }
     }
     if (!$contentTypes) {
         $contentTypes = $available_types;
     }
     $nodes = $this->createNodeData->create($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 0;
 }