Run preupdate before an update

The update routine tries to test the database migration before actually performing the update.

However, this will fail hard if the schema has changed (for example an unique key has been added). App developers can convert the DB in preupdate.php, however it is not called before and therefore the update fails.

This actually breaks ownCloud updates from ownCloud 6 to ownCloud 7 when the files_antivirus app is enabled.
Move CSRF check

Because we're closing the session now before controllers are executed there are cases where we cannot write the session.

Conflicts:
	lib/private/server.php

Conflicts:
	lib/private/template.php