diff --git a/bin/csv-import.php b/bin/csv-import.php index 16cbe6a..b801b75 100644 --- a/bin/csv-import.php +++ b/bin/csv-import.php @@ -49,6 +49,10 @@ cli_write('.'); }); + +cli_writeln("\nWarnings:"); +print_r(OuUser::getWarnings()); + cli_writeln("\nUsers inserted: $count"); diff --git a/db/User.php b/db/User.php index 674ac2d..44bab73 100644 --- a/db/User.php +++ b/db/User.php @@ -27,7 +27,7 @@ class User const CSV_TEAM = 4; const PREFIX = 'ouop_'; - const UNDEF_INSTRUMENT = 'kd'; + const UNDEF_INSTRUMENT = 'tpt'; //'kd'; const INSTRUMENT_REGEX = '@^(kd|tpt)@'; const OUCU_REGEX = '@^[a-z]{2,4}\d{1,7}$@'; @@ -35,6 +35,8 @@ class User const USERNAME_REGEX = '@^httpopenidopenacukoucu(?P\w+)$@'; const USERNAME_REPLACE = '@^(httpopenidopenacukoucu)?@'; + protected static $warnings = []; + /** Get plugin DB record for given username. * @return object */ @@ -103,9 +105,9 @@ public static function insertFromCsv($filename = '../example.csv', $ignore_headi } $user_record = (object) [ - 'oucu' => self::validateOucu($row[ self::CSV_OUCU ]), # 0, + 'oucu' => self::validateOucu($row[ self::CSV_OUCU ], $count), # 0, 'course_presentation' => $row[ self::CSV_OUCU + 1 ], # 1, - 'teslainstrument' => self::validateInstrument(self::row($row, self::CSV_OUCU + 2)), + 'teslainstrument' => self::validateInstrument(self::row($row, self::CSV_OUCU + 2), $count, $row[ self::CSV_OUCU ]), 'notes' => self::row($row, self::CSV_OUCU + 3), # 3, 'is_team' => self::row($row, self::CSV_TEAM), # 4, 'firstname' => self::row($row, self::CSV_TEAM + 1), # 5, @@ -125,18 +127,20 @@ public static function insertFromCsv($filename = '../example.csv', $ignore_headi return $count; } - protected static function validateOucu($oucu) + protected static function validateOucu($oucu, $row) { if (!preg_match(self::OUCU_REGEX, $oucu)) { - throw new Exception('Unexpected OUCU format: ' . $oucu); + self::$warnings[] = [ 'row' => $row, 'msg' => 'Unexpected OUCU', 'oucu' => $oucu ]; + echo 'W'; + //throw new Exception('Unexpected OUCU format: ' . $oucu); } return $oucu; } - protected static function validateInstrument($instrument) + protected static function validateInstrument($instrument, $row, $ref) { if (!preg_match(self::INSTRUMENT_REGEX, $instrument)) { - throw new Exception('Unexpected TeSLA instrument code: '. $instrument); + throw new Exception(sprintf('Unexpected TeSLA instrument code, %d, %s: "%s"', $row, $ref, $instrument)); } return $instrument; } @@ -236,6 +240,11 @@ public static function getRoles() return (object) [ 'is_admin' => is_siteadmin(), 'roles' => $roles, 'is_loggedin' => isloggedin() ]; } + public static function getWarnings() + { + return self::$warnings; + } + // ==================================================================== /** Get URL relating to the TeSLA instrument assigned to the user (in the DB) [ MOVE ] ? diff --git a/index.php b/index.php index bf44135..61fd178 100644 --- a/index.php +++ b/index.php @@ -18,7 +18,8 @@ class Ou_Open_Id_Form { const ACTION = '/login/index.php'; - const OUCU_REGEX = '[a-z]{2,4}\d{1,7}'; + const OUCU_REGEX = '[a-z]{1,6}\d{1,7}'; // Was: '[a-z]{2,4}\d{1,7}'. + const OUCU_MIN = 2; // Was: 3. const OPEN_ID_URL = 'http://openid.open.ac.uk/oucu/'; const JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js'; @@ -59,7 +60,7 @@ public static function printOucu() { ?>