by Kevin Frapin.
It' s just a question of legacy code.
We made this script when we were under Moodle 1.9, and we have adapted it for Moodle 2.X
But, you are right, I should use the Web service API.
Nevertheless, I don't really have time to do it right now, so I will probably try to do it a bit later. Thanks for the comment.
In fact, thanks to your comment I will take a look at this function core_role_assign_roles() and see how it works