1
0

Backend.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Share;
  8. use OC\Share20\Manager;
  9. use OCP\Server;
  10. use OCP\Share\IShare;
  11. class Backend implements \OCP\Share_Backend {
  12. public const FORMAT_SOURCE = 0;
  13. public const FORMAT_TARGET = 1;
  14. public const FORMAT_PERMISSIONS = 2;
  15. private $testItem1 = 'test.txt';
  16. private $testItem2 = 'share.txt';
  17. private $testId = 1;
  18. public function isValidSource($itemSource, $uidOwner) {
  19. if ($itemSource == $this->testItem1 || $itemSource == $this->testItem2 || $itemSource == 1) {
  20. return true;
  21. }
  22. }
  23. public function generateTarget($itemSource, $shareWith, $exclude = null) {
  24. // Always make target be test.txt to cause conflicts
  25. if (substr($itemSource, 0, strlen('test')) !== 'test') {
  26. $target = "test.txt";
  27. } else {
  28. $target = $itemSource;
  29. }
  30. $shareManager = Server::get(Manager::class);
  31. $shares = array_merge(
  32. $shareManager->getSharedWith($shareWith, IShare::TYPE_USER),
  33. $shareManager->getSharedWith($shareWith, IShare::TYPE_GROUP),
  34. );
  35. $knownTargets = [];
  36. foreach ($shares as $share) {
  37. $knownTargets[] = $share['item_target'];
  38. }
  39. if (in_array($target, $knownTargets)) {
  40. $pos = strrpos($target, '.');
  41. $name = substr($target, 0, $pos);
  42. $ext = substr($target, $pos);
  43. $append = '';
  44. $i = 1;
  45. while (in_array($name.$append.$ext, $knownTargets)) {
  46. $append = $i;
  47. $i++;
  48. }
  49. $target = $name.$append.$ext;
  50. }
  51. return $target;
  52. }
  53. public function formatItems($items, $format, $parameters = null) {
  54. $testItems = [];
  55. foreach ($items as $item) {
  56. if ($format === self::FORMAT_SOURCE) {
  57. $testItems[] = $item['item_source'];
  58. } elseif ($format === self::FORMAT_TARGET) {
  59. $testItems[] = $item['item_target'];
  60. } elseif ($format === self::FORMAT_PERMISSIONS) {
  61. $testItems[] = $item['permissions'];
  62. }
  63. }
  64. return $testItems;
  65. }
  66. public function isShareTypeAllowed($shareType) {
  67. return true;
  68. }
  69. }