Skip to content

Commit 3b8d349

Browse files
committed
GetDKAN#4332: Fix import status dashboard pagination
1 parent 373a734 commit 3b8d349

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

modules/datastore/src/Form/DashboardForm.php

+29-8
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,31 @@ public function buildTable(array $datasets): array {
238238
];
239239
}
240240

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+
241266
/**
242267
* Retrieve list of UUIDs for datasets matching the given filters.
243268
*
@@ -259,7 +284,7 @@ protected function getDatasets(array $filters): array {
259284
// belonging to the specfied harvest.
260285
elseif (isset($filters['harvest_id'])) {
261286
$harvestLoad = iterator_to_array($this->getHarvestLoadStatus($filters['harvest_id']));
262-
$datasets = array_keys($harvestLoad);
287+
$datasets = $this->filterImportableDatasets(array_keys($harvestLoad));
263288
$total = count($datasets);
264289
$currentPage = $this->pagerManager->createPager($total, $this->itemsPerPage)->getCurrentPage();
265290

@@ -269,14 +294,10 @@ protected function getDatasets(array $filters): array {
269294
// If no filter values were supplied, fetch from the list of all dataset
270295
// UUIDs.
271296
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);
273299
$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);
280301
}
281302

282303
return $datasets;

0 commit comments

Comments
 (0)