Skip to content

Commit 37895ed

Browse files
committed
fix: syllabus being detected and replaced in file change process
1 parent 1b8d591 commit 37895ed

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

assets/js/Components/ReviewFilesPage.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,18 @@ useEffect(() => {
521521
}
522522
}
523523

524-
const extractUrl = (url) => {
524+
const extractUrl = (url, contentType) => {
525525
if(!url) return ''
526526

527527
const idx = url.indexOf('courses/');
528528
if (idx !== -1) {
529529
// slice from "courses/" onward and strip any leading slashes (defensive)
530-
return url.slice(idx).replace(/^\/+/, '');
530+
let slicedUrl = url.slice(idx).replace(/^\/+/, '');
531+
if(contentType == "syllabus"){
532+
const parts = slicedUrl.split("/")
533+
slicedUrl = `${parts[0]}/${parts[1]}?include[]=syllabus_body`
534+
}
535+
return slicedUrl
531536
}
532537

533538
// if no "courses/" found, remove leading slashes and return the remainder
@@ -614,7 +619,7 @@ useEffect(() => {
614619
}
615620

616621
const createContentItemPostOptions = (fullPageHtml, contentUrl, contentId, contentType, sectionIds) => {
617-
const contentItemOption = {
622+
const contentItemOption = {
618623
fullPageHtml: fullPageHtml,
619624
contentUrl: contentUrl,
620625
contentId: contentId,
@@ -646,7 +651,7 @@ useEffect(() => {
646651
if(reference.contentItemBody){
647652
newFullPageHtml = replaceFileInHtml(reference.contentItemBody, file.lmsFileId, newFile.metadata.url)
648653
}
649-
postContentItemOptions.push(createContentItemPostOptions(newFullPageHtml, extractUrl(reference.contentItemUrl), reference.contentItemId, reference.contentType, reference.sectionIds))
654+
postContentItemOptions.push(createContentItemPostOptions(newFullPageHtml, extractUrl(reference.contentItemUrl, reference.contentType), reference.contentItemId, reference.contentType, reference.sectionIds))
650655
})
651656
}
652657
return postContentItemOptions
@@ -836,6 +841,7 @@ const getSectionPostOptions = (newFile, sectionReferences) => {
836841
const postContentItemOptions = getContentPostItems(activeFile.replacement, activeFile, contentReferences)
837842
const postSectionOptions = getSectionPostOptions(activeFile, sectionReferences)
838843

844+
839845
if((postContentItemOptions && postContentItemOptions.length > 0) || (postSectionOptions && postSectionOptions.length > 0)){
840846
const responseStatus = await updateAndScanContent(postContentItemOptions, postSectionOptions, activeFile.id)
841847
if(responseStatus && responseStatus[0]?.type == "error"){

src/Lms/Canvas/CanvasApi.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public function apiFilePost(string $url, array $options, string $filepath, strin
217217
public function apiPut($url, $options)
218218
{
219219
$lmsResponse = new LmsResponse();
220+
$output = new ConsoleOutput();
220221
if(!isset($options['headers'])) {
221222
$options['headers'] = [];
222223
}
@@ -285,6 +286,10 @@ public function apiPutBatch(array $paths, array $options){
285286
$type = "";
286287
$lmsId = "";
287288

289+
if (preg_match('#^courses/(\d+)\?include\[\]=syllabus_body$#', $paths[$i], $matches)) {
290+
$type = "syllabus";
291+
}
292+
288293
if (preg_match('#/(\w+)/([^/]+)$#', $paths[$i], $matches)) {
289294
$type = $matches[1];
290295
$type = preg_replace('/s$/', '', $type);
@@ -301,6 +306,10 @@ public function apiPutBatch(array $paths, array $options){
301306
if ($type == 'discussion_topic' && isset($normalizedContent->is_announcement) && $normalizedContent->is_announcement) {
302307
$type = 'announcement';
303308
}
309+
310+
if ($type == 'syllabus'){
311+
$lmsId = $normalizedContent->id;
312+
}
304313
$response = [
305314
'content' => $normalizedContent,
306315
'id' => $lmsId,

src/Lms/Canvas/CanvasLms.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,11 @@ public function postContentItemNoIssue($contentOptions, $sectionOptions)
644644
if($contentItem){
645645
$normalizedContent = [];
646646
if($response['status'] == 200){
647-
$normalizedContent = $this->normalizeLmsContent($contentItem->getCourse(), $response['type'], json_decode(json_encode($response['content']), true));
647+
$lmsContentNew = json_decode(json_encode($response['content']), true);
648+
if ($response['type'] == 'syllabus') {
649+
$lmsContentNew['syllabus_body'] = $option['fullPageHtml'];
650+
}
651+
$normalizedContent = $this->normalizeLmsContent($contentItem->getCourse(), $response['type'], $lmsContentNew);
648652
$contentItem->update($normalizedContent);
649653
$this->entityManager->flush();
650654
}
@@ -900,6 +904,13 @@ protected function createLmsPostOptions(ContentItem $contentItem)
900904
protected function createLmsPostOptionsWithHtml($type, $fullPageHtml){
901905
$options = [];
902906
switch($type){
907+
case('syllabus'):
908+
$options = [
909+
'course' => [
910+
'syllabus_body' => $fullPageHtml,
911+
],
912+
];
913+
break;
903914
case('page'):
904915
$options = [
905916
'wiki_page' => [

0 commit comments

Comments
 (0)