@@ -214,11 +214,6 @@ private function saveOrUpdateContentItem($canvasApi, Course $course, $contentTyp
214214 }
215215 }
216216
217- /* get HTML file content */
218- if (('file ' === $ contentType ) && ('html ' === $ content ['mime_class ' ])) {
219- $ lmsContent ['body ' ] = file_get_contents ($ content ['url ' ]);
220- }
221-
222217 if (!$ contentItem ) {
223218 $ contentItem = new ContentItem ();
224219 $ metadata = $ parentLmsId ? array ('parentLmsId ' => $ parentLmsId ) : array ();
@@ -390,18 +385,15 @@ public function updateCourseContent(Course $course, User $user, $force = false):
390385 $ apiToken = $ this ->getApiToken ($ user );
391386
392387 $ canvasApi = new CanvasApi ($ apiDomain , $ apiToken );
388+ $ scanFails = 0 ;
393389
394- // Batch page pulling maintaince
395- $ pageUrls = [];
396- $ asyncFetch = true ;
397-
398- $ start_time = microtime (true );
399390 foreach ($ urls as $ contentType => $ url ) {
400391 $ response = $ canvasApi ->apiGet ($ url );
392+ $ statusCode = $ response ->getStatusCode ();
401393
402- if ( $ response ->getErrors ()) {
403- $ this -> util -> createMessage ( ' Error retrieving content. Failed API Call: ' . $ url , ' error ' , $ course , $ user ) ;
404- throw new \ Exception ( ' msg.sync.error.api ' );
394+ if (! $ statusCode || $ statusCode != 200 || $ response ->getErrors ()){
395+ $ scanFails += 1 ;
396+ continue ; // Continue to onto next content item if we failed to get a status code
405397 }
406398 else {
407399 if ('syllabus ' === $ contentType ) {
@@ -427,62 +419,13 @@ public function updateCourseContent(Course $course, User $user, $force = false):
427419 if (('assignment ' === $ contentType ) && isset ($ content ['discussion_topic ' ])) {
428420 continue ;
429421 }
430- if (('page ' === $ contentType ) && ($ asyncFetch )){
431- // If we are using async fetch we need the
432- $ lmsContent = $ this ->normalizeLmsContent ($ course , $ contentType , $ content );
433- $ contentItem = $ this ->contentItemRepo ->findOneBy ([
434- 'contentType ' => $ contentType ,
435- 'lmsContentId ' => $ lmsContent ['id ' ],
436- 'course ' => $ course ,
437- ]);
438-
439- if (!$ contentItem ) {
440- $ contentItem = new ContentItem ();
441- $ contentItem ->setCourse ($ course )
442- ->setLmsContentId ($ lmsContent ['id ' ])
443- ->setActive (true )
444- ->setContentType ($ contentType );
445- $ this ->entityManager ->persist ($ contentItem );
446- }
447- $ url = "courses/ {$ course ->getLmsCourseId ()}/pages/ {$ lmsContent ['id ' ]}" ;
448- $ tempContentItems [] = $ contentItem ;
449- $ pageUrls [] = $ url ;
450- continue ;
451- }
452-
453422 $ this ->saveOrUpdateContentItem ($ canvasApi , $ course , $ contentType , $ content , $ force );
454423 }
455424 }
456425 }
457-
458- if (count ($ pageUrls ) > 0 ) {
459-
460- $ output ->writeln ('Fetching contents for ' . count ($ pageUrls ) . ' pages asynchronously... ' );
461-
462- // Request pages in a batch instead of synchronously
463- $ allPages = $ canvasApi ->apiGetBatch ($ pageUrls );
464-
465- // Save indices for the tempContentItems array so it will be easier (O(1)) to match up...
466- $ tempContentItemsIndexById = [];
467- foreach ($ tempContentItems as $ index => $ item ) {
468- $ tempContentItemsIndexById [$ item ->getLmsContentId ()] = $ index ;
469- }
470-
471- foreach ($ allPages as $ pageData ) {
472- $ lmsContent = $ this ->normalizeLmsContent ($ course , 'page ' , json_decode ($ pageData , true ));
473-
474- if (!empty ($ lmsContent ['body ' ])) {
475- $ lmsContentId = $ lmsContent ['id ' ];
476- // If the item exists in the tempContentItems array... Update and add to contentItems to scan.
477- if (isset ($ tempContentItemsIndexById [$ lmsContentId ])) {
478- $ index = $ tempContentItemsIndexById [$ lmsContentId ];
479- $ tempContentItems [$ index ]->update ($ lmsContent );
480- $ this ->contentItemList [] = $ tempContentItems [$ index ];
481- }
482- }
483- }
484- }
485-
426+ if ($ scanFails > 0 ){
427+ $ this ->util ->createMessage ('Failed to fetch {$scanFails} from LMS. Please try to rescan the course to account for all issues. ' , 'error ' , $ course , $ user );
428+ }
486429 // push any updates made to content items to DB
487430 $ this ->entityManager ->flush ();
488431 return $ this ->contentItemList ;
0 commit comments