Does the glob() function always give you the patches in the correct order, alphabetically sorted?

I think you are also missing the query where you add the applied patch levels to the patch_history table, or is this done inside the patches?