3.1 code refactor

Replacing lots of old 2.4 deprecated code with new 3.1 compatible code.

Will require peer review and also aware that we could take this further... for now it's just what I could find and repair.

Most issues were around the ORM style and the use of Config system vs statics.

Locally all previous tests are passing and a quick smoke tests playing around in the forum and posting some stuff seems to work as expected. More testing would be great though.
If you remove the `class_exists` check (which is checking to see if `SapphireTest` has been loaded, not if it exists), you also have to remove the `SapphireTest::is_running_test()` check.