danmarsden/moodle-plagiarism_turnitin — pull request #34 by mattgibson (2012-08-09 15:15:32+00:00)
Title: Fix stalled events

Hi Dan.

I found a problem with our events queue getting stuck, so I've had a poke about and found that sometimes, there is an error from Turnitin e.g. user has a duplicate email, but it is not recorded in the plagiarism_turnitin_files status field. There was also a problem where the turnitin_send_file() function would return null in that case, which was causing false to get sent back to the event handler, which then stopped processing, on the assumption that Turnitin was down.

This patch fixes a few other things too. Full list:
- turnitin_send_file() returns boolean all the time instead of either nothing or the XML (which is never used).
- Problems e.g. cannot enrol in class also now return true so that the events clear.
- The event handler has updated code so that files that are found to be already sent return true always, which takes the event out of the queue and lets the cron job take over.
- There is now an option to send an array of stored files along with the event.
- Fixed a problem where whitespace in the list of codes to resent was stopping them from working.
- Added some PHPDoc comments.
- Status codes are always saved so we can see the code if it gets stuck halfway.
- Turnitin session is ended cleanly even if the process gets stuck.
- Problem with undefined variable in the sanity checks in turnitin_send_file() is gone.

I'm afraid these aren't very cleanly separated into different commits, but hopefully that doesn't matter.

Matt