@@ -907,6 +907,12 @@ public function organisationsAction(array $params): array
907
907
'reload_url ' => '/localTools/action/ ' . h ($ params ['connection ' ]['id ' ]) . '/organisationsAction ' ,
908
908
'popover_url ' => '/localTools/action/ ' . h ($ params ['connection ' ]['id ' ]) . '/fetchSelectedOrganisationsAction '
909
909
],
910
+ [
911
+ 'text ' => __ ('Fetch all organisations ' ),
912
+ 'html ' => '<i class="fas fa-download"></i> ' ,
913
+ 'reload_url ' => '/localTools/action/ ' . h ($ params ['connection ' ]['id ' ]) . '/organisationsAction ' ,
914
+ 'popover_url ' => '/localTools/action/ ' . h ($ params ['connection ' ]['id ' ]) . '/fetchSelectedOrganisationsAction?ids=all '
915
+ ],
910
916
[
911
917
'text ' => __ ('Push organisations ' ),
912
918
'html ' => '<i class="fas fa-upload"></i> ' ,
@@ -1190,23 +1196,42 @@ public function fetchSelectedOrganisationsAction(array $params): array
1190
1196
return [
1191
1197
'data ' => [
1192
1198
'title ' => __ ('Fetch organisations ' ),
1193
- 'description ' => __ ('Fetch and create/update the selected {0} organisations from MISP? ' , count ($ ids )),
1199
+ 'description ' => is_array ($ ids ) ?
1200
+ __ ('Fetch and create/update the selected {0} organisations from MISP? ' , count ($ ids )) :
1201
+ __ ('Fetch and create/update ALL organisations from MISP? ' ),
1194
1202
'submit ' => [
1195
1203
'action ' => $ params ['request ' ]->getParam ('action ' )
1196
1204
],
1197
- 'url ' => ['controller ' => 'localTools ' , 'action ' => 'action ' , $ params ['connection ' ]['id ' ], 'fetchSelectedOrganisationsAction ' ]
1205
+ 'url ' => is_array ($ ids ) ?
1206
+ ['controller ' => 'localTools ' , 'action ' => 'action ' , $ params ['connection ' ]['id ' ], 'fetchSelectedOrganisationsAction ' ] :
1207
+ ['controller ' => 'localTools ' , 'action ' => 'action ' , $ params ['connection ' ]['id ' ], 'fetchSelectedOrganisationsAction?ids=all ' ]
1198
1208
]
1199
1209
];
1200
1210
} elseif ($ params ['request ' ]->is (['post ' ])) {
1201
1211
$ successes = 0 ;
1202
1212
$ errors = 0 ;
1203
- foreach ($ ids as $ id ) {
1204
- $ response = $ this ->getData ('/organisations/view/ ' . $ id , $ params );
1205
- $ result = $ this ->captureOrganisation ($ response ->getJson ()['Organisation ' ]);
1213
+ if (!is_array ($ ids ) && $ ids === 'all ' ) {
1214
+ $ response = $ this ->getData ('/organisations/index/scope:all ' , $ params );
1206
1215
if ($ response ->getStatusCode () == 200 ) {
1207
- $ successes ++;
1208
- } else {
1209
- $ errors ++;
1216
+ $ orgs = $ response ->getJson ();
1217
+ foreach ($ orgs as $ org ) {
1218
+ $ result = $ this ->captureOrganisation ($ org ['Organisation ' ]);
1219
+ if ($ result ) {
1220
+ $ successes ++;
1221
+ } else {
1222
+ $ errors ++;
1223
+ }
1224
+ }
1225
+ }
1226
+ } else {
1227
+ foreach ($ ids as $ id ) {
1228
+ $ response = $ this ->getData ('/organisations/view/ ' . $ id , $ params );
1229
+ $ result = $ this ->captureOrganisation ($ response ->getJson ()['Organisation ' ]);
1230
+ if ($ response ->getStatusCode () == 200 ) {
1231
+ $ successes ++;
1232
+ } else {
1233
+ $ errors ++;
1234
+ }
1210
1235
}
1211
1236
}
1212
1237
if ($ successes ) {
0 commit comments