mirror of https://github.com/MISP/MISP
chg: [CLI] Simplify updating JSON structures
parent
8ecb50a492
commit
2dd74ed79b
|
@ -184,20 +184,8 @@ jobs:
|
||||||
app/Console/cake Admin setSetting "Plugin.ZeroMQ_enable" 1
|
app/Console/cake Admin setSetting "Plugin.ZeroMQ_enable" 1
|
||||||
app/Console/cake Admin setSetting "Plugin.ZeroMQ_audit_notifications_enable" 1
|
app/Console/cake Admin setSetting "Plugin.ZeroMQ_audit_notifications_enable" 1
|
||||||
|
|
||||||
- name: Update Galaxies
|
- name: Update JSON
|
||||||
run: app/Console/cake Admin updateGalaxies
|
run: app/Console/cake Admin updateJSON
|
||||||
|
|
||||||
- name: Update Taxonomies
|
|
||||||
run: app/Console/cake Admin updateTaxonomies
|
|
||||||
|
|
||||||
- name: Update Warninglists
|
|
||||||
run: app/Console/cake Admin updateWarningLists --verbose
|
|
||||||
|
|
||||||
- name: Update Noticelists
|
|
||||||
run: app/Console/cake Admin updateNoticeLists
|
|
||||||
|
|
||||||
- name: Update Object Templates
|
|
||||||
run: app/Console/cake Admin updateObjectTemplates 1
|
|
||||||
|
|
||||||
- name: Turn MISP live
|
- name: Turn MISP live
|
||||||
run: app/Console/cake Admin live 1
|
run: app/Console/cake Admin live 1
|
||||||
|
|
|
@ -302,16 +302,22 @@ class AdminShell extends AppShell
|
||||||
public function updateJSON()
|
public function updateJSON()
|
||||||
{
|
{
|
||||||
$this->out('Updating all JSON structures.');
|
$this->out('Updating all JSON structures.');
|
||||||
$results = $this->Server->updateJSON();
|
$overallSuccess = true;
|
||||||
foreach ($results as $type => $result) {
|
foreach ($this->Server->updateJSON() as $type => $result) {
|
||||||
$type = Inflector::pluralize(Inflector::humanize($type));
|
$type = Inflector::pluralize(Inflector::humanize($type));
|
||||||
if ($result !== false) {
|
if ($result['success']) {
|
||||||
$this->out(__('%s updated.', $type));
|
$this->out(__('%s updated in %.2f seconds.', $type, $result['duration']));
|
||||||
} else {
|
} else {
|
||||||
$this->out(__('Could not update %s.', $type));
|
$this->out(__('Could not update %s.', $type));
|
||||||
|
$this->out($result['result']);
|
||||||
|
$overallSuccess = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->out('All JSON structures updated. Thank you and have a very safe and productive day.');
|
if ($overallSuccess) {
|
||||||
|
$this->out('All JSON structures updated. Thank you and have a very safe and productive day.');
|
||||||
|
} else {
|
||||||
|
$this->error('Some structure could no be updated');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateGalaxies()
|
public function updateGalaxies()
|
||||||
|
|
|
@ -2084,7 +2084,10 @@ class ServersController extends AppController
|
||||||
|
|
||||||
public function updateJSON()
|
public function updateJSON()
|
||||||
{
|
{
|
||||||
$results = $this->Server->updateJSON();
|
$results = [];
|
||||||
|
foreach ($this->Server->updateJSON() as $type => $result) {
|
||||||
|
$results[$type] = $results['success'];
|
||||||
|
}
|
||||||
return $this->RestResponse->viewData($results, $this->response->type());
|
return $this->RestResponse->viewData($results, $this->response->type());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4746,15 +4746,18 @@ class Server extends AppModel
|
||||||
return $servers;
|
return $servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Generator[string, array]
|
||||||
|
*/
|
||||||
public function updateJSON()
|
public function updateJSON()
|
||||||
{
|
{
|
||||||
$results = array();
|
|
||||||
foreach (['Galaxy', 'Noticelist', 'Warninglist', 'Taxonomy', 'ObjectTemplate', 'ObjectRelationship'] as $target) {
|
foreach (['Galaxy', 'Noticelist', 'Warninglist', 'Taxonomy', 'ObjectTemplate', 'ObjectRelationship'] as $target) {
|
||||||
$model = ClassRegistry::init($target);
|
$model = ClassRegistry::init($target);
|
||||||
|
$start = microtime(true);
|
||||||
$result = $model->update();
|
$result = $model->update();
|
||||||
$results[$target] = $result === false ? false : true;
|
$duration = microtime(true) - $start;
|
||||||
|
yield $target => ['success' => $result !== false, 'result' => $result, 'duration' => $duration];
|
||||||
}
|
}
|
||||||
return $results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetRemoteAuthKey($id)
|
public function resetRemoteAuthKey($id)
|
||||||
|
|
Loading…
Reference in New Issue