/** * Receiving the three required CSVs, performs the importation of the data of a course: course info, enrolled users, * and log info. The data is imported to a total of three different tables. All operations are done in a unique * transaction: if something fails (a CSV does not respect the format, an importing course exists, etc.), nothing * will be saved. * * After the importation, associates the just created historic course with the current course, and sets this course as * active and personalizable, just in case it was marked as inactive and/or not personalizable. * * @param object $formdata The data submited in form. * @param object $coursefile The CSV file with the information about the course. * @param object $usersfile The CSV file with the information about the users enrolled in courses. * @param object $logsfile The CSV file with the information about the log views of the users. * @param int $currentcourseid The course id of the course for which the csv is being imported. * @throws \Exception If something bad happened when trying to insert the data. The exception is thrown after doing the * rollback. */ public static function import_data($formdata, $coursefile, $usersfile, $logsfile, $currentcourseid) { $db = new database_helper(); self::$lastinsertedcourses = 0; self::$lastinsertedusers = 0; self::$lastinsertedusers = 0; $transaction = $db->start_transaction(); try { $generatedcourseid = self::import_course($coursefile, $formdata, $db); self::import_users($usersfile, $formdata, $generatedcourseid, $db); self::import_logs($logsfile, $formdata, $generatedcourseid, $db); $db->associate_current_course_with_historic($currentcourseid, $generatedcourseid); $db->set_course_active($currentcourseid); $db->set_course_personalizable($currentcourseid); $db->commit_transaction($transaction); } catch (\Exception $e) { $db->rollback_transaction($transaction, $e); throw $e; } }