selective backport of the bug fixes from pr #6863
Merge pull request #6874 from owncloud/versioning_expire_fixes_stable6

selective backport of the bug fixes from pr #6863