Recently accessed courses block showing "No recent courses" on production server

Recently accessed courses block showing "No recent courses" on production server

by Surya Pratap -
Number of replies: 3

Hi there everyone,

The recently accessed course block is not working properly on the production server. It has shown "No recent courses" in the content area of the block. Whereas it is working properly on the localhost environment. I am using  Moodle 3.6.5

Here is my test case Scenario:

created two courses: C1 and C2

enrolled users in the courses: student1, student2, student3

log in as "student1", "student2" and "student3" and accessed the course "c1 and c2" 

And I follow "Dashboard" in the user menu

Then I have seen "c1" and "c2" in the "Recently accessed courses" "block"

The same scenario is working on the localhost but it is not working on the production server. 


Thanking you in advance.


Average of ratings: -
In reply to Surya Pratap

Re: Recently accessed courses block showing "No recent courses" on production server

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers
In reply to Jon Bolton

Re: Recently accessed courses block showing "No recent courses" on production server

by Surya Pratap -
Thanks, Jon for your reply.

I already have checked this.

As I found this query is used to get the result of a recently accessed course. In my case, it working on the localhost system but won't work on the production.

Here is the query:
SELECT c.id,idnumber,summary,summaryformat,startdate,enddate,category,shortname,fullname,timeaccess,component, ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel, ctx.instanceid AS ctxinstance, ctx.locked AS ctxlocked
FROM mdl_course c
JOIN mdl_context ctx
ON ctx.contextlevel = 50
AND ctx.instanceid = c.id
JOIN mdl_user_lastaccess ul
ON ul.courseid = c.id
LEFT JOIN mdl_favourite fav
ON fav.component = 'core_course'
AND fav.itemtype = 'courses'
AND fav.userid = 14401
AND fav.itemid = ul.courseid
WHERE ul.userid = 14401
AND c.visible = 1
AND EXISTS (SELECT 1
FROM mdl_enrol e
LEFT JOIN mdl_user_enrolments ue ON ue.enrolid = e.id
WHERE e.courseid = c.id
AND e.status = 0
AND ((ue.status = 0
AND ue.userid = ul.userid
AND ue.timestart < 1590494500
AND (ue.timeend = 0 OR ue.timeend > 1590494500)
)
OR e.enrol = 'guest'
)
)
ORDER BY timeaccess DESC
In reply to Surya Pratap

Re: Recently accessed courses block showing "No recent courses" on production server

by Surya Pratap -
Hi there everyone,

I tried to find the cause of my issue. If I comment on this "#OR e.enrol = 'guest'" condition from the query then the result will come. May I know the actual reason? Did I miss any configuration in moodle?

SELECT c.id,idnumber,summary,summaryformat,startdate,enddate,category,shortname,fullname,timeaccess,component, ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel, ctx.instanceid AS ctxinstance, ctx.locked AS ctxlocked
FROM mdl_course c
JOIN mdl_context ctx
ON ctx.contextlevel = 50
AND ctx.instanceid = c.id
JOIN mdl_user_lastaccess ul
ON ul.courseid = c.id
LEFT JOIN mdl_favourite fav
ON fav.component = 'core_course'
AND fav.itemtype = 'courses'
AND fav.userid = 14401
AND fav.itemid = ul.courseid
WHERE ul.userid = 14401
AND c.visible = 1
AND EXISTS (SELECT e.id
FROM mdl_enrol e
LEFT JOIN mdl_user_enrolments ue ON ue.enrolid = e.id
WHERE e.courseid = c.id
AND e.status = 0
AND ((ue.status = 0
AND ue.userid = ul.userid
AND ue.timestart < 1590494500
AND (ue.timeend = 0 OR ue.timeend > 1590494500)
)
#OR e.enrol = 'guest'
)
)
ORDER BY timeaccess DESC


Please check the above query. If I comment this  ``OR e.enrol = 'guest'`` then it is working.  why is this condition creating a problem for me?