mirror of https://github.com/MISP/MISP
new: [API] update command got new branch parameter
- instruct the update process to be prepended by a checkout of a given branch - passed via a URL parameter (/servers/update/branch:develop) OR - passed via a JSON object ({"branch": "develop"})pull/6898/head
parent
6f8359a8c8
commit
8ee0555798
|
@ -1823,9 +1823,19 @@ class ServersController extends AppController
|
||||||
$result = $this->Server->checkoutMain();
|
$result = $this->Server->checkoutMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update()
|
public function update($branch = false)
|
||||||
{
|
{
|
||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
|
$branch = false;
|
||||||
|
$filterData = array(
|
||||||
|
'request' => $this->request,
|
||||||
|
'named_params' => $this->params['named'],
|
||||||
|
'paramArray' => ['branch'],
|
||||||
|
'ordered_url_params' => @compact($paramArray),
|
||||||
|
'additional_delimiters' => PHP_EOL
|
||||||
|
);
|
||||||
|
$exception = false;
|
||||||
|
$settings = $this->_harvestParameters($filterData, $exception);
|
||||||
$status = $this->Server->getCurrentGitStatus();
|
$status = $this->Server->getCurrentGitStatus();
|
||||||
$raw = array();
|
$raw = array();
|
||||||
if (empty($status['branch'])) { // do not try to update if you are not on branch
|
if (empty($status['branch'])) { // do not try to update if you are not on branch
|
||||||
|
@ -1833,7 +1843,7 @@ class ServersController extends AppController
|
||||||
$raw[] = $msg;
|
$raw[] = $msg;
|
||||||
$update = $msg;
|
$update = $msg;
|
||||||
} else {
|
} else {
|
||||||
$update = $this->Server->update($status, $raw);
|
$update = $this->Server->update($status, $raw, $settings);
|
||||||
}
|
}
|
||||||
if ($this->_isRest()) {
|
if ($this->_isRest()) {
|
||||||
return $this->RestResponse->viewData(array('results' => $raw), $this->response->type());
|
return $this->RestResponse->viewData(array('results' => $raw), $this->response->type());
|
||||||
|
|
|
@ -3924,7 +3924,7 @@ class Server extends AppModel
|
||||||
return implode('\n', $result);
|
return implode('\n', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(array $status, &$raw = array())
|
public function update(array $status, &$raw = [], array $settings = [])
|
||||||
{
|
{
|
||||||
$final = '';
|
$final = '';
|
||||||
$workingDirectoryPrefix = 'cd $(git rev-parse --show-toplevel) && ';
|
$workingDirectoryPrefix = 'cd $(git rev-parse --show-toplevel) && ';
|
||||||
|
@ -3943,7 +3943,18 @@ class Server extends AppModel
|
||||||
);
|
);
|
||||||
$final .= implode("\n", $output) . "\n\n";
|
$final .= implode("\n", $output) . "\n\n";
|
||||||
}
|
}
|
||||||
$command1 = $workingDirectoryPrefix . 'git pull origin ' . $status['branch'] . ' 2>&1';
|
if (!empty($settings['branch'])) {
|
||||||
|
$branchname = preg_match('/$[a-z0-9\_]+/i', $settings['branch']);
|
||||||
|
$checkout_command = $workingDirectoryPrefix . 'git checkout ' . escapeshellarg($branchname) . ' 2>&1';
|
||||||
|
exec($checkout_command, $output, $returnCode);
|
||||||
|
$raw[] = array(
|
||||||
|
'input' => $command1,
|
||||||
|
'output' => $output,
|
||||||
|
'status' => $returnCode,
|
||||||
|
);
|
||||||
|
$status = $this->getCurrentGitStatus();
|
||||||
|
}
|
||||||
|
$command1 = $workingDirectoryPrefix . 'git pull origin ' . escapeshellarg($status['branch']) . ' 2>&1';
|
||||||
$command2 = $workingDirectoryPrefix . 'git submodule update --init --recursive 2>&1';
|
$command2 = $workingDirectoryPrefix . 'git submodule update --init --recursive 2>&1';
|
||||||
$final .= $command1 . "\n\n";
|
$final .= $command1 . "\n\n";
|
||||||
$returnCode = false;
|
$returnCode = false;
|
||||||
|
|
Loading…
Reference in New Issue