You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hooks.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Bjoern Schiessle
  6. * @copyright 2014 Bjoern Schiessle <schiessle@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 OC\Share;
  22. class Hooks extends \OC\Share\Constants {
  23. /**
  24. * Function that is called after a user is deleted. Cleans up the shares of that user.
  25. * @param array arguments
  26. */
  27. public static function post_deleteUser($arguments) {
  28. // Delete any items shared with the deleted user
  29. $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share`'
  30. .' WHERE `share_with` = ? AND `share_type` = ? OR `share_type` = ?');
  31. $result = $query->execute(array($arguments['uid'], self::SHARE_TYPE_USER, self::$shareTypeGroupUserUnique));
  32. // Delete any items the deleted user shared
  33. $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*share` WHERE `uid_owner` = ?');
  34. $result = $query->execute(array($arguments['uid']));
  35. while ($item = $result->fetchRow()) {
  36. Helper::delete($item['id']);
  37. }
  38. }
  39. /**
  40. * Function that is called after a user is added to a group.
  41. * TODO what does it do?
  42. * @param array arguments
  43. */
  44. public static function post_addToGroup($arguments) {
  45. // Find the group shares and check if the user needs a unique target
  46. $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?');
  47. $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid']));
  48. $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`,'
  49. .' `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`,'
  50. .' `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
  51. while ($item = $result->fetchRow()) {
  52. if ($item['item_type'] == 'file' || $item['item_type'] == 'file') {
  53. $itemTarget = null;
  54. } else {
  55. $itemTarget = Helper::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER,
  56. $arguments['uid'], $item['uid_owner'], $item['item_target'], $item['id']);
  57. }
  58. if (isset($item['file_source'])) {
  59. $fileTarget = Helper::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER,
  60. $arguments['uid'], $item['uid_owner'], $item['file_target'], $item['id']);
  61. } else {
  62. $fileTarget = null;
  63. }
  64. // Insert an extra row for the group share if the item or file target is unique for this user
  65. if ($itemTarget != $item['item_target'] || $fileTarget != $item['file_target']) {
  66. $query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'],
  67. self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'],
  68. $item['stime'], $item['file_source'], $fileTarget));
  69. \OC_DB::insertid('*PREFIX*share');
  70. }
  71. }
  72. }
  73. /**
  74. * Function that is called after a user is removed from a group. Shares are cleaned up.
  75. * @param array arguments
  76. */
  77. public static function post_removeFromGroup($arguments) {
  78. $sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`'
  79. .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)';
  80. $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'],
  81. self::$shareTypeGroupUserUnique, $arguments['uid']));
  82. while ($item = $result->fetchRow()) {
  83. if ($item['share_type'] == self::SHARE_TYPE_GROUP) {
  84. // Delete all reshares by this user of the group share
  85. Helper::delete($item['id'], true, $arguments['uid']);
  86. } else {
  87. Helper::delete($item['id']);
  88. }
  89. }
  90. }
  91. /**
  92. * Function that is called after a group is removed. Cleans up the shares to that group.
  93. * @param array arguments
  94. */
  95. public static function post_deleteGroup($arguments) {
  96. $sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?';
  97. $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid']));
  98. while ($item = $result->fetchRow()) {
  99. Helper::delete($item['id']);
  100. }
  101. }
  102. }