1
0

Backend.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Michael Gapczynski
  6. * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. namespace Test\Share;
  22. use OC\Share20\Manager;
  23. use OCP\Server;
  24. use OCP\Share\IShare;
  25. class Backend implements \OCP\Share_Backend {
  26. public const FORMAT_SOURCE = 0;
  27. public const FORMAT_TARGET = 1;
  28. public const FORMAT_PERMISSIONS = 2;
  29. private $testItem1 = 'test.txt';
  30. private $testItem2 = 'share.txt';
  31. private $testId = 1;
  32. public function isValidSource($itemSource, $uidOwner) {
  33. if ($itemSource == $this->testItem1 || $itemSource == $this->testItem2 || $itemSource == 1) {
  34. return true;
  35. }
  36. }
  37. public function generateTarget($itemSource, $shareWith, $exclude = null) {
  38. // Always make target be test.txt to cause conflicts
  39. if (substr($itemSource, 0, strlen('test')) !== 'test') {
  40. $target = "test.txt";
  41. } else {
  42. $target = $itemSource;
  43. }
  44. $shareManager = Server::get(Manager::class);
  45. $shares = array_merge(
  46. $shareManager->getSharedWith($shareWith, IShare::TYPE_USER),
  47. $shareManager->getSharedWith($shareWith, IShare::TYPE_GROUP),
  48. );
  49. $knownTargets = [];
  50. foreach ($shares as $share) {
  51. $knownTargets[] = $share['item_target'];
  52. }
  53. if (in_array($target, $knownTargets)) {
  54. $pos = strrpos($target, '.');
  55. $name = substr($target, 0, $pos);
  56. $ext = substr($target, $pos);
  57. $append = '';
  58. $i = 1;
  59. while (in_array($name.$append.$ext, $knownTargets)) {
  60. $append = $i;
  61. $i++;
  62. }
  63. $target = $name.$append.$ext;
  64. }
  65. return $target;
  66. }
  67. public function formatItems($items, $format, $parameters = null) {
  68. $testItems = [];
  69. foreach ($items as $item) {
  70. if ($format === self::FORMAT_SOURCE) {
  71. $testItems[] = $item['item_source'];
  72. } elseif ($format === self::FORMAT_TARGET) {
  73. $testItems[] = $item['item_target'];
  74. } elseif ($format === self::FORMAT_PERMISSIONS) {
  75. $testItems[] = $item['permissions'];
  76. }
  77. }
  78. return $testItems;
  79. }
  80. public function isShareTypeAllowed($shareType) {
  81. return true;
  82. }
  83. }