Commit 668e53f8 authored by Jon Pugh's avatar Jon Pugh

Allow editing of contexts using provision save command.

parent 28984d44
...@@ -32,6 +32,11 @@ class SaveCommand extends Command ...@@ -32,6 +32,11 @@ class SaveCommand extends Command
*/ */
private $context_type; private $context_type;
/**
* @var bool
*/
private $newContext = FALSE;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -135,6 +140,8 @@ class SaveCommand extends Command ...@@ -135,6 +140,8 @@ class SaveCommand extends Command
// If this is a new context... // If this is a new context...
if (empty($this->context)) { if (empty($this->context)) {
$this->newContext = TRUE;
// If context_type is still empty, throw an exception. Happens if using -n // If context_type is still empty, throw an exception. Happens if using -n
if (empty($context_type)) { if (empty($context_type)) {
throw new \Exception('Option --context_type must be specified.'); throw new \Exception('Option --context_type must be specified.');
...@@ -175,7 +182,6 @@ class SaveCommand extends Command ...@@ -175,7 +182,6 @@ class SaveCommand extends Command
exit(1); exit(1);
} }
$options = $this->askForContextProperties(); $options = $this->askForContextProperties();
$options['name'] = $this->context_name; $options['name'] = $this->context_name;
$options['type'] = $this->context_type; $options['type'] = $this->context_type;
...@@ -183,6 +189,22 @@ class SaveCommand extends Command ...@@ -183,6 +189,22 @@ class SaveCommand extends Command
$class = Context::getClassName($this->input->getOption('context_type')); $class = Context::getClassName($this->input->getOption('context_type'));
$this->context = new $class($input->getArgument('context_name'), $this->getProvision(), $options); $this->context = new $class($input->getArgument('context_name'), $this->getProvision(), $options);
} }
else {
// Save over existing contexts.
$this->newContext = FALSE;
$this->input->setOption('context_type', $this->context->type);
$properties = $this->askForContextProperties();
// Write over each property with new values.
foreach ($properties as $name => $value) {
$this->context->setProperty($name, $value);
}
$context_type = $this->context->type;
$this->input->setOption('context_type', $this->context->type);
}
// Delete context config. // Delete context config.
if ($input->getOption('delete')) { if ($input->getOption('delete')) {
...@@ -324,6 +346,11 @@ class SaveCommand extends Command ...@@ -324,6 +346,11 @@ class SaveCommand extends Command
$property = Provision::newProperty($property); $property = Provision::newProperty($property);
} }
// If we are editing a context, override the default property.
if (!$this->newContext && $current_value = $this->context->getProperty($name)) {
$property->default = $current_value;
}
// If option does not exist, ask for it. // If option does not exist, ask for it.
if (!empty($this->input->getOption($name))) { if (!empty($this->input->getOption($name))) {
$properties[$name] = $this->input->getOption($name); $properties[$name] = $this->input->getOption($name);
......
...@@ -426,6 +426,17 @@ class Context implements BuilderAwareInterface ...@@ -426,6 +426,17 @@ class Context implements BuilderAwareInterface
} }
} }
/**
* Set a specific property.
*
* @param $name
* @return mixed
* @throws \Exception
*/
public function setProperty($name, $value) {
$this->properties[$name] = $value;
}
/** /**
* Saves the config class to file. * Saves the config class to file.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment