@@ -238,6 +238,31 @@ public function buildTable(array $datasets): array {
238
238
];
239
239
}
240
240
241
+ /**
242
+ * Filter datasets with importable distributions
243
+ *
244
+ * @param array $dataset_uuids
245
+ * Datasets to be filtered.
246
+ *
247
+ * @return array
248
+ * Filtered datasets.
249
+ */
250
+ protected function filterImportableDatasets ($ dataset_uuids ) {
251
+ $ datasets_filtered = [];
252
+ foreach ($ dataset_uuids as $ dataset_uuid ) {
253
+ $ dataset = $ this ->datasetInfo ->gather ($ dataset_uuid );
254
+ foreach ($ dataset as $ rev ) {
255
+ $ distributions = array_filter ($ rev ['distributions ' ], function ($ v ) {
256
+ return !isset ($ v ['mime_type ' ]) || in_array ($ v ['mime_type ' ], DataResource::IMPORTABLE_FILE_TYPES );
257
+ });
258
+ if (!empty ($ distributions )) {
259
+ $ datasets_filtered [] = $ dataset_uuid ;
260
+ }
261
+ }
262
+ }
263
+ return $ datasets_filtered ;
264
+ }
265
+
241
266
/**
242
267
* Retrieve list of UUIDs for datasets matching the given filters.
243
268
*
@@ -259,7 +284,7 @@ protected function getDatasets(array $filters): array {
259
284
// belonging to the specfied harvest.
260
285
elseif (isset ($ filters ['harvest_id ' ])) {
261
286
$ harvestLoad = iterator_to_array ($ this ->getHarvestLoadStatus ($ filters ['harvest_id ' ]));
262
- $ datasets = array_keys ($ harvestLoad );
287
+ $ datasets = $ this -> filterImportableDatasets ( array_keys ($ harvestLoad) );
263
288
$ total = count ($ datasets );
264
289
$ currentPage = $ this ->pagerManager ->createPager ($ total , $ this ->itemsPerPage )->getCurrentPage ();
265
290
@@ -269,14 +294,10 @@ protected function getDatasets(array $filters): array {
269
294
// If no filter values were supplied, fetch from the list of all dataset
270
295
// UUIDs.
271
296
else {
272
- $ total = $ this ->metastore ->count ('dataset ' , TRUE );
297
+ $ datasets_filtered = $ this ->filterImportableDatasets ($ this ->metastore ->getIdentifiers ('dataset ' , NULL , NULL , TRUE ));
298
+ $ total = count ($ datasets_filtered );
273
299
$ currentPage = $ this ->pagerManager ->createPager ($ total , $ this ->itemsPerPage )->getCurrentPage ();
274
- $ datasets = $ this ->metastore ->getIdentifiers (
275
- 'dataset ' ,
276
- ($ currentPage * $ this ->itemsPerPage ),
277
- $ this ->itemsPerPage ,
278
- TRUE
279
- );
300
+ $ datasets = array_slice ($ datasets_filtered , $ currentPage * $ this ->itemsPerPage , $ this ->itemsPerPage );
280
301
}
281
302
282
303
return $ datasets ;
0 commit comments