Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4332: Fix import status dashboard pagination #4333

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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