MDL-12585 make sure category path, parent and depth are ok before creating contexts; merged from MOODLE_19_STABLE
MDL-12585 make sure category path, parent and depth are ok before creating contexts; merged from MOODLE_19_STABLE

dilawar/moodle