Skip to content

Commit

Permalink
MDL-46546 core_grades: Notice display for bad import.
Browse files Browse the repository at this point in the history
If the initial import of csv data is bad, a notification
will be displayed to the user.
  • Loading branch information
abgreeve committed Oct 13, 2014
1 parent d3ff822 commit a2809ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions grade/import/csv/classes/load_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,21 @@ public function load_csv_content($text, $encoding, $separator, $previewrows) {
$csvimport->load_csv_content($text, $encoding, $separator);
$this->error = $csvimport->get_error();

// Get header (field names).
$this->headers = $csvimport->get_columns();
$this->trim_headers();
// If there are no import errors then proceed.
if (empty($this->error)) {

$csvimport->init();
$this->previewdata = array();
// Get header (field names).
$this->headers = $csvimport->get_columns();
$this->trim_headers();

for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
$lines = $csvimport->next();
if ($lines) {
$this->previewdata[] = $lines;
$csvimport->init();
$this->previewdata = array();

for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
$lines = $csvimport->next();
if ($lines) {
$this->previewdata[] = $lines;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion grade/import/direct/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
$csvimport->load_csv_content($text, $formdata->encoding, 'tab', $formdata->previewrows);
$csvimporterror = $csvimport->get_error();
if (!empty($csvimporterror)) {
echo $renderer->errors($csvimport->get_error());
echo $renderer->errors(array($csvimport->get_error()));
echo $OUTPUT->footer();
die();
}
Expand Down

0 comments on commit a2809ae

Please sign in to comment.