homeobjectstorestorage.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @author Jörn Friedrich Dreyer
  4. * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public
  17. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. namespace OC\Files\ObjectStore;
  21. use OC\User\User;
  22. class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage {
  23. /**
  24. * The home user storage requires a user object to create a unique storage id
  25. * @param array $params
  26. */
  27. public function __construct($params) {
  28. if ( ! isset($params['user']) || ! $params['user'] instanceof User) {
  29. throw new \Exception('missing user object in parameters');
  30. }
  31. $this->user = $params['user'];
  32. parent::__construct($params);
  33. //initialize cache with root directory in cache
  34. if ( ! $this->is_dir('files') ) {
  35. $this->mkdir('files');
  36. }
  37. }
  38. public function getId () {
  39. return 'object::user:' . $this->user->getUID();
  40. }
  41. /**
  42. * get the owner of a path
  43. *
  44. * @param string $path The path to get the owner
  45. * @return false|string uid
  46. */
  47. public function getOwner($path) {
  48. if (is_object($this->user)) {
  49. return $this->user->getUID();
  50. }
  51. return false;
  52. }
  53. /**
  54. * @param string $path, optional
  55. * @return \OC\User\User
  56. */
  57. public function getUser($path = null) {
  58. return $this->user;
  59. }
  60. }