MoveFromCacheTrait.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Files\Cache;
  8. use OCP\Files\Cache\ICache;
  9. use OCP\Files\Cache\ICacheEntry;
  10. /**
  11. * Fallback implementation for moveFromCache
  12. */
  13. trait MoveFromCacheTrait {
  14. /**
  15. * store meta data for a file or folder
  16. *
  17. * @param string $file
  18. * @param array $data
  19. *
  20. * @return int file id
  21. * @throws \RuntimeException
  22. */
  23. abstract public function put($file, array $data);
  24. abstract public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int;
  25. /**
  26. * Move a file or folder in the cache
  27. *
  28. * @param \OCP\Files\Cache\ICache $sourceCache
  29. * @param string $sourcePath
  30. * @param string $targetPath
  31. */
  32. public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
  33. $sourceEntry = $sourceCache->get($sourcePath);
  34. $this->copyFromCache($sourceCache, $sourceEntry, $targetPath);
  35. $sourceCache->remove($sourcePath);
  36. }
  37. }