-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsis_import_courses_and_terms.php
74 lines (58 loc) · 3.31 KB
/
sis_import_courses_and_terms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/*
* sis_import_courses_and_terms.php
* It's pretty simple. All this file does is import courses and terms from EX
* All these CSV files are automagically generated by jobs on the EX Database server
*
*/
require 'functions.php';
include 'uploads_by_month.inc';
/*
* We'll start with the terms first.
* You need terms before you can have courses.
* And you need courses before you can have sections.
* The order is everything, padawan.
*
* This is commented out because we've opted to manually manage our terms in Canvas.
$url=$canvas_base_url."/api/v1/accounts/1/sis_imports.json?import_type=instructure_csv";
// Send in the terms, those happy little terms
$file1=$samba_share."terms.csv";
echo "Now uploading: Terms\n=======================================================================================================\n\n";
system("curl -F attachment=@$file1 -H 'Authorization: Bearer $access_token' $url");
*/
/*
*
* Loop through each file we be keepin and send it on over to da Canvas peeples
*
*/
foreach ($files as $file) {
$courses_file=$samba_share.$file.'_courses.csv';
$sections_file=$samba_share.$file.'_sections.csv';
$xlist_file=$samba_share.$file.'_xlist.csv';
echo "\n\nDebug Data:\n=======================================================================================================\nFile: ".$file."\nCourses File: ".$courses_file."\nSections File: ".$sections_file."\nXList File: ".$xlist_file."\n\n";
// open the file real quick like so that we can grab the term_id from it... we'll need that for our batch mode process
$importer = new CsvImporter($courses_file,true);
$data = $importer->get(1);
$this_term=$data[0]['term_id'];
if (strlen($this_term) > 4 && $this_term != "2013MA") {
// now, let's send Canvas the courses file for the term we're uploading
if (file_fresh($courses_file)) {
$url=$canvas_base_url."/api/v1/accounts/1/sis_imports.json?import_type=instructure_csv&batch_mode=1&batch_mode_term_id=sis_term_id:".$this_term;
echo "\n\nNow uploading: ".$this_term." Courses\n=======================================================================================================\nURL: ".$url."\n\n";
system("curl -F attachment=@$courses_file -H 'Authorization: Bearer $access_token' '$url'");
}
// we chase that file with sections. what good is a course without a section?
if (file_fresh($sections_file)) {
$url=$canvas_base_url."/api/v1/accounts/1/sis_imports.json?import_type=instructure_csv&batch_mode=1&batch_mode_term_id=sis_term_id:".$this_term;
echo "\n\nNow uploading: ".$this_term." Sections\n=======================================================================================================\nURL: ".$url."\n\n";
system("curl -F attachment=@$sections_file -H 'Authorization: Bearer $access_token' '$url'");
}
// now, on to the cross listed courses. we be mergin!
if (file_fresh($xlist_file)) {
$url=$canvas_base_url."/api/v1/accounts/1/sis_imports.json?import_type=instructure_csv&batch_mode=1&batch_mode_term_id=sis_term_id:".$this_term;
echo "\n\nNow uploading: ".$this_term." Cross listed courses\n=======================================================================================================\nURL: ".$url."\n\n";
system("curl -F attachment=@$xlist_file -H 'Authorization: Bearer $access_token' '$url'");
}
}
}
?>