protected function execute(InputInterface $input, OutputInterface $output)
{
$this->validateInput($input);
$id = $input->getArgument('id');
$integration = $this->getSelectedProject()->getIntegration($id);
if (!$integration) {
$this->stdErr->writeln("Integration not found: <error>{$id}</error>");
return 1;
}
$values = [];
$form = $this->getForm();
$currentValues = $integration->getProperties();
foreach ($form->getFields() as $key => $field) {
$value = $field->getValueFromInput($input);
if ($value !== null && $currentValues[$key] !== $value) {
$values[$key] = $value;
}
}
if (!$values) {
$this->stdErr->writeln("No changed values were provided to update");
return 1;
}
// Complete the PATCH request with the current values. This is a
// workaround: at the moment a PATCH with only the changed values will
// cause a 500 error.
foreach ($currentValues as $key => $currentValue) {
if ($key !== 'id' && !array_key_exists($key, $values)) {
$values[$key] = $currentValue;
}
}
$result = $integration->update($values);
$this->stdErr->writeln("Integration <info>{$id}</info> (<info>{$integration->type}</info>) updated");
$this->displayIntegration($integration, $input, $this->stdErr);
if (!$input->getOption('no-wait')) {
ActivityUtil::waitMultiple($result->getActivities(), $this->stdErr, $this->getSelectedProject());
}
return 0;
}