CachedMountInfo.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. * @author Semih Serhat Karakaya <karakayasemi@itu.edu.tr>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Files\Config;
  24. use OC\Files\Filesystem;
  25. use OCP\Files\Config\ICachedMountInfo;
  26. use OCP\Files\Node;
  27. use OCP\IUser;
  28. class CachedMountInfo implements ICachedMountInfo {
  29. /**
  30. * @var IUser
  31. */
  32. protected $user;
  33. /**
  34. * @var int
  35. */
  36. protected $storageId;
  37. /**
  38. * @var int
  39. */
  40. protected $rootId;
  41. /**
  42. * @var string
  43. */
  44. protected $mountPoint;
  45. /**
  46. * @var int|null
  47. */
  48. protected $mountId;
  49. /**
  50. * @var string
  51. */
  52. protected $rootInternalPath;
  53. /**
  54. * CachedMountInfo constructor.
  55. *
  56. * @param IUser $user
  57. * @param int $storageId
  58. * @param int $rootId
  59. * @param string $mountPoint
  60. * @param int|null $mountId
  61. * @param string $rootInternalPath
  62. */
  63. public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null, $rootInternalPath = '') {
  64. $this->user = $user;
  65. $this->storageId = $storageId;
  66. $this->rootId = $rootId;
  67. $this->mountPoint = $mountPoint;
  68. $this->mountId = $mountId;
  69. $this->rootInternalPath = $rootInternalPath;
  70. }
  71. /**
  72. * @return IUser
  73. */
  74. public function getUser() {
  75. return $this->user;
  76. }
  77. /**
  78. * @return int the numeric storage id of the mount
  79. */
  80. public function getStorageId() {
  81. return $this->storageId;
  82. }
  83. /**
  84. * @return int the fileid of the root of the mount
  85. */
  86. public function getRootId() {
  87. return $this->rootId;
  88. }
  89. /**
  90. * @return Node the root node of the mount
  91. */
  92. public function getMountPointNode() {
  93. // TODO injection etc
  94. Filesystem::initMountPoints($this->getUser()->getUID());
  95. $userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
  96. $nodes = $userNode->getParent()->getById($this->getRootId());
  97. if (count($nodes) > 0) {
  98. return $nodes[0];
  99. } else {
  100. return null;
  101. }
  102. }
  103. /**
  104. * @return string the mount point of the mount for the user
  105. */
  106. public function getMountPoint() {
  107. return $this->mountPoint;
  108. }
  109. /**
  110. * Get the id of the configured mount
  111. *
  112. * @return int|null mount id or null if not applicable
  113. * @since 9.1.0
  114. */
  115. public function getMountId() {
  116. return $this->mountId;
  117. }
  118. /**
  119. * Get the internal path (within the storage) of the root of the mount
  120. *
  121. * @return string
  122. */
  123. public function getRootInternalPath() {
  124. return $this->rootInternalPath;
  125. }
  126. }