Skip to content

Commit

Permalink
DataSet: trying to import without any columns logs an unhelpful error…
Browse files Browse the repository at this point in the history
… (#3458)

relates to xibosignage/xibo#3458
  • Loading branch information
nadzpogi committed Jul 31, 2024
1 parent b63e55c commit 809a27b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/Controller/DataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,9 @@ public function editForm(Request $request, Response $response, $id)
// Retrieve data sources from the event
$dataConnectorSources = $event->getDataConnectorSources();

// retrieve the columns of the selected dataset
$dataSet->getColumn();

// Set the form
$this->getState()->template = 'dataset-form-edit';
$this->getState()->setData([
Expand Down
7 changes: 6 additions & 1 deletion lib/Helper/DataSetUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ protected function handleFormData($file, $index)
throw new AccessDeniedException();
}

// Check if there are any columns defined in the dataset
if (count($dataSet->getColumn()) === 0) {
$controller->getLog()->error('Import failed: No columns defined in the dataset.');
throw new InvalidArgumentException('Import failed: No columns defined in the dataset.');
}

// We are allowed to edit - pull all required parameters from the request object
$overwrite = $sanitizer->getCheckbox('overwrite');
$ignoreFirstRow = $sanitizer->getCheckbox('ignorefirstrow');
Expand Down Expand Up @@ -95,7 +101,6 @@ protected function handleFormData($file, $index)

$firstRow = true;
$i = 0;

$handle = fopen($controller->getConfig()->getSetting('LIBRARY_LOCATION') . 'temp/' . $fileName, 'r');
while (($data = fgetcsv($handle)) !== FALSE ) {
$i++;
Expand Down
4 changes: 4 additions & 0 deletions views/dataset-form-edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
{{ forms.dropdown("dataConnectorSource", "single", title, dataSet.dataConnectorSource, dataConnectorSources, "id", "name", helpText) }}
</div>

{% if dataSet.columns|length == 0 %}
{{ forms.message("No columns have been configured for this dataset. Please configure your columns accordingly."|trans, "alert alert-warning") }}
{% endif %}

{% if dataSet.isActive() %}
{{ forms.message("This DataSet has been accessed or updated recently, which means the CMS will keep it active."|trans, "alert alert-success") }}
{% endif %}
Expand Down

0 comments on commit 809a27b

Please sign in to comment.