Fix upgrade script
Adding permission bypass to the APIv4 calls. Also there's a call to in_array
that doesn't pass the first argument.
The performance of this upgrade script is slow, and I considered optimizing, but given that it only runs once I decided it wasn't worth it.