Skip to content
Merged
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
33 changes: 17 additions & 16 deletions student_auto_feed/submitty_student_auto_feed.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,18 @@ private function validate_csv($csv_data) {
}

//BEGIN VALIDATION
$course = strtolower($row[COLUMN_COURSE_PREFIX]) . $row[COLUMN_COURSE_NUMBER];
$section = intval($row[COLUMN_SECTION]); //intval($str) returns zero when $str is not integer.
//Invalidate any row that doesn't have requisite number of fields. Do this, first.
//Invalidation will disqualify the data file to protect DB data integrity.
$num_fields = count($row);
if ($num_fields !== $validate_num_fields) {
$this->log_it("Row {$index} has {$num_fields} columns. {$validate_num_fields} expected.");
$validation_flag = false;
continue;
}

$course = strtolower($row[COLUMN_COURSE_PREFIX]) . $row[COLUMN_COURSE_NUMBER];
// Remove any leading zeroes from "integer" registration sections.
$section = (ctype_digit($row[COLUMN_SECTION])) ? ltrim($row[COLUMN_SECTION], "0") : $row[COLUMN_SECTION];

//Row validation filters. If any prove false, row is discarded.
switch(false) {
Expand All @@ -163,15 +172,9 @@ private function validate_csv($csv_data) {
//Check that row shows student is registered.
case (in_array($row[COLUMN_REGISTRATION], unserialize(STUDENT_REGISTERED_CODES))):
break;
//Validate expected number of fields
case ($num_fields === $validate_num_fields):
//Log that row is invalid per number of columns
$this->log_it("Row {$index} has {$num_fields} columns. {$validate_num_fields} expected.");
$validation_flag = false;
break;
//Check row columns
//Row is OK, next check row columns.
default:
//Column validation filters. If any prove false, the entire row is discarded.
//Column validation filters. If any prove false, the entire data file will be disqualified.
switch(false) {
//Check term code (skips when set to null).
case ((is_null(EXPECTED_TERM_CODE)) ? true : ($row[COLUMN_TERM_CODE] === EXPECTED_TERM_CODE)):
Expand Down Expand Up @@ -210,7 +213,7 @@ private function validate_csv($csv_data) {
$tmp_course = $course;
$tmp_section = $section;
$course = self::$course_mappings[$tmp_course][$tmp_section]['mapped_course'];
$section = intval(self::$course_mappings[$tmp_course][$tmp_section]['mapped_section']);
$section = self::$course_mappings[$tmp_course][$tmp_section]['mapped_section'];
} else {
$this->log_it("{$course} has been mapped. Section {$section} is in feed, but not mapped.");
$validation_flag = false;
Expand Down Expand Up @@ -440,7 +443,6 @@ private function deduplicate($subset = 'users', $key = 'user_id') {
* @return boolean true when upsert is complete
*/
private function upsert_psql() {

$sql = array('begin' => 'BEGIN',
'commit' => 'COMMIT',
'rollback' => 'ROLLBACK');
Expand All @@ -466,11 +468,11 @@ private function upsert_psql() {

$sql['courses_users']['temp_table'] = <<<SQL
CREATE TEMPORARY TABLE upsert_courses_users (
semester VARCHAR,
course VARCHAR,
semester VARCHAR(255),
course VARCHAR(255),
user_id VARCHAR,
user_group INTEGER,
registration_section VARCHAR,
registration_section VARCHAR(255),
manual_registration BOOLEAN
) ON COMMIT DROP
SQL;
Expand Down Expand Up @@ -682,7 +684,6 @@ private function upsert_psql() {
pg_query(self::$db, $sql['courses_users']['lock']);
switch (false) {
case pg_query(self::$db, $sql['registration_section']['insert']):

pg_query(self::$db, $sql['rollback']);
break;
case pg_query(self::$db, $sql['courses_users']['update']):
Expand Down