enrol/database MDL-19445 Fixed infinite loops and removed superfluous objects and casts.
enrol/database MDL-19445 Fixed infinite loops and removed superfluous objects and casts.

thanks to Daren Chandisingh for the patch

dilawar/moodle