コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $config_name = $input->getArgument('configset_name');
     $helper = new ConfigHelper();
     $configsets = $helper->getAllConfigSets();
     // Ensure we have a 'current' config
     $current = $helper->getCurrentConfigSetParsed();
     if (empty($current)) {
         $output->writeln("<error>Unable to save an empty configuration set.</error>");
         $output->writeln("<info>Use the <option=bold>'drupalci config:set [variablename]=[value]'</option=bold> command to set some configuration defaults before attempting to save a new config set.</info>");
         return;
     }
     // Check if configset name already exists
     if (in_array($config_name, array_keys($configsets))) {
         // Prompt the user that this will overwrite the existing configuration setting file
         $qhelper = $this->getHelper('question');
         $output->writeln("<error>The <option=bold>{$config_name}</option=bold> config set already exists.</error>");
         $output->writeln("<info>Continuing will overwrite the existing file with the current configuration values.</info>");
         $message = "<question>Are you sure you wish to continue? (yes/no)</question> ";
         $question = new ConfirmationQuestion($message, false);
         if (!$qhelper->ask($input, $output, $question)) {
             $output->writeln("<comment>Action cancelled.</comment>");
             return;
         }
     }
     $helper->saveCurrentConfig($config_name);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     // Retrieve passed argument
     $arguments = $input->getArgument('variable');
     $helper = new ConfigHelper();
     // Retrieve current config
     $config = $helper->getCurrentConfigSetParsed();
     foreach ($arguments as $argument) {
         // Check that the variable exists
         if (!array_key_exists($argument, $config)) {
             $output->writeln("<info>The <option=bold>{$argument}</option=bold> variable does not exist.  No action taken.");
         } else {
             // Prompt the user that this will overwrite the existing setting
             $qhelper = $this->getHelper('question');
             $output->writeln("<info>This will remove the <option=bold>{$argument}</option=bold> variable from your current configuration set.</info>");
             $message = "<question>Are you sure you wish to continue? (yes/no)</question> ";
             $question = new ConfirmationQuestion($message, false);
             if (!$qhelper->ask($input, $output, $question)) {
                 $output->writeln("<comment>Action cancelled.</comment>");
                 return;
             }
             $helper->clearConfigVariable($argument);
             $output->writeln("<comment>The <info>{$argument}</info> variable has been deleted from the current config set.</comment>");
         }
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     // Retrieve passed argument
     $arguments = $input->getArgument('assignment');
     $helper = new ConfigHelper();
     // Retrieve current config
     $config = $helper->getCurrentConfigSetParsed();
     foreach ($arguments as $argument) {
         // Parse key => value
         $parsed = explode('=', $argument);
         if (count($parsed) != 2) {
             $output->writeln("<error>Unable to parse argument.</error>");
             $output->writeln("<comment>Please provide both a variable name and value formatted as <options=bold>variable_name=variable_value</options=bold></comment>");
             return;
         }
         // TODO: Validate key against a list of allowed variables
         $key = trim($parsed[0]);
         $value = trim($parsed[1]);
         // Check if replacing an existing environment variable
         if ($existing = getenv($key)) {
             // Prompt the user that an existing environment variable exists and can not be overwritten
             $output->writeln("<error>The <option=bold>{$key}</option=bold> setting has been set via an environment variable and can not be set via the console.</error>");
             $output->writeln("<comment>To override this value, provide it on the command line as part of the drupalci invocation.");
             $output->writeln("<comment>Example: </comment> {$key}={$value} ./drupalci [command]");
         } elseif (in_array($key, array_keys($config))) {
             // Prompt the user that this will overwrite the existing setting
             $qhelper = $this->getHelper('question');
             $output->writeln("<info>The <option=bold>{$key}</option=bold> variable already exists.</info>");
             $message = "<question>Are you sure you wish to override it? (yes/no)</question> ";
             $question = new ConfirmationQuestion($message, false);
             if (!$qhelper->ask($input, $output, $question)) {
                 $output->writeln("<comment>Action cancelled.</comment>");
                 return;
             }
             $helper->setConfigVariable($key, $value);
         } else {
             // Set the var and provide feedback
             $output->writeln("<info>Setting the value of the <option=bold>{$key}</option=bold> variable to <option=bold>{$value}</option=bold>");
             $helper->setConfigVariable($key, $value);
         }
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function run(JobInterface $job, $data = NULL)
 {
     // Get and parse test definitions
     // DrupalCI jobs are controlled via a hierarchy of configuration settings, which define the behaviour of the platform while running DrupalCI jobs.  This hierarchy is defined as follows, which each level overriding the previous:
     // 1. Out-of-the-box DrupalCI defaults
     // 2. Local overrides defined in ~/.drupalci/config
     // 3. 'DCI_' namespaced environment variable overrides
     // 4. Test-specific overrides passed inside a DrupalCI test definition (e.g. .drupalci.yml)
     // 5. Custom overrides located inside a test definition defined via the $source variable when calling this function.
     $confighelper = new ConfigHelper();
     // Load job defaults
     $platform_args = $job->getPlatformDefaults();
     $default_args = $job->getDefaultArguments();
     if (!empty($default_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables for this job type.</comment>");
     }
     // Load DrupalCI local config overrides
     $local_args = $confighelper->getCurrentConfigSetParsed();
     if (!empty($local_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables from DrupalCI local config overrides.</comment>");
     }
     // Load "DCI_ namespaced" environment variable overrides
     $environment_args = $confighelper->getCurrentEnvVars();
     if (!empty($environment_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables from namespaced environment variable overrides.</comment>");
     }
     // Load command line arguments
     // TODO: Routine for loading command line arguments.
     // TODO: How do we pull arguments off the drupalci command, when in a job class?
     // $cli_args = $somehelper->loadCLIargs();
     $cli_args = array();
     if (!empty($cli_args)) {
         $job->getOutput()->writeln("<comment>Loading test parameters from command line arguments.</comment>");
     }
     // Create temporary config array to use in determining the definition file source
     $config = $cli_args + $environment_args + $local_args + $default_args + $platform_args;
     // Load any build vars defined in the job definition file
     // Retrieve test definition file
     if (isset($source)) {
         $config['explicit_source'] = $source;
     }
     $definition_file = $this->getDefinitionFile($config);
     $definition_args = array();
     // Load test definition file
     if (!empty($definition_file)) {
         $job->getOutput()->writeln("<comment>Loading test parameters from build file: </comment><info>{$definition_file}</info>");
         $jobdef = new JobDefinition();
         $result = $jobdef->load($definition_file);
         if ($result == -1) {
             // Error loading definition file.
             $job->errorOutput("Failed", "Unable to parse build file.");
             // TODO: Robust error handling
             return;
         }
         $job_definition = $jobdef->getParameters();
         if (empty($job_definition)) {
             $job_definition = array();
             $definition_args = array();
         } else {
             $definition_args = !empty($job_definition['build_vars']) ? $job_definition['build_vars'] : array();
         }
         $job->setDefinition($job_definition);
     }
     $config = $cli_args + $definition_args + $environment_args + $local_args + $default_args + $platform_args;
     // Set initial build variables
     $buildvars = $job->getBuildVars();
     $job->setBuildVars($buildvars + $config);
     // Map relevant build variables into the job definition array
     // $this->buildvarsToDefinition($job);
     return;
 }