Problem/Motivation

While creating or browsing a Book node that has been added to a Course, PHP warnings will appear if the content is being viewed before the user has enrolled in a course containing that book.

    Warning: array_filter() expects parameter 1 to be array, null given in CourseObjectBook->grade() (line 88 of PATH_TO_COURSE\modules\course_book\course_book.classes.inc).
    Warning: array_keys() expects parameter 1 to be array, null given in CourseObjectBook->grade() (line 88 of PATH_TO_COURSE\modules\course_book\course_book.classes.inc).
    Warning: array_diff(): Argument #2 is not an array in CourseObjectBook->grade() (line 89 of PATH_TO_COURSE\modules\course_book\course_book.classes.inc).

This is because the Course Book will try to grade and save or update course fulfillment when a book page is viewed, even if the viewer isn't enrolled in a course related to this object. The grading and fulfillment fail to save, as you'd expect, but the grading does it noisily.

Comments

stickywes created an issue. See original summary.

wwedding’s picture

Issue summary: View changes
wwedding’s picture

Title: Viewing a Book course object while not enrolled in Course generates warnings » Viewing a Book Course Object while not enrolled in a related Course generates warnings
wwedding’s picture

Fixed the local problem, specific to the grade() function, but it feels like it shouldn't even get to that point. If I'm not enrolled, it seems like all that work going into trying to save, set options, make a fulfillment object, shouldn't be happening to begin with. Perhaps there should be a check right at the top of a node_view that checks if someone is even in a course.

I tried to take that approach, initially, but I couldn't figure out how to walk backwards from node to a list of courses that a node might be a part of using existing module functionality.

wwedding’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: course-viewing_a_book_warning-2625464-4.patch, failed testing.

wwedding’s picture

Status: Needs work » Needs review

What's up with the testing? Seems like 5.6 is broken or something.

djdevin’s picture

Status: Needs review » Fixed

Looks fine. Thanks!

  • djdevin committed 9b48d9d on 7.x-1.x authored by stickywes
    Issue #2625464 by stickywes: Viewing a Book Course Object while not...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.