Fix9475

Avoids unnecessary writing to the DB when the value in question is not changed. Small changeset,  with unit tests. Fixes https://github.com/owncloud/core/issues/9475

What happens in general is that ownCloud reads the email from LDAP address for a users every 24hrs at earliest. It is taken over into owncloud i.e. written to the database. Now we write it only, if the value has actually changed. User preferences are read at once so this has no additional read operations but saves a write. It also avoids a double-write when it is triggered from both login and userExists check. userExists is always called prior to the login attempt.

Reviewers/testers please, maybe @Xenopathic @PVince81 @icewind1991 or others?