Big problems after recycling files

Nextcloud version (eg, 12.0.2): 18.0.3
Operating system and version (eg, Ubuntu 17.04): debian 9
Apache or nginx version (eg, Apache 2.4.25): apache
PHP version (eg, 7.1): 7.3

The issue you are facing:
Error during recycle process. Files are restored not to original location, but to root folder which means total mess.

Is this the first time you’ve seen this error? (Y/N): Yes

Steps to replicate it: .

  1. Collect files over several years.
  2. Forget to stop sync folder on moving files.
  3. Try to recycle those files
  4. Wonder that folder structure gets messed up

The output of your Nextcloud log in Admin > Logging:

opendir(/data/someUser/files_trashbin/versions/2017.d1586305764): failed to open dir: No such file or directory at /var/www/html/lib/private/Files/Storage/Local.php#127
Doctrine\DBAL\Exception\DeadlockException: An exception occurred while executing 'DELETE FROM `oc_filecache` WHERE `parent` = ?' with params [308442]: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):


The output of your Apache/nginx/system log in /var/log/____:


Does someone have any hint or idea? My data is messed up and I cannot get it back from recycle bin. I have more details in this ticket:

Thanks a lot!