Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Generate / ProfileCommand.php
index f04a3ea0977a550f7cbdf775fd6ce7793c9d66c3..5dfbe1509205d726d09cd4ec62c748752f164fa3 100644 (file)
@@ -18,8 +18,6 @@ use Drupal\Console\Core\Command\Shared\CommandTrait;
 use Drupal\Console\Extension\Manager;
 use Drupal\Console\Core\Utils\StringConverter;
 use Drupal\Console\Utils\Validator;
-use Drupal\Console\Utils\Site;
-use GuzzleHttp\Client;
 
 /**
  * Class ProfileCommand
@@ -33,13 +31,13 @@ class ProfileCommand extends Command
     use CommandTrait;
 
     /**
- * @var Manager
-*/
    * @var Manager
+     */
     protected $extensionManager;
 
     /**
- * @var ProfileGenerator
-*/
    * @var ProfileGenerator
+     */
     protected $generator;
 
     /**
@@ -48,19 +46,9 @@ class ProfileCommand extends Command
     protected $stringConverter;
 
     /**
- * @var Validator
-*/
-    protected $validator;
-
-    /**
-     * @var Site
+     * @var Validator
      */
-    protected $site;
-
-    /**
-     * @var Client
-     */
-    protected $httpClient;
+    protected $validator;
 
     /**
      * ProfileCommand constructor.
@@ -70,25 +58,19 @@ class ProfileCommand extends Command
      * @param StringConverter  $stringConverter
      * @param Validator        $validator
      * @param $appRoot
-     * @param Site             $site
-     * @param Client           $httpClient
      */
     public function __construct(
         Manager $extensionManager,
         ProfileGenerator $generator,
         StringConverter $stringConverter,
         Validator $validator,
-        $appRoot,
-        Site $site,
-        Client $httpClient
+        $appRoot
     ) {
         $this->extensionManager = $extensionManager;
         $this->generator = $generator;
         $this->stringConverter = $stringConverter;
         $this->validator = $validator;
         $this->appRoot = $appRoot;
-        $this->site = $site;
-        $this->httpClient = $httpClient;
         parent::__construct();
     }
 
@@ -103,37 +85,45 @@ class ProfileCommand extends Command
             ->setHelp($this->trans('commands.generate.profile.help'))
             ->addOption(
                 'profile',
-                '',
+                null,
                 InputOption::VALUE_REQUIRED,
                 $this->trans('commands.generate.profile.options.profile')
             )
             ->addOption(
                 'machine-name',
-                '',
+                null,
                 InputOption::VALUE_REQUIRED,
                 $this->trans('commands.generate.profile.options.machine-name')
             )
             ->addOption(
                 'description',
-                '',
+                null,
                 InputOption::VALUE_OPTIONAL,
                 $this->trans('commands.generate.profile.options.description')
             )
             ->addOption(
                 'core',
-                '',
+                null,
                 InputOption::VALUE_OPTIONAL,
                 $this->trans('commands.generate.profile.options.core')
             )
             ->addOption(
                 'dependencies',
-                false,
+                null,
                 InputOption::VALUE_OPTIONAL,
-                $this->trans('commands.generate.profile.options.dependencies')
+                $this->trans('commands.generate.profile.options.dependencies'),
+                ''
+            )
+            ->addOption(
+                'themes',
+                null,
+                InputOption::VALUE_OPTIONAL,
+                $this->trans('commands.generate.profile.options.themes'),
+                ''
             )
             ->addOption(
                 'distribution',
-                false,
+                null,
                 InputOption::VALUE_OPTIONAL,
                 $this->trans('commands.generate.profile.options.distribution')
             );
@@ -147,31 +137,18 @@ class ProfileCommand extends Command
         $io = new DrupalStyle($input, $output);
 
         if (!$this->confirmGeneration($io)) {
-            return;
+            return 1;
         }
 
         $profile = $this->validator->validateModuleName($input->getOption('profile'));
         $machine_name = $this->validator->validateMachineName($input->getOption('machine-name'));
         $description = $input->getOption('description');
         $core = $input->getOption('core');
+        $dependencies = $this->validator->validateExtensions($input->getOption('dependencies'), 'module', $io);
+        $themes = $this->validator->validateExtensions($input->getOption('themes'), 'theme', $io);
         $distribution = $input->getOption('distribution');
         $profile_path = $this->appRoot . '/profiles';
 
-        // Check if all module dependencies are available.
-        $dependencies = $this->validator->validateModuleDependencies($input->getOption('dependencies'));
-        if ($dependencies) {
-            $checked_dependencies = $this->checkDependencies($dependencies['success']);
-            if (!empty($checked_dependencies['no_modules'])) {
-                $io->info(
-                    sprintf(
-                        $this->trans('commands.generate.profile.warnings.module-unavailable'),
-                        implode(', ', $checked_dependencies['no_modules'])
-                    )
-                );
-            }
-            $dependencies = $dependencies['success'];
-        }
-
         $this->generator->generate(
             $profile,
             $machine_name,
@@ -179,47 +156,11 @@ class ProfileCommand extends Command
             $description,
             $core,
             $dependencies,
+            $themes,
             $distribution
         );
     }
 
-    /**
-     * @param  array $dependencies
-     * @return array
-     */
-    private function checkDependencies(array $dependencies)
-    {
-        $this->site->loadLegacyFile('/core/modules/system/system.module');
-        $local_modules = [];
-
-        $modules = system_rebuild_module_data();
-        foreach ($modules as $module_id => $module) {
-            array_push($local_modules, basename($module->subpath));
-        }
-
-        $checked_dependencies = [
-            'local_modules' => [],
-            'drupal_modules' => [],
-            'no_modules' => [],
-        ];
-
-        foreach ($dependencies as $module) {
-            if (in_array($module, $local_modules)) {
-                $checked_dependencies['local_modules'][] = $module;
-            } else {
-                $response = $this->httpClient->head('https://www.drupal.org/project/' . $module);
-                $header_link = explode(';', $response->getHeader('link'));
-                if (empty($header_link[0])) {
-                    $checked_dependencies['no_modules'][] = $module;
-                } else {
-                    $checked_dependencies['drupal_modules'][] = $module;
-                }
-            }
-        }
-
-        return $checked_dependencies;
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -237,7 +178,7 @@ class ProfileCommand extends Command
         } catch (\Exception $error) {
             $io->error($error->getMessage());
 
-            return;
+            return 1;
         }
 
         if (!$profile) {
@@ -256,7 +197,7 @@ class ProfileCommand extends Command
         } catch (\Exception $error) {
             $io->error($error->getMessage());
 
-            return;
+            return 1;
         }
 
         if (!$machine_name) {