I am creating a system with Codeigniter that will allow us to distribute a module from one of our development courses to several courses in different sub-accounts.
After some trials everything seemed to work fine but suddenly I started getting duplicate (triplicate or even more) instances of the module in the new course. I have checked my code thoroughly and there is no explanation of what could be causing this behavior.
Does anyone know what could be happening? Or maybe I am using a bad approach to this. What I am doing, step by step is:
- Getting the information of the original course and module, including the list of items.
- Posting a new module inside the target course.
- Going through each item of the module to make a copy depending on the parameters of each type of item, including a copy of the files.
- Updating each page so the internal links target the correct files in the new course.
- Updating the front page to add a link to the new module.
- Updating the module so its published state is set to true, thus publishing the rest of the contents.
Everything is working fine and the final result is exactly what I expect. The problem comes when instead of one fully functional module I get two, three or more copies of the new module in the target course.
Now, the weirdest thing is that it doesn't happen systematically. Not all the modules present the same behavior, some are not duplicated and the number of times they are created is completely random.
Now, I guess the obvious question would be "Why don't you use Commons to do that for you?" but I haven't found a way to download a module to 15 or more courses in a simple and rapid way and each time I need to get into the front page to update the links in each one of the target courses.
Any insight on what I am doing wrong will be greatly appreciated.