Backport fix-5828 manually to stable5. Implements 17e45e2 on stable5

Backports https://github.com/owncloud/core/pull/5828/commits to fix https://github.com/owncloud/enterprise/issues/64 on stable5 @ser72 @felixboehm @DeepDiver1975