Skip to content

Commit

Permalink
GetDKAN#4332: Fix import status dashboard pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-korn committed Nov 7, 2024
1 parent 373a734 commit 3b8d349
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions modules/datastore/src/Form/DashboardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,31 @@ public function buildTable(array $datasets): array {
];
}

/**
* Filter datasets with importable distributions
*
* @param array $dataset_uuids
* Datasets to be filtered.
*
* @return array
* Filtered datasets.
*/
protected function filterImportableDatasets($dataset_uuids) {
$datasets_filtered = [];
foreach ($dataset_uuids as $dataset_uuid) {
$dataset = $this->datasetInfo->gather($dataset_uuid);
foreach ($dataset as $rev) {
$distributions = array_filter($rev['distributions'], function ($v) {
return !isset($v['mime_type']) || in_array($v['mime_type'], DataResource::IMPORTABLE_FILE_TYPES);
});
if (!empty($distributions)) {
$datasets_filtered[] = $dataset_uuid;
}
}
}
return $datasets_filtered;
}

/**
* Retrieve list of UUIDs for datasets matching the given filters.
*
Expand All @@ -259,7 +284,7 @@ protected function getDatasets(array $filters): array {
// belonging to the specfied harvest.
elseif (isset($filters['harvest_id'])) {
$harvestLoad = iterator_to_array($this->getHarvestLoadStatus($filters['harvest_id']));
$datasets = array_keys($harvestLoad);
$datasets = $this->filterImportableDatasets(array_keys($harvestLoad));
$total = count($datasets);
$currentPage = $this->pagerManager->createPager($total, $this->itemsPerPage)->getCurrentPage();

Expand All @@ -269,14 +294,10 @@ protected function getDatasets(array $filters): array {
// If no filter values were supplied, fetch from the list of all dataset
// UUIDs.
else {
$total = $this->metastore->count('dataset', TRUE);
$datasets_filtered = $this->filterImportableDatasets($this->metastore->getIdentifiers('dataset', NULL, NULL, TRUE));
$total = count($datasets_filtered);
$currentPage = $this->pagerManager->createPager($total, $this->itemsPerPage)->getCurrentPage();
$datasets = $this->metastore->getIdentifiers(
'dataset',
($currentPage * $this->itemsPerPage),
$this->itemsPerPage,
TRUE
);
$datasets = array_slice($datasets_filtered, $currentPage * $this->itemsPerPage, $this->itemsPerPage);
}

return $datasets;
Expand Down

0 comments on commit 3b8d349

Please sign in to comment.