Skip to content

Commit e1a59c1

Browse files
committed
Get all sets when performing LTI date synchronization.
After the issue with the names and role service URL and realizing that the `next` link needs to be utilized to get all names and roles from the URL, I figured I had better check the spec for the `lineitems` URL used for set date synchronization to see if it works the same, and in fact, it does. See https://www.imsglobal.org/spec/lti-ags/v2p0#container-request-filters. So this makes sure that all sets are obtained from the `lineitems` URL in the same way. In testing this with Canvas, it turns out that Canvas only sends 10 sets at once. So if a course has more than 10 sets, then only 10 sets will be retrieved from the lineitems URL in the first request. Note that date synchronization will not necessarily fail though, as in the next phase of the job queue task, requests are sent to the individual lineitem URLs for the sets if the data was not received from the lineitems URL for the set assuming that the lineitem URL for the set has been obtained (webwork will have it if content item selection was used, or if a user has entered the set directly from the LMS). However, this results in extra network communication that is unnecessary.
1 parent 838b4fc commit e1a59c1

1 file changed

Lines changed: 30 additions & 18 deletions

File tree

lib/Mojolicious/WeBWorK/Tasks/LTISetDateSync.pm

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,37 @@ async sub synchronizeSetDates ($job, $setIDs, $syncToLMS) {
5252

5353
my $ua = Mojo::UserAgent->new;
5454

55-
my $lineitemsRequest =
56-
await $ua->get_p($lineitemsURL, { Authorization => "$accessToken->{token_type} $accessToken->{access_token}" })
57-
->catch(sub ($err) {
58-
return $err;
59-
});
60-
61-
return $job->fail(
62-
$job->maketext('There was an error communicating with the lineitems URL: [_1]', $lineitemsRequest))
63-
unless ref $lineitemsRequest;
64-
65-
my $lineitemsResult = $lineitemsRequest->result;
66-
67-
return $job->fail($job->maketext(
68-
'There was an error obtaining the current lineitems from the LMS: [_1]',
69-
$lineitemsResult->message
70-
))
71-
unless $lineitemsResult->is_success;
55+
my %lineitems;
56+
while (1) {
57+
my $lineitemsRequest =
58+
await $ua->get_p($lineitemsURL,
59+
{ Authorization => "$accessToken->{token_type} $accessToken->{access_token}" })->catch(sub ($err) {
60+
return $err;
61+
});
62+
63+
return $job->fail(
64+
$job->maketext('There was an error communicating with the lineitems URL: [_1]', $lineitemsRequest))
65+
unless ref $lineitemsRequest;
66+
67+
my $lineitemsResult = $lineitemsRequest->result;
68+
69+
return $job->fail($job->maketext(
70+
'There was an error obtaining the current lineitems from the LMS: [_1]',
71+
$lineitemsResult->message
72+
))
73+
unless $lineitemsResult->is_success;
74+
75+
for (@{ $lineitemsResult->json }) {
76+
next unless defined $_->{resourceId};
77+
$lineitems{ $_->{resourceId} } = $_;
78+
}
7279

73-
my %lineitems = map { $_->{resourceId} => $_ } grep { defined $_->{resourceId} } @{ $lineitemsResult->json };
80+
if ($lineitemsResult->headers->link && $lineitemsResult->headers->link =~ /<([^>]*)>;\s*rel="next"/) {
81+
$lineitemsURL = $1;
82+
} else {
83+
last;
84+
}
85+
}
7486

7587
my @messages;
7688

0 commit comments

Comments
 (0)