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

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

by Jon Bolton -
Number of replies: 2
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?